Hello world!
So here's where I'm at. I have an SHT20 sensor connected to my Arduino Uno with an added Ethernet shield.
My goal is to send the data collected for the SHT20 over UDP to predetermined web server listening on a specific port.
I haven't set the port my will listen on yet. At the moment my Uno is listening on port 8888 for anything from my server's IP, and then return the temp and humidity data to the same IP and Port. If another IP sends a UDP packet by chance or maliciously, the arduino ignores it.
So far it seems to do everything up to that point and I caught the packet manually on my "server" (currently just my laptop) with wireshark.
Here's snippet of my UDP packet code:
void loop() {
//if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize) {
if (Udp.remoteIP() == listeningFor) {
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i=0; i < 4; i++) {
Serial.print(remote[i], DEC);
if (i < 3) {
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBufffer
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer);
byte humd = sht20.readHumidity(); // Read Humidity
byte temp = sht20.readTemperature(); // Read Temperature
Serial.println();
Serial.println("Temperature: ");
Serial.print(temp);
Serial.println();
Serial.println("Humidity: ");
Serial.print(humd);
byte replyBuffer[] = {temp, humd};
// send a reply to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write("SHT20");
for (int i=0; i<2; i++){
Udp.write(replyBuffer[i]);
};
Udp.endPacket();
}
else {
Serial.print("Received Packet From Unknown Source ");
Serial.print(Udp.remoteIP());
}
}
delay(10);
}
Wireshark says the whole packet is 60bytes and the "Data" portion is 7bytes.
Given that I told the Uno to write "SHT20" as the packet message and the tmp & hum variable as individual bytes to the buffer array a total of 7 bytes make sense. 1 for each character in the string message and 1 for each data point.
So what I'm wondering is that the data reads: 53485432301426
Or: 0x53, 0x48, 0x54, 0x32, 0x30, 0x14, 0x26?
I've been all over ASCII tables: https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html
And can't make heads or tails of the result I caught.
If any of you could help shed some light on this I would really appreciate it. The following step after this is to build something on the server end to collect these datagrams and serve it to other, permissioned, clients.
Thanks so much! These forums have been a great help!