Rechercher dans ce blog

dimanche 29 avril 2012

7. Yoctopuce

Now, we can start the analysis part of Yoctopuce devices. These devices are low cost devices that you plug on your USB port.  For the purpose of this demo, I bought this device: https://www.yoctopuce.com/EN/products/yocto-meteo

If you have a native interface, you can directly use a library but in my case, I do not. So, I will use a tool called VirtualHub which provides a simple REST interface.

When the yocto-meteo is plugged and VirtualHub is running. You should be able to go on http://127.0.0.1:4444 and see this page:





This means that the devices and VirtualHub are working properly. We can see there are two devices:


  • VirtualHub: the device to which the different functions are plugged. In this case only yocto-meteo but we could envision there are more.
  • Yocto-meteo: the device itself. In this screenshot, we could click on the it and get the temperature, humidity and pressure.
Anyway, we do not care about this UI. We are analyzing how to access it from a java source code, so let's use the JSON url which is: http://127.0.0.1:4444/api.json. The result you should get is something like this:


{
"module":{"productName":"VirtualHub","serialNumber":"VIRTHUB0-480741bdd3","logicalName":"","productId":0,"productRelease":1,"firmwareRelease":"6019","persistentSettings":0,"luminosity":50,"beacon":0,"upTime":4245111515,"usbCurrent":0,"realmHTTP":"YoctoDevices","adminPassword":"","userPassword":"","rebootCountdown":0,"usbBandwidth":0},
"services":{
"whitePages":[
{"serialNumber":"VIRTHUB0-480741bdd3","logicalName":"","productName":"VirtualHub","productId":0,"networkUrl":"/api","beacon":0,"index":0},
{"serialNumber":"METEOMK1-0268C","logicalName":"","productName":"Yocto-Meteo","productId":24,"networkUrl":"/bySerial/METEOMK1-0268C/api","beacon":0,"index":1}],
"yellowPages":{
"DataLogger":[
{"hardwareId":"METEOMK1-0268C.dataLogger","logicalName":"","advertisedValue":"OFF","index":0}],
"Temperature":[
{"hardwareId":"METEOMK1-0268C.temperature","logicalName":"","advertisedValue":"23.4","index":1}],
"Pressure":[
{"hardwareId":"METEOMK1-0268C.pressure","logicalName":"","advertisedValue":"958.0","index":2}],
"Humidity":[
{"hardwareId":"METEOMK1-0268C.humidity","logicalName":"","advertisedValue":"44.0","index":3}]}}}

There are a few interesting sections which are useful:


  • services.whitePages: contains the description of all the modules
  • service.yellowPages: contains the relevant values for the different modules
I decided to use the whitePages to get the information even if it is slightly more complex...

So, let's look on an whitePage entry:

{"serialNumber":"METEOMK1-0268C","logicalName":"","productName":"YoctoMeteo","productId":24,"networkUrl":"/bySerial/METEOMK1-0268C/api","beacon":0,"index":1}]

We can see already a lot of information:


  • The serial number which is unique to each yoctopuce device
  • The productId corresponding to the device. ProductName provides the same human-readable value
  • networkUrl: corresponds to the URL where to access the particular device values.
Let's take a deeper look on the network url and try to append the current URL + networkURL (http://127.0.0.1:4444/bySerial/METEOMK1-0268C/api): we get this page:


This provides us all the information about the selected device, in this case the yocto-meteo. As before, we do not care about the fancy widgets but only about the data: so let's append .json to the URL:



{
"module":{"productName":"Yocto-Meteo","serialNumber":"METEOMK1-0268C","logicalName":"","productId":24,"productRelease":1,"firmwareRelease":"5991","persistentSettings":2,"luminosity":50,"beacon":0,"upTime":231437,"usbCurrent":27,"realmHTTP":"YoctoDevices","adminPassword":"","userPassword":"","rebootCountdown":0,"usbBandwidth":0},
"humidity":{"logicalName":"","advertisedValue":"38.0","currentValue":2490368,"lowestValue":2490368,"highestValue":3145728},
"pressure":{"logicalName":"","advertisedValue":"959.0","currentValue":62783488,"lowestValue":62717952,"highestValue":62849024},
"temperature":{"logicalName":"","advertisedValue":"25.6","currentValue":1675264,"lowestValue":1458176,"highestValue":1675264},
"dataLogger":{"logicalName":"","advertisedValue":"OFF","oldestRunIndex":0,"currentRunIndex":1,"samplingInterval":1,"timeUTC":0,"recording":0,"autoStart":0,"clearHistory":0}}

And we get here, the temperature, pressure, humidity, etc. Now that we have everything, we can start the development and write a JAVA API.

Aucun commentaire:

Enregistrer un commentaire