change data type

This commit is contained in:
DevilBinder 2022-06-21 22:56:48 +02:00
parent 0c988e5d99
commit 073c1f8140
2 changed files with 43 additions and 51 deletions

View File

@ -9,36 +9,27 @@ uint8_t newData = 0;
uint8_t ln = 0; uint8_t ln = 0;
DataReading theData[256]; DataReading theData[256];
DataReading ESPNOWGbuffer[256]; DataReadingBuffer_t ESPNOWGbuffer;
uint16_t lenESPNOWG = 0;
uint32_t timeESPNOWG = 0;
DataReading ESPNOW1buffer[256]; DataReadingBuffer_t ESPNOW1buffer;
uint16_t lenESPNOW1 = 0;
uint32_t timeESPNOW1 = 0; uint32_t timeESPNOW1 = 0;
DataReading ESPNOW2buffer[256]; DataReadingBuffer_t ESPNOW2buffer;
uint16_t lenESPNOW2 = 0;
uint32_t timeESPNOW2 = 0; uint32_t timeESPNOW2 = 0;
DataReading SERIALbuffer[256]; DataReadingBuffer_t SERIALbuffer;
uint16_t lenSERIAL = 0;
uint32_t timeSERIAL = 0; uint32_t timeSERIAL = 0;
DataReading MQTTbuffer[256]; DataReadingBuffer_t MQTTbuffer;
uint8_t lenMQTT = 0;
uint32_t timeMQTT = 0; uint32_t timeMQTT = 0;
DataReading LORAGbuffer[256]; DataReadingBuffer_t LORAGbuffer;
uint8_t lenLORAG = 0;
uint32_t timeLORAG = 0; uint32_t timeLORAG = 0;
DataReading LORA1buffer[256]; DataReadingBuffer_t LORA1buffer;
uint8_t lenLORA1 = 0;
uint32_t timeLORA1 = 0; uint32_t timeLORA1 = 0;
DataReading LORA2buffer[256]; DataReadingBuffer_t LORA2buffer;
uint8_t lenLORA2 = 0;
uint32_t timeLORA2 = 0; uint32_t timeLORA2 = 0;
// Set ESP-NOW send and receive callbacks for either ESP8266 or ESP32 // Set ESP-NOW send and receive callbacks for either ESP8266 or ESP32
@ -234,47 +225,47 @@ void bufferESPNOW(uint8_t interface) {
switch (interface) { switch (interface) {
case 0: case 0:
memcpy(&ESPNOWGbuffer[lenESPNOWG],&theData[0],ln); memcpy(&ESPNOWGbuffer.buffer[eSPNOWGbuffer.len],&theData[0],ln);
lenESPNOWG += ln; eSPNOWGbuffer.len += ln;
break; break;
case 1: case 1:
memcpy(&ESPNOW1buffer[lenESPNOW2],&theData[0],ln); memcpy(&ESPNOW1buffer.buffer[eSPNOW1buffer.len],&theData[0],ln);
lenESPNOW2 += ln; eSPNOW1buffer.len += ln;
break; break;
case 2: case 2:
memcpy(&ESPNOW2buffer[lenESPNOW2],&theData[0],ln); memcpy(&ESPNOW2buffer.buffer[eSPNOW2buffer.len],&theData[0],ln);
lenESPNOW2 += ln; eSPNOW2buffer.len += ln;
break; break;
} }
} }
void bufferSerial() { void bufferSerial() {
DBG("Buffering Serial."); DBG("Buffering Serial.");
memcpy(&SERIALbuffer[lenSERIAL],&theData[0],ln); memcpy(&SERIALbuffer.buffer[sERIALbuffer.len],&theData[0],ln);
lenSERIAL += ln; sERIALbuffer.len += ln;
//UART_IF.println("SENDSERIAL:" + String(lenSERIAL) + " "); //UART_IF.println("SENDSERIAL:" + String(sERIALbuffer.len) + " ");
} }
void bufferMQTT() { void bufferMQTT() {
DBG("Buffering MQTT."); DBG("Buffering MQTT.");
memcpy(&MQTTbuffer[lenMQTT],&theData[0],ln); memcpy(&MQTTbuffer.buffer[mQTTbuffer.len],&theData[0],ln);
lenMQTT += ln; mQTTbuffer.len += ln;
} }
void bufferLoRa(uint8_t interface) { void bufferLoRa(uint8_t interface) {
DBG("Buffering LoRa."); DBG("Buffering LoRa.");
switch (interface) { switch (interface) {
case 0: case 0:
memcpy(&LORAGbuffer[lenLORAG],&theData[0],ln); memcpy(&LORAGbuffer.buffer[lORAGbuffer.len],&theData[0],ln);
lenLORAG += ln; lORAGbuffer.len += ln;
break; break;
case 1: case 1:
memcpy(&LORA1buffer[lenLORA1],&theData[0],ln); memcpy(&LORA1buffer.buffer[lORA1buffer.len],&theData[0],ln);
lenLORA1 += ln; lORA1buffer.len += ln;
break; break;
case 2: case 2:
memcpy(&LORA2buffer[lenLORA2],&theData[0],ln); memcpy(&LORA2buffer.buffer[lORA2buffer.len],&theData[0],ln);
lenLORA2 += ln; lORA2buffer.len += ln;
break; break;
} }
} }
@ -300,13 +291,13 @@ void releaseESPNOW(uint8_t interface) {
DBG("Releasing ESP-NOW."); DBG("Releasing ESP-NOW.");
switch (interface) { switch (interface) {
case 0: case 0:
espSend(broadcast_mac,ESPNOWGbuffer,&lenESPNOWG); espSend(broadcast_mac,ESPNOWGbuffer.buffer,&eSPNOWGbuffer.len);
break; break;
case 1: case 1:
espSend(ESPNOW1,ESPNOW1buffer,&lenESPNOW1); espSend(ESPNOW1,ESPNOW1buffer.buffer,&eSPNOW1buffer.len);
break; break;
case 2: case 2:
espSend(ESPNOW2,ESPNOW2buffer,&lenESPNOW2); espSend(ESPNOW2,ESPNOW2buffer.buffer,&eSPNOW2buffer.len);
break; break;
} }
} }
@ -350,13 +341,13 @@ void releaseLoRa(uint8_t interface) {
switch (interface) { switch (interface) {
case 0: case 0:
LoRaSend(broadcast_mac,LORAGbuffer,&lenLORAG); LoRaSend(broadcast_mac,LORAGbuffer.buffer,&lORAGbuffer.len);
break; break;
case 1: case 1:
LoRaSend(LoRa1,LORA1buffer,&lenLORA1); LoRaSend(LoRa1,LORA1buffer.buffer,&lORA1buffer.len);
break; break;
case 2: case 2:
LoRaSend(LoRa2,LORA2buffer,&lenLORA2); LoRaSend(LoRa2,LORA2buffer.buffer,&lORA2buffer.len);
break; break;
} }
#endif #endif
@ -365,29 +356,29 @@ void releaseLoRa(uint8_t interface) {
void releaseSerial() { void releaseSerial() {
DBG("Releasing Serial."); DBG("Releasing Serial.");
DynamicJsonDocument doc(24576); DynamicJsonDocument doc(24576);
for (int i = 0; i < lenSERIAL; i++) { for (int i = 0; i < sERIALbuffer.len; i++) {
doc[i]["id"] = SERIALbuffer[i].id; doc[i]["id"] = SERIALbuffer.buffer[i].id;
doc[i]["type"] = SERIALbuffer[i].t; doc[i]["type"] = SERIALbuffer.buffer[i].t;
doc[i]["data"] = SERIALbuffer[i].d; doc[i]["data"] = SERIALbuffer.buffer[i].d;
} }
serializeJson(doc, UART_IF); serializeJson(doc, UART_IF);
UART_IF.println(); UART_IF.println();
lenSERIAL = 0; sERIALbuffer.len = 0;
} }
void releaseMQTT() { void releaseMQTT() {
#ifdef USE_WIFI #ifdef USE_WIFI
DBG("Releasing MQTT."); DBG("Releasing MQTT.");
DynamicJsonDocument doc(24576); DynamicJsonDocument doc(24576);
for (int i = 0; i < lenMQTT; i++) { for (int i = 0; i < mQTTbuffer.len; i++) {
doc[i]["id"] = MQTTbuffer[i].id; doc[i]["id"] = MQTTbuffer.buffer[i].id;
doc[i]["type"] = MQTTbuffer[i].t; doc[i]["type"] = MQTTbuffer.buffer[i].t;
doc[i]["data"] = MQTTbuffer[i].d; doc[i]["data"] = MQTTbuffer.buffer[i].d;
} }
String outgoingString; String outgoingString;
serializeJson(doc, outgoingString); serializeJson(doc, outgoingString);
client.publish(TOPIC_DATA, (char*) outgoingString.c_str()); client.publish(TOPIC_DATA, (char*) outgoingString.c_str());
lenMQTT = 0; mQTTbuffer.len = 0;
#endif #endif
} }
@ -407,7 +398,6 @@ void reconnect() {
#endif #endif
} }
void begin_espnow() { void begin_espnow() {
DBG("Initializing ESP-NOW!"); DBG("Initializing ESP-NOW!");
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);

View File

@ -106,4 +106,6 @@ void releaseMQTT();
void reconnect(); void reconnect();
void begin_espnow();
#endif #endif