iot.status.js 683 B

12345678910111213141516171819202122232425262728293031
  1. //IoT Status
  2. //This agi script get the device status of the first iot device in list
  3. //Require the iot lib
  4. requirelib("iot");
  5. function main(){
  6. //Check if the IoT Controller is ready
  7. if (iot.ready() == true){
  8. //List the iot devices in the network
  9. var devList = iot.list();
  10. //Pick the first device to get status
  11. var firstDevice = devList[0];
  12. iot.connect(firstDevice);
  13. var deviceStatus = iot.status(firstDevice.DeviceUUID);
  14. //Return the results as respond
  15. var output = JSON.stringify(deviceStatus);
  16. HTTP_HEADER = "application/json; charset=utf-8";
  17. sendResp(output);
  18. }else{
  19. sendResp("IoT Manager not ready");
  20. }
  21. }
  22. //Run the main function
  23. main();