JSON Web Server

Turns the script into a JSON REST server. Access it in a browser at http://<Q5 IP>/app/abc.

// Example JSON rest webserver
// Access the test webserver in your browser at http://<Q5 IP>/app/abc

setEnv("http.aesKey","myAesPassphrase"); // Set end to end encryption key (Only used if encryption is enabled), if not set the system password is used


function handleHttp(req){

   print(string(req));

  if(req.url === 'abc')
  {

    let reply = {
      batteryVoltage: 14.8,
      io: io,
      uptime: now(),
      epoch:  datetime().epoch
    };

    return string(reply);
  }

  return "Invalid Request URL, try /app/abc";

}


http.handle(handleHttp, // request handler funciton
            false); // no aes encryption

while(run()){
  waitMS(1000); // wait 1 second
}