Friday, May 20, 2016

Java and Edison: Configuration, not Code

I decided to try to see if it was possible, and how difficult, to develop a configurable Java program for Intel Edison.

What do I mean as configurable?

I wanted a Java program able to run and:

1. Read a set of analog sensors connected, in a continuous loop

2. Be able to specify through a configuration file (config.properties) the type of sensors and the pins used

3. Be able to send a MQTT message to a MQTT broker, containing all the readings from sensors

4. Be able to specify the broker destination in the config file.

It is still a trial, but I succeeded. The configurable parameters are:

1. Type of sensor.

2. Pins used

3. Interval between readings

4. URL of the broker

One of the problems was that the UPM classes have not a uniform interface. For some classes the method to be used is getValue(), for others a different signature.

Therefore I have defined a Sensor Interface and a set of classes, extending the UPM class for the relative sensor and implementing the Sensor Interface.

This way all the object created for sensors are inserted in a List<ISensor> and I can literate.

The repository for the code is:

https://github.com/luigisaetta/edison-java-projects/tree/master/RoomStation

Inside you can also find an example for the config.properties.

For the tests I have used:

1. Intel Edison, with Arduino Board;

2. Grove Shield

3. Grove Temp, Grove Light and Grove TP401 Gas sensor

4. RabbitMQ MQTT broker, installed on a RPI.

This is the format of JSON msgs sent. Formatted using Google GSON library. 

{
   "id":"thunder10",
   "type":"Edison",
   "date":"May 23, 2016 9:16:13 AM",
   "readings":[
      {
         "type":"Grove.Temp",
         "unit":"C",
         "value":"25.0"
      },
      {
         "type":"Grove.Light",
         "unit":"LUX",
         "value":"324.0"
      },
      {
         "type":"Grove.TP401",
         "unit":"PPM",
         "value":"83"
      }
   ]
}
 
Nice.

No comments:

Post a Comment