There is more to low-latency communication than just squirting data as fast as you can (though that is an important part of it).
One thing people often forget is that the Arduino can only (easily) do one thing at a time. While you're sending your buffer to the PC it can't be sampling and filling your buffer. If you have a buffer which fills up over the ...
It is an internal buffer and only the pointer gets increased. It it visible in the source code off the project, located on github:
// Read data from buffer
// Empty buffer?
if (_receive_buffer_head == _receive_buffer_tail)
// Read from "head"
uint8_t d = ...
You can do it with snprintf_P:
snprintf_P(mac, 18, (PGM_P)F("%02X-%02X-%02X-%02X-%02X-%02X"),
That is, assuming that report->...
Actually there are 2 buffers per Serial hardware interface: The hardware buffer, that is 1 byte (per direction of data transfer). The Serial library then transfers this byte in an extra buffer (64 bytes big) from an ISR. Every hardware Serial interface (Serial and Serial1 to 3 on the Mega) has it's own hardware buffer.
Then the Serial library is implemented ...
The Arduino Mega has 8 KB of RAM, all of which you could use in a StaticJsonDocument.
The ESP8266 has 80 KB of RAM, but the core limits the stack to 4 KB. If you need something bigger, switch to a DynamicJsonDocument.
In both cases, you need to leave a lot of room for other variables and libraries. As an example, I wouldn't create a StaticJsonDocument bigger ...
What do each of the 12 elements represent?
Things in the header. That is off-topic for here.
Why is there a difference in the output between the output of the raw buffer and snifferPacket?
snifferPacket is overlaid over the incoming buffer. That includes the "data" buffer which you are printing. The data buffer is only a portion of the ...
Thanks for the pointer - that did the trick. Applying it to my original code, if I update the few lines around handle call from Python to the following, it works as intended.
// handle call from Python
strncpy(buff, received_str, myTransfer.bytesRead);
A byte can only contain values from 0 to 255 (including).
So my guess it works for values until 255.
You should use a different type, e.g. unsigned int or unsigned short.
for (unsigned short i = len; i < 250; i++) buffer[i] = '#'; // pad with #
Also, I advise to use a constant or define for the buffer size, now you have 3 values (512, 500 and 250 ...
toCharArray is alias for getBytes. getBytes is documented as "Copies the String’s characters to the supplied buffer." You did not allocate the memory for the copied characters.
the right use of 'getBytes' and 'toCharArray' is
note: getBytes functions sets the terminating zero of the c-string in ...
The communication protocol used by this library is unreliable. Thus,
each code word is sent multiple times, 10 times by
default. One solution around this problem is to send
a “byte number” along with each byte you transmit. You would then
transmit 16-bit words, where the MSB (most significant byte) is the byte
number, and the LSB is the actual byte you want ...
I found my stupid mistake:
By using try without catching specific exceptions (I know one shouln't do that) in my Laptop-Server script I didn't recognize that I was trying to send unencoded strings.
clientsocket.send("hi there, "+str(addr)+"\n")
has to be
clientsocket.send(bytes(("hi there, "+str(addr)+"\n").encode('utf-8')))
The simple answer is that the Arduino Wire library has an internal buffer, and it can bring in characters and have them sitting there ready for you to pick them up.
It can also sense a total disconnect because of the way it uses both data pins to establish communications. It is more like a current loop than a simple one-is-transmit-and-the-other-is-...