PacketSerial icon indicating copy to clipboard operation
PacketSerial copied to clipboard

Packet not received

Open gordon13 opened this issue 5 years ago • 7 comments

I'm trying to send a packet from Python to the Arduino but the handler is never triggered. Maybe I misunderstand the packet format?

I'm using the COBS library to encode the data. Here's the packet as it is sent using the standard python serial library: b'\x03\x01\x04\x00'

Here's the Arduino code:

#include <PacketSerial.h>
PacketSerial myPacketSerial;

void setup() {
  myPacketSerial.begin(9600);
  myPacketSerial.setPacketHandler(&onPacketReceived);
}

void loop() {
  myPacketSerial.update();
}

void onPacketReceived(const uint8_t* buffer, size_t size)
{
  uint8_t tempBuffer[size];
  memcpy(tempBuffer, buffer, size);
  uint8_t id = tempBuffer[0];
  myPacketSerial.send(id, 1);
}

Why am I not getting anything back?

gordon13 avatar Nov 13 '19 19:11 gordon13

This lib seems to be unsupported. A much easier to use and supported serial packet library can be found here. The library also has a Python compatible (and pip-installable) package here.

PowerBroker2 avatar May 12 '20 18:05 PowerBroker2

It's supported. What problem are you having?

On Tue, May 12, 2020, 12:14 PM PB2 [email protected] wrote:

This lib seems to be unsupported. A much easier to use and supported serial packet library can be found here https://github.com/PowerBroker2/SerialTransfer.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bakercp/PacketSerial/issues/23#issuecomment-627507794, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACJLRCRIWJ5D5IIXSUNL33RRGGWZANCNFSM4JNAWGTA .

bakercp avatar May 13 '20 03:05 bakercp

By the way, python, with test code is linked in the readme.

On Wed, Nov 13, 2019, 12:52 PM Paul (mightyboat) [email protected] wrote:

I'm trying to send a packet from Python to the Arduino but the handler is never triggered. Maybe I misunderstand the packet format?

I'm using the COBS library to encode the data. Here's the packet as it is sent using the standard python serial library: b'\x03\x01\x04\x00'

Here's the Arduino code:

#include <PacketSerial.h> PacketSerial myPacketSerial;

void setup() { myPacketSerial.begin(9600); myPacketSerial.setPacketHandler(&onPacketReceived); }

void loop() { myPacketSerial.update(); }

void onPacketReceived(const uint8_t* buffer, size_t size) { uint8_t tempBuffer[size]; memcpy(tempBuffer, buffer, size); uint8_t id = tempBuffer[0]; myPacketSerial.send(id, 1); }

Why am I not getting anything back?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bakercp/PacketSerial/issues/23?email_source=notifications&email_token=AACJLRCIOYVKPVIHFIXGBY3QTRLGPA5CNFSM4JNAWGTKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HZDX7FA, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACJLRC3DOLUAQSLSLIID3DQTRLGPANCNFSM4JNAWGTA .

bakercp avatar May 13 '20 03:05 bakercp

@gordon13 One thing of note -- the send method takes a pointer e.g.

void send(const uint8_t* buffer, size_t size) const

and you are giving it a value, thus it may not give the correct value. You may want to try:

...
  uint8_t id = tempBuffer[0];
  myPacketSerial.send(&id, 1);
...

Also, if the value of your id is actually equal to zero, you may be running into this issue: https://github.com/bakercp/PacketSerial/issues/24

bakercp avatar May 13 '20 03:05 bakercp

I'm having the same issue.. I'm sending data and trying to send back data after it is received. It seems onPacketReceived is not firing. Any Ideas?

ranfro avatar Jan 06 '24 02:01 ranfro