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

Stale Packet error #111

Open
queenidog opened this issue Jul 16, 2023 · 1 comment
Open

Stale Packet error #111

queenidog opened this issue Jul 16, 2023 · 1 comment

Comments

@queenidog
Copy link

queenidog commented Jul 16, 2023

I'm sending joystick values via Nano connected to HC12, to a ProMicro Receiver also attached (obviously) to an HC12. I was running both at 9600 baud with a delay (in TX) of 250 mS. I don't like the delay but will deal with that after I get better results. As I go down in delay, the frequency of Stale Packets increases. At 250 mS, I get a couple a minute. I increased the baud of the system (HC12 and serials) to 19200 and get maybe 1 stale packet every 2 minutes.
I had other Serial sketches that did all kinds of manipulation to improve throughput but they did not work and your library makes everything so much simpler, so its definitely the way to go.
But...my problem is the receiver is for a robot and when it receives bad data (it was triggering on < begin data markers before) the motor driver is triggered and the robot begins to move forward. So...at this point if I'm going to get packet errors, I must prevent that bad data from getting passed to the motor driver (a simple H bridge using L9110). How can I do this effectively? I'm not even at a point of calling myself "intermediate programmer" (I'm real old school Assembly programmer), so need some guidance. This is the current (test) setup, basically your example receive code:
`#include "SerialTransfer.h"
SerialTransfer myTransfer;
int xAxis;
int yAxis;
struct STRUCT {
int x;
int y;
} testStruct;
//char arr[6];//Count # of characters inc spaces in transmit char arr

void setup() {
Serial.begin(19200);
Serial1.begin(19200);
myTransfer.begin(Serial1);
}

void loop() {
if (myTransfer.available()) {
// use this variable to keep track of how many bytes we've processed from the receive buffer
uint16_t recSize = 0;

recSize = myTransfer.rxObj(testStruct, recSize);
Serial.print(testStruct.x);
Serial.print(" | ");
Serial.println(testStruct.y);

//recSize = myTransfer.rxObj(arr, recSize);
// Serial.println(arr);

}
}`

And my TX code:
`#include "SerialTransfer.h"
#include <SoftwareSerial.h>
//SoftwareSerial HC12(9, 10);
SerialTransfer myTransfer;
int xAxis;
int yAxis;

struct STRUCT {
int x;
int y;
} testStruct;

//char arr[] = "hello"; //count # of characters, put in TX char arr[29]

void setup() {
Serial.begin(19200);
//HC12.begin(9600);
myTransfer.begin(Serial);
}

void loop() {
testStruct.x = analogRead(A2);
testStruct.y = analogRead(A3);
// use this variable to keep track of how many bytes we're stuffing in the transmit buffer
uint16_t sendSize = 0;
sendSize = myTransfer.txObj(testStruct, sendSize);// Stuff buffer with struct
// sendSize = myTransfer.txObj(arr, sendSize); // Stuff buffer with array
myTransfer.sendData(sendSize); // Send buffer
delay(250);//def was 500
}
`
image

The Nano is not using software serial (slower, more errors) so I'm using HW Serial. The ProMicro has a separate Serial1.

@PowerBroker2
Copy link
Owner

A stale packet occurs when the beginning of a packet is received, but the rest of the packet isn't received before a timeout occurs. In your case (streaming data constantly), it suggests there are Serial input (or output) buffer overflows. Cranking BOTH the USB and HC-12 bauds as high as possible will help mitigate this. You might even want to look at increasing the serial buffer sizes (I don't know how to do that for the boards you are using). I hope it helps

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

2 participants