Saturday, May 7, 2016

Now with real sensors

The hardware configuration I’m going to test consist of an Edison Board equipped with a Grove Shield to which we have connected three sensors (for now Air Quality Sensor is not used):
  • Temperature sensor, to A0
  • Light sensor, to A1
To handle reading from sensors, we will use UPM library. As we will see the Node code is simple.

IMG 0145
With the following code, we read values from sensors and send every 2 secs. (in the config) a msg to AWS IoT, containing value read for temperature (C) and light (lux).

Configuration is read from a file (config.js), whose content is:

{
"keyPath" : "/node_app_slot/certs/thunder10-private.pem.key",
"certPath" : "/node_app_slot/certs/thunder10-certificate.pem.crt",
"caPath" : "/node_app_slot/certs/root-ca.crt",
"region" : "eu-west-1",
"clientId" : "thunder10",
"sleepTime" : 2000
 }

The last piece (config.js) shows you what must be considered a best practice: Keep separated the logic from the configuration, that probably needs to be different from device to device and maybe can change more frequently. This way you need only to replace the config.js file.

The nice thing with Edison is that, if you want to change the configuration, you can simply upload the config.js file Over The Air.

No comments:

Post a Comment