Hi Folks,
I have a strange behaviour on using WiFiUDP with WiFiLink Firmware.
First, WiFiLink UDP-Lib V1.0.1 has a major bug in WiFiUDP.cpp. "availUdpData" has to be decreased in function "read(xxx)" by the actual read bytes. Scanning this class I think there are some other bugs but they dont affect my program.
My problem starts answering a status request UDP-package. I reserved an array of 48 bytes for building the UDP-packet. As long as I only use local variables, everything is fine.
But I have a global configuration class instance. If I try to add some values of the configuration into he packet, all values become zero. I have no clue why.
Here is the code snippet:
// Sendet das vollständige Statuspaket
void UdpService::SendStatusUdpPackage(IPAddress& addr, uint16_t port, Konfiguration* cfg)
{
// Temperatur und Feuchtigkeit
uint16_t temperatur = 0;
uint16_t hum = 0;
// alle Bytes im Puffer auf NULL
memset(_packetBuffer, 0, CPE_SW_PACKET_SIZE);
// Paket-Daten setzen für Funktion "CPE-SW#2017"
sprintf((char *)_packetBuffer, "CPE-SW#2017");
// Funktion = Status
_packetBuffer[12] = UdpFunctionCode::Status;
// Daten holen
temperatur = temp.GetValues(&hum);
// Feuchtigkeit
WriteUint16_t(_packetBuffer, 21, hum);
// Temperatur
WriteUint16_t(_packetBuffer, 23, temperatur);
// Lichtsensor
WriteUint16_t(_packetBuffer, 25, LastAnalogInputA0);
// und das Flag
_packetBuffer[27] = firmware.GetStatus();
// die anderen Werte
for (int i = 0; i < sizeof(Konfiguration); ++i)
_packetBuffer[13 + i] = ((byte )cfg);*
#ifdef USE_DEBUG
- Serial.print("Bytes=");*
- for (uint8_t i = 0; i < offset; ++i)*
- {*
_ Serial.print(buffer*);_
_ Serial.print(",");_
_ }_
_ Serial.println(".");_
_#endif*_
* // Zielport: der lokale Port*
* if (Udp.beginPacket(addr, port) == 1)
_ {*
* // Paket schreiben ...*
* Udp.write(packetBuffer, CPE_SW_PACKET_SIZE);
_ // ... und senden*
* Udp.endPacket();
_ }*
#ifdef USE_DEBUG
* Serial.print("After send=");*
* for (uint8_t i = 0; i < offset; ++i)
_ {*
_ Serial.print(buffer*);
Serial.print(",");
}
Serial.println(".");
#endif*
}
Any suggestions?
Greetings
Chris_