Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packet not received #23

Open
gordon13 opened this issue Nov 13, 2019 · 7 comments
Open

Packet not received #23

gordon13 opened this issue Nov 13, 2019 · 7 comments

Comments

@gordon13
Copy link

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?

@PowerBroker2
Copy link

PowerBroker2 commented May 12, 2020

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.

@bakercp
Copy link
Owner

bakercp commented May 13, 2020 via email

@bakercp
Copy link
Owner

bakercp commented May 13, 2020 via email

@bakercp
Copy link
Owner

bakercp commented May 13, 2020

@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: #24

@ranfro
Copy link

ranfro commented Jan 6, 2024

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?

@socram8888
Copy link

FTR I've experienced this issue. Python cobs module will not add the final 00 byte. Add it yourself (packet = cobs.encode(packet) + b'\x00') and it'll work.

@dcheang
Copy link

dcheang commented Sep 24, 2024

FTR I've experienced this issue. Python cobs module will not add the final 00 byte. Add it yourself (packet = cobs.encode(packet) + b'\x00') and it'll work.

Thank you! This works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants