Вы находитесь на странице: 1из 8

OpenPicus Web Controlled Simulator & Tweet, Nimbits and ThingSpeak messages

This project is integrating several technologies, found during the investigation of my new FlyPort : Web server Wifi connection Dynamic variables substitutions (in xml files) Ajax callbacks jQuery use case Dynamic Memory allocation (malloc/free) (see heap.s) Web service calls : for tweeter, thingspeak and nimbits

The web page here is explaining the outcome :

Architecture of the project :


The Flyport is connected to my PC for development, and power. I use my tablet as a browser for controlling the simulator User Interface, as well as to get the results of the web services published by the FlyPort on the right side.

I created accounts for Nimbits, Thingspeak and declare some channels inside to be able to publish. I used for the test my own twitter, but it is advised to change by a dedicated account for the sensors you want to monitor. For twitter, you will get a key to let your sensor write into the stream. For Thingspeak & Nimbits, idem, you will need a key for sending your data to the right channel.

Web page : index.htm and its Flyport processing,

File buttons.cgi and its processing.


Note : The buttons.cgi file contains : When calling the Flyport web server, the function HTTPPrint_cgi() is called. Here we have choosen to toggle a led only.

Ajax processing of files : status.xml & data.xml


I have integrated the jQuery exemple with the file main.js(see above) included in the index.htm page

You see in the index.htm page 3 mydynvar areas that will be set by the function called readData() This readData() is making a get of the data.xml file of the Flyport server. While processing the data.xml content below, you see that 2 variables t & rh will be substituted by the result of the server call of the HTTPPrint_xxx() functions.

2nd Ajax example :


In the status.xml that is called by the Javascript of the index.htm directly, the similar substitution is made in the server. The newAjaxcommand is launching the updateStatus javascript function every 500mS. Inside the updateStatus, the data is received and the setDisplay will display the numbers on the web page (big digits)

Here ~t~ and ~rh~ will be replaced by the values returned by the HTTPPrint_t &nd HTTPPrint_rh in the server.

Posting messages to tweeter & others


While a button is pressed, the status is set in the server, in one variable that is shared with the main loop. A switch is used to select the right operation to make depending of the users choice

Then 2 libraries are integrated to the project Nimbits.c/.h Thingspeak.c/.h (included tweet and thingspeak, as well as query not demonstrated in that case)

I updated the nimbits(simplified, as it was crashing) void wfNIMBITS(char* hostappspot, char* email, char* secret, char* namevalue, float* value); I also integrated some dynamic memory allocation to avoid the static alloc of hundreds of bytes in each function that will not be released. Use of malloc / free. For that I integrated a heap.s file in the project directory

corresponds to a heap of 2000 bytes.

Reusing the sources & testing the project on your own


1. Edit the myaccounts.h file and put inside the keys you will get from Twitter, ThingSpeak and Nimbits

If you do want to remove some, just remove the call to the function in the main task code. 2. 3. 4. 5. 6. Then in the OpenPicus IDE, open the existing project file temperatura.conf Click on the Wizard for the connection setup, and the Web Pages button to generate the intermediate code. Launch the compilation of the project. Download to the Flyport

Then connect your browser to the IP address of your http Flyport defined in the configuration wizard (like 192.168.0.27) You should see the main page as above. Then you will check that your actions to send message is fine by connecting to each of the sites (twitter, thingspeak or nimbits) to verify that the messages are well received and recorded. I have noticed that the processing of one message is lasting >10 seconds, so you have to wait between clicks It could be improved by putting some real time programming like critical areas and semaphores, but for this project it is fine with me.

Вам также может понравиться