Sie sind auf Seite 1von 2

/* Tux Clous Test Gold Standard */ #include <SPI.h> #include <Ethernet.

h> // assign a MAC address for the ethernet controller. // Newer Ethernet shields have a MAC address printed on a sticker on the shield // fill in your address here: byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // fill in an available IP address on your network here, // for manual configuration: IPAddress ip(10,1,10,99); // initialize the library instance: EthernetClient client; // if you don't want to use DNS (and reduce your sketch size) // use the numeric IP instead of the name for the server: char server[] = "staging.water-cents.com"; unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds boolean lastConnected = false; // state of the connection last t ime through the main loop const unsigned long postingInterval = 360*1000; //delay between updates to Cosm. com void setup() { // start serial port: Serial.begin(9600); // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // DHCP failed, so use a fixed IP address: Ethernet.begin(mac, ip); } } void loop() { // read the analog sensor: int sensorReading = analogRead(A0); // // // if } // if there's no net connection, but there was one last time // through the loop, then stop the client: if (!client.connected() && lastConnected) { Serial.println(); Serial.println("disconnecting."); client.stop(); } if there's incoming data from the net connection. send it out the serial port. This is for debugging purposes only: (client.available()) { char c = client.read(); Serial.print(c);

// if you're not connected, and ten seconds have passed since // your last connection, then connect again and send data: if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) { sendData(sensorReading); } // store the state of the connection for next time through // the loop: lastConnected = client.connected(); } // this method makes a HTTP connection to the server: void sendData(int thisData) { // if there's a successful connection: Serial.println(millis()); if (client.connect(server, 8080)) { Serial.println('connecting...'); client.println("POST /api/RawMeasurements HTTP/1.1"); client.println("Content-Type: application/json; charset=utf-8"); client.println("Host: staging.water-cents.com"); client.println("Content-Length: 72"); client.println("Expect: 72-Continue"); client.println("Connection: close"); client.println(); /*client.println("{\"RawValue\"\"id\"\"type\":\"ICCID\",\"v\":\"890126076223 3172015\"},"); client.println("\"ms\":[{\"ts\":\"TimeStamp\","); client.println("\"wtr\"\"wmt\":\"CUMM\",\"wmv\":\"1\",\"wms\":\"100\",\"wmu\ ":\"GAL\"},"); client.println("\"tmp\"\"tmt\":\"AIR\",\"tmv\":\"22.16\",\"tms\":\"C\",\"tmu \":\"DEG\""); client.println("}}]}}"); */ client.println("{\"RawValue\":\"{\\\"id\\\":{\\\"type\\\":\\\"ICCID\\\",\\\" v\\\":\\\"8901260762233172015\\\"}}\"},"); client.println("\\\"ms\\\":[{\\\"ts\\\":\\\"TimeStamp\\\","); client.println("\\\"wtr\\\":{\\\"wmt\\\":\\\"CUMM\\\",\\\"wmv\\\":\\\"1\\\",\\\" wms\\\":\\\"100\\\",\\\"wmu\\\":\\\"GAL\\\"},"); client.println("\\\"tmp\\\":{\\\"tmt\\\":\\\"AIR\\\",\\\"tmv\\\":\\\"22.16\\\",\ \\"tms\\\":\\\"C\\\",\\\"tmu\\\":\\\"DEG\\\""); client.println("}}]}}"); } else { // if you couldn't make a connection: Serial.println("connection failed"); Serial.println(); Serial.println("disconnecting."); client.stop(); } // note the time that the connection was made or attempted: lastConnectionTime = millis(); Serial.println(millis()); }

Das könnte Ihnen auch gefallen