O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

IoT with OpenPicus Flyport

1.120 visualizações

Publicada em

IoT with OpenPicus Flyport Temperature/Pressure with BMP085
I2C LCD setup Use case of Pachube and Paraimpu

Publicada em: Tecnologia, Negócios
  • Seja o primeiro a comentar

  • Seja a primeira pessoa a gostar disto

IoT with OpenPicus Flyport

  1. 1. Page | 1 9-Feb-12 JMLambert V1.0 IoT with OpenPicus Flyport : Temperature/Pressure with BMP085 I2C LCD setup Use case of Pachube and Paraimpu
  2. 2. Page | 2 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. I2C Bus & BMP085 acquision programming. I connected the BMP085 directly on the Flyport, as it handles already on board the pullup. I used the few libraries from the OpenPicus Download content : - OP-LIB - i2c Helper rev1.0.zip - LIB - BMP085 temperature sensor_rev1.0.zip After some initial issue on the I2C reading, I fixed the soldering… I just connected the required wires : GND+VCC + I2C Bus : SCL+SDA
  3. 3. Page | 3 9-Feb-12 JMLambert V1.0 Web time & RTCC Programming The objective is to get the current time from an external web site (always included in a response), then set the time in the RTCC and create alarms from the RTC at regular interval to perform the acquisition and sensor data transmission to the storage (not too often) Get the time from a web site header : www.google.com In aim to get the time, the simpler is to make a POST request to a site, and analyses the header response. Then you extract the fields and use them to initialize the RTCC.
  4. 4. Page | 4 9-Feb-12 JMLambert V1.0 Then, the time will be set in the RTCC and next steps :
  5. 5. Page | 5 9-Feb-12 JMLambert V1.0 I2C Bus & LCD HD44780 I used also the I2CHelper library as above, but I needed to create a new function : New function : I2CSendString() To handle the LCD, I added a new function in complement to the I2CHelper : I2cSendString() This function is necessary to send messages to the I2C LCD and handles the split of messages within the max size of the I2C buffer (generally 32, but it is a parameter) LCD Display organization In aim to put some flexibility in the way to create and eventually change the content of the display dynamically, I have gone through some descriptions data.
  6. 6. Page | 6 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. LCD I2C Controller BV4208 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.
  7. 7. Page | 7 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.
  8. 8. Page | 8 9-Feb-12 JMLambert V1.0 Pachube Setup & use Pachube is a place to collect Sensor feeds, and allow their presentation in graphs. 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. API Keys & Access control You may have generic keys or specifics that have their own restrictions, (for example the key can be used to update only one datastream, or you may allow only one IP address as origin, as well for getting the data, you have some access controls. 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:
  9. 9. Page | 9 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. Web service format What is interesting is that you may use several formats to update the streams : JSON, XML or CSV 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 “rn”) Example : “1,20.5rn2,1013.0rn” 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.1rnHost: %srnAccept: */*rnContent-Type: text/csvrnX-PachubeApiKey:%srnContent-Length: %drnConnection: closernrn%s", RemoteURL, ServerName, PachubeKey, strlen(buf), buf );
  10. 10. Page | 10 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. Interface with Paraimpu Paraimpu is competitor of Pachube (beta) I have successfully connected my flyport to Paraimpu, but it is not featuring graphing yet. So I choosed Pachube for data & graphing, and tried Paraimpu for the tweets management; Identically to Pachube, you need to declare a sensor in Paraimpu and get a key to use the web service to publish your sensor data. There is an OpenPicus sensor template that you may use. This is in fact providing a piece of C code that can be the starter to make your sensor. The API key is included in the C code, and is not available in the Web Page. I have requested the change, as this seems not the best choice… In this project, the Pachube is seen as a sensor itself, and data are gathered from Pachube. Then I have declared a twitter Actuator with my twitter account.
  11. 11. Page | 11 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.
  12. 12. Page | 12 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.