Professional Documents
Culture Documents
Page | 1
9-Feb-12
JMLambert V1.0
Introduction
After the previous exercise with a Flyport Simulator connected to the web services, I will expose the experience and solution of the following problem : Acquire Temperature & Pressure of a BMP085 device on a I2C bus Set the Real Time clock to the web time and use an alarm to acquire regularly the measurements Send the measurements to some Cloud storage, (I have integrated successfully NimBits, ThingSpeak, Paraimpu and Pachube) Display the curves of the measurements on the web page of the Flyport. Setup a LCD display HD44780 connected to the Flyport with I2C bus, thanks to I2C driver chip that is easy and low cost and need less wires. Display some values on the local LCD as a weather station
As explained above, I tried different Web Services to store the data, and Pachube seems quite good as it allows a very easy graphing out of the data. But Pachube is not able to process the Data and generate alerts (it seems) as easy as with ParaImpu I chose to create a Pachube sensor in Paraimpu, and a connector inside Paraimpu that will tweet a message when an alert is raised. We will see how.
After some initial issue on the I2C reading, I fixed the soldering I just connected the required wires : GND+VCC + I2C Bus : SCL+SDA
Page | 2
9-Feb-12
JMLambert V1.0
Page | 3
9-Feb-12
JMLambert V1.0
Then, the time will be set in the RTCC and next steps :
Page | 4
9-Feb-12
JMLambert V1.0
Page | 5
9-Feb-12
JMLambert V1.0
This function is the one that will prepare the right strings in the display buffer for the iFieldNum field.
The above pointers are filled with Malloc to allocate the right size to the array. I put 2 sets of strings, the one Requested, that is prepared with the above formatting elements and the one Content that is filled after the LCD is updated. This allows sending messages to the LCD only when a char has changed, and reduce the number of useless I2C message. If we put the time HH:MM::SS, anyway, the update will be at least each second, but if you put only minutes, then the message will only be sent every minute or if a displayed measure changes.
http://www.i2c.byvac.com/downloads/BV4208%20DataSheet.pdf
A set of commands is declared for this driver that is quite simple. The LCD I2C Driver is also containing a EEPROM, that may be used for preset messages, but also to store your own params independently of the OpenPicus file system.
Page | 6
9-Feb-12
JMLambert V1.0
We will use the I2CHelper library completed as described above to send long strings. Note : I am preparing a library for that chip, but as I did not received the LCD from my order, I cannot test it This will be in the V2 of the document.
Page | 7
9-Feb-12
JMLambert V1.0
Sensor declaration
You need to declare your sensor (Feed) that may contain several datastreams. The feeds is at the url: /feeds/<feednumber> and you will have some access keys.
For example : Here I create a key that would be able to UPDATE only the pressure datastream of the feed 47332
Then the Key provided will be put in the URL of access for the action (PUT/GET/DELETE etc) in the http header field X-PachubeApiKey: Page | 8 9-Feb-12 JMLambert V1.0
You may also regenerate the key, if you do not know if your key has been compromised. The http requests are well documented in the API manual of Pachube here https://pachube.com/docs/ Once you have declared your feed, your datastreams (with an ID that will be used in the API call), and you have got the key allowed to access the stream, you will need to put them in your program.
For easy cases, it if obvious that the CSV is preferred. The selection of the format is made at the URL level
http://api.pachube.com/v2/feeds/1977/datastreams/1.csv
For CSV the data string will contain one value per line (each line separated by \r\n) Example : 1,20.5\r\n2,1013.0\r\n means assign 20.5 to the datastream 1 and 1013.0 to datastream 2. In this project, I construct this string that will be sent to the api.pachube.com url via a PUT request : sprintf( tmpString, "PUT %s HTTP/1.1\r\nHost: %s\r\nAccept: */*\r\nContent-Type: text/csv\r\nX-PachubeApiKey:%s\r\nContent-Length: %d\r\nConnection: close\r\n\r\n%s", RemoteURL, ServerName, PachubeKey, strlen(buf), buf );
Page | 9
9-Feb-12
JMLambert V1.0
Pachube Graphing
By default, Pachube proposes a graph of all datastream like that :
You may tune the graphic by the parameter button and generate a URL of the result to include in your Flyport webpage. Your browser will get the URL from the flyport, but will get the display from the Pachube site. https://api.pachube.com/v2/feeds/47332/datastreams/1.png?width=730&height=250&colour=%23f15a24&duration =1day&show_axis_labels=true&detailed_grid=true&timezone=UTC The duration is a parameter that you may manually change or even put a dynamic field inside to change that dynamically (~my_duration~) to replace the 1day above by a choice you may integrate in your web page. (eg: popup)
Triggers/ Alerts
You may have some triggers on some datastream, to generate alerts in twitter or SMS. I have tested the SMS alert, but not the tweet. There are several applications around Pachube that you may explore too.
Page | 10
9-Feb-12
JMLambert V1.0
And the last point is the connection that is making the link between the sensor data and the actuator :
You may have a message going to your actuator depending on the value received on the sensor. Here I just put a message depending on the temperature. You may create a message with smart content to have a script interpreted in your flyport for example.
Page | 11
9-Feb-12
JMLambert V1.0
Misc
I used the malloc/free to manage the dynamic memory allocation. I just added the heap.s file in the project directory to create a heap of 2000bytes.
Then you just need to declare pointers and allocate memory that you assigned to that pointer.
Standard example :
This is quite useful for the http requests of body that do not need to be kept very longtime.
Page | 12
9-Feb-12
JMLambert V1.0