#include <SPI.h>
#include <Ethernet2.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(192, 168, 0, 228); // numeric IP for Google (no DNS)
//char server[] = "www.google.com"; // name address for Google (using DNS)
IPAddress ip(192, 168, 0, 229);
void setup() {
Serial.begin(9600);
Ethernet.init(4);
while (!Serial) {
}
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
delay(1000);
Serial.println("connecting...");
}
void loop()
{
EthernetClient client;
String data = "{\"login\":\"admin\",\"password\":\"qwerty\",\"deviceName\":\"ard\",\"deviceType\":\"nano\",\"sensorsValue\":{\"temp\":36.0,\"light\":1023.0,\"humiditu\":233.0}}";
if (client.connect(server, 8080)) {
Serial.println("connected");
client.println("POST /intler_iot_war_exploded/send-device-data HTTP/1.1");
client.println("Host: 192.168.0.228:8080");
client.println("Content-Type: application/json");
client.println("Connection: close");
client.print("Content-Length: ");
client.println(data.length());
client.println();
client.print(data);
client.println();
Serial.println(client);
}
else {
Serial.println("connection failed");
}
delay(1000);
}