small upd

This commit is contained in:
2024-11-21 17:51:59 +03:00
parent e6f2883584
commit a642e913ed
5 changed files with 95 additions and 42 deletions

View File

@ -40,7 +40,11 @@ void onSend(){
#define TEST_1
// #define TEST_2
class VAR {
public:
uint16_t var = 1337;
};
VAR vvv;
void setup()
{
Serial.begin(115200);
@ -55,8 +59,12 @@ void setup()
// Ethernet.setRtCount(3);
// client.setNoDelayedACK(true); // Не ждать ответа от сервера
client.setOnSendSuccess(onSend);
// client.setOnSendSuccess(onSend);
client.setOnSendSuccess(std::bind([](VAR* bind_vvv){
Serial.print("Sending Successfully: ");
Serial.println(bind_vvv->var++);
}, &vvv));
}
#ifdef TEST_2
@ -120,4 +128,41 @@ void loop()
dataReady = false;
}
#endif
if(client.available()>0){
byte response[16];
int len = client.read(response, sizeof(response));
if (len == 16)
{
// Проверка контрольной суммы
uint8_t checksum = 0;
for (int i = 0; i < 15; i++)
{
checksum += response[i];
}
Serial.print("RX: ");
for (int i = 0; i < 16; i++)
{
Serial.print(response[i], HEX);
Serial.print(" ");
}
if (response[15] == checksum)
{
Serial.println("Checksum is OK");
}
else
{
Serial.println("Checksum is ERROR");
}
client.activityUpdate(); // Обновляем время последней активности
}
else
{
Serial.println("Received an incomplete response");
}
}
}