PacketSerial
PacketSerial copied to clipboard
Packet not received
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?
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.
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 .
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 .
@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
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?