JSON Send Measurements to Server

Streams JSON measurements to a server by POSTing on an interval, with upload error handling. The server can reply with commands (e.g. relay changes).

// Example stream JSON measurements to server

function sendMeasurement(host){

    let payload = {
      batteryVoltage:14.3,
      uptime: now()
    };

    let res = http.req(host, 			// url
                       string(payload),	// payload
                       1000,			// timeout
                       false);			// aes encryption

    if(res.err === 0 || res.code === 200){
    print("Received from server",string(res));

    // Could receive messages back from server to change relays etc... See web client example for more info

    } else {
    print("Upload Error, http status=",res.code);
    }

}



while(run()){


  sendMeasurement("http://myserver.com/url");
  // server will receive a POST request with the json payload specified

  waitMS(5000);

}