element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Internet of Things
  • Technologies
  • More
Internet of Things
Blog Sending Atmospheric Data from the MSP430 and Wi-Fi CC3100 BoosterPack to Plot.ly
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Internet of Things to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: kas.lewis
  • Date Created: 14 Sep 2014 7:15 AM Date Created
  • Views 4670 views
  • Likes 4 likes
  • Comments 16 comments
  • board
  • msp430f5529
  • xtrinsic
  • cc3100
  • sensor
  • mpl3115a
Related
Recommended

Sending Atmospheric Data from the MSP430 and Wi-Fi CC3100 BoosterPack to Plot.ly

kas.lewis
kas.lewis
14 Sep 2014

image

Figure 1. Terminal screen displaying live data being transmitted and demo Plot.ly graph

 

For a while now I have been thinking about the ability to remotely monitor what is going on environmentally in a location. I have thought about this with regards to the summer, with a cottage more than an hour away it would be nice to know what the weather pattern is for the cottages location (not the general city or county) to decide if it is worth the long drive. I have also thought about this with regards to parts of my house, such as the attic, basement etc, to help determine how well the insulation is working or what is going on in parts of the house where people may not often frequent. Lastly it has come up in many conversations with storekeepers who want to know how their fridges are performing and to know when there may be an issue. With all these usage cases I decided I should come up with a solution.

 

When TI came out with their CC3000CC3000 I thought I would give that a try. I spent a few weeks working with this BoosterPack in conjunction with a StellarisStellaris (Tiva Tiva C) and MSP430G2553MSP430G2553  launchpad but had a good few issues that just didn't seem easily resolvable as well as some limitations that hinder the usability of the system, besides by then TI had come out with the CC3100 CC3100 that was supposed to resolve a lot of issues as well as be some what easier to use.

imageimage

Figure 2. CC3100 layout and pin assignment

 

At the same time I was introduced to Plot.ly, an online graphing tool that allows for real time plotting of almost any form of data. After looking over how Plot.ly works I decided these two tools together would make a good start to resolving my real time remote data logging problem.

 

As I have a decent background with TI devices the use of TI products was a natural and convenient choice.The MSP430F5529LP MSP430F5529LP was chosen as the brains behind the system and as previously stated the CC3100  CC3100  was chosen for the Wi-Fi connection. The MSP430F5529LP MSP430F5529LP was chosen do to the wide availability of example code and wide usage of this launchpad with the CC3100CC3100.

image

Figure 3. MSP430F5529 pin assignment for use with BoosterPacks

 

The Wi-Fi connection is a CC3100 CC3100 Boosterpack that contains an integrated TCP stack and is interacted via SPI. One of the important features about this BoosterPack is its conformity to the BYOB (build your own board) standards.

 

image

Figure 4. Build Your Own Board pin assignment layout

 

This means that all the pin connections are in predetermined locations allowing for ease of use with other BoosterPacks. The sensor chosen is a MPL3115AMPL3115A pressure sensor from Freescale and was integrated using the Xtrinsic sensor boardXtrinsic sensor board from Element14 and Freescale. Lastly as this needs to be able to work in a remote location I decided to add a local power source, for this the Fuel Tank BoosterPackFuel Tank BoosterPack from Element14 was chosen. This choice however does present its own issue. The Fuel Tank BoosterPackFuel Tank BoosterPack does not conforme to the BYOB standard. With some connections in contention this board was connected via jumper leads and for now only provides power, the power monitoring ability of the BoosterPack has not been implemented but hopefully will be in a later iteration of this project.





image

Figure 5. Fuel Tank BoosterPack pin assignment (non-conforming)



The project is based on the TCP_Socket demo for the CC3100CC3100. This demo has the basics needed to connect to an access point (AP), open a socket and send data, this provides a very substantial start for the project. This code was modified one step at a time. The first step was to allow for data of my choosing to be transmitted. This was tested and verified using a piece of software from HW-Group called Hercules. This software allows you to have a server running on your PC and to easily receive and see incoming data. One this was done the code needed to be further modified to allow for one connection to be made and multiple packets of data to be transmitted. This was done by splitting the BSDclient function into two distinct functions. The first function would take care of creating a socket and connecting to it. The second function packetTx would then take care of transmitting the desired data. Once this was done (with some difficulty, see forum posts for details), it was time to start transmitting data to Plot.ly.

 

The website for Plot.ly origanly did not provide a lot information if you were not using one of there standard platforms (Arduino, Matlab, etc) or one of there chosen languages (Python, R, Arduino), I therefore had to take the Arduino code (the easiest to understand) and parse it so it could be used in the format needed by the CC3100CC3100. From this code (Plotly’s Arduino code) I was able to create a graph using the REST API commands. These commands in their most basic form look like this:

 

POST /clientresp HTTP/1.1

Host: 107.21.214.199

User-Agent: MSP430F5529/0.5.1

Content-Length: 243

 

where the IP address “107.21.214.199” is the address of Plot.ly. The content length is the length of the following string in bytes that actually creates the graph (Note each line is terminated with a carriage return as well as a new line (“\r\n”)):

 

version=2.2&origin=plot&platform=Stellaris&un=Kas&key=ABCDEFGHI&args=[{"y": [], "x": [], "type": "scatter", "stream": {"token": "1234567890", "maxpoints": 500}}]&kwargs={"fileopt": "overwrite", "filename": "test plot", "world_readable": true}

 

I will explain this string briefly. Platform is the platform or language being used, from what I can tell changing this has no effect on how the graph behaves. “un” is the username, mine is Kas. “key” is your unique identifier key that allows access to your account. “args” is used to set up the individual traces, in this case I have only one trace so there is only one set of args. if you wanted more than one trace you would use something like this:

 

version=2.2&origin=plot&platform=MSP430F5529&un=Kas&key=ABCDEFGHI

 

&args=[{"y": [],"x": [],"name": "Temperature","type": "scatter", "stream": {"token": "1234567890", "maxpoints": 500},"yaxis":"y1"}, {"y": [],"x": [],"name": "Pressure","type": "scatter", "stream": {"token": "1a2b3c4d5e", "maxpoints": 500}, "yaxis": "y2"}]

 

&kwargs={"filename": "Temperature and Pressure", "fileopt": "overwrite", "style": {"type": "scatter"}, "layout": {"title": "Temperature and Pressure vs. Time", "xaxis": {"title": "Time (s)"}, "yaxis": {"title": "Temperature (Celsius)"}, "yaxis2": {"title": "Pressure"}}, "world_readable": true}





for a full listing of commands you can look at this documentation. “kwargs” is the settings for the overall graph such as the title, public/private access as well as others. At this point I had a graph created and was able to see it in my workspace on the Plot.ly website. I now needed to stream data, using the Arduino code for this however did not appear to help very much. I will again show the commands to open a stream and stream data and then explain them.

 

POST / HTTP/1.1

Host: stream.plot.ly

User-Agent: Python

Transfer-Encoding: chunked

Connection: keep-alive

plotly-streamtoken: 1234567890

 

In this code the main command that you need to edit is “plotly-streamtoken”. This line is used to specify the specific trace that this data should be posted to, it is the same as the token in the args passed to create the graph. Note each line is terminated with a carriage return as well as a new line (“\r\n”). Once the stream is open data can be sent to tos graph and trace specified this is done by the following line:

 

3134

{"x":1,"y":5}

3134

{"x":2,"y":5}

 

This is where it gets confusing, the 3135 appears to be meaningless but is is infact hex for 14. There are 14 bytes transmitted here including a new line. The “X” value here can be seen to be 1, 2 and the “Y” value is 5. The order of the “X” and ”Y” does not appear to matter. Data must be transmitted once per minute or Plot.ly closes the stream, you can choose to reopen the stream (Plot.ly would prefer you don’t consttly open and close sockets) or preferably send a heartbeat (“\r\n”) if it will be longer then a minute before your next data transmission. Now that we can open a connection with Plot.ly using the CC3100CC3100, stream data to plot in reat time its time to get the data from the desired sensor.

 

I chose to use the MPL3115AMPL3115A as it is a relatively simple sensor to use and I had one laying around. The MPL3115AMPL3115A uses I2C to communicate and once set up to take a reading every second there is not much to do other than poll for data. This will eventually be changed to an interrupt based system which would ideally allow for the MSP430F5529LP MSP430F5529LP to sleep for approximately 95% of the time (back of the envelope calculation) increasing the units life by orders of magnitude.

 

imageimage

Figure 6. Xtrinsic Sensor Board and pin assignment configuration

 

This code was initially developed separately from the TCP_Socket code and was slowly merged allowing for issues to be easily resolved. The main issue encountered was the “Error: "Program will not fit into" after adding interrupt handler” this was eventually resolved by simply removing the interrupt handler for “USCI_B1_ISR” in board.c. Once the data is read in it needs to be changed to a string and assembeled as message that Plot.ly can interpret. This is all done in the “plotlyPlotString” function, two integers are passed in as well as a pointer to a char array. The integers are converted to chars and inserted into the string ready to be sent to Plot.ly (this function in its entierty can be confusing so if anyone would like more clarification I would be happy to further exlpain it below). One integrated and tested the system performed pretty well.

 

image imageFigure 7. MSP430F5529 with CC3100 BoosterPack mounted and connected to the Xtrinsic Sensor Board (P4.1, P4.2) and Fuel Tank BoosterPack (3.3V, 5V, GND)

 

Next Steps

Moving forward there are a number of improvements that need to be made. As of now the system disconnects from Plot.ly after ~530 data points (this does not happen with the Hercules server), this issue will need to be resolved and is currently under further investigation. There is also the issue of inadvertent disconnections from the AP that for a robust system will need to be taken care of, this will involve checking that the connection has not been closed and if it has, to reconnect. There is also the need to check that the socket has not been closed and again if it has to reopen it before continuing to send data. Lastly for complete robutness the system should be able to check for error messages from Plot.ly and react to them in a meanigfull manour.

 

Besides for these steps the inclusion of pressure data on a separate “Y” axis would allow for a better use of the chosen sensor. Also the full implementation of the Fuel Tank BoosterPackFuel Tank BoosterPack with power monitoring and plotting time remaining, battery voltage and possibly other metrics would be a useful addition.

 

I will update this post as the project evolves. If you have any questions or comments I would be happy to address them in the comments below.





For those who would like to try this and may run into the same issues I have, I have included a link to the issues I had and how TI helped me resolve each of them

 

CC3100

Can't use I2C device with CC3100BOOST

CC3100 TCP Client Receive

Can't use I2C device with CC3100BOOST

MPS430F5529 Low Power Mode Hanging.

Code hanging at "establishConnectionWithAP(); "

CC3100BOOST Rev 3.1 vs Rev 3.3

Upgrading CC3100 Firmware

Error: "Program will not ft into" after adding interrupt handler

CC3100 Error while sending the data

Get_Time / Get_Weather Code size issue

CC3100 + MSP430F5529 No Console Output

 

 

MSP430F5529 I2C Example Issues

 

 

 



 





Tweet

Follow @Kazzzzzzzzzzz

Follow Kas' blog
Attachments:
  • Sign in to reply
  • Former Member
    Former Member over 9 years ago in reply to kas.lewis

    Thanks Kas,

     

    Those carriage return / line feeds was definately a problem..   to make it a bit easier to use Hercules, I'm sending the POST string in ascii, and then separatly, the 0D 0A as HEX.   This seemed to at least get plot.ly to respond.    

     

    Another issue I had was the character counting..  to that end I used charactercountonline.com and just pasted the version=2.2..."world_readable":true}  string, to see what the count should be.   This seems to work ok.

     

    I'm still trying to get it to accept my initialization and plot data, but I think there's hope!   This is my first time trying to do anything API/web-related so it's been a bit of a learning curve.   I wonder if Plot.ly is uniquly unforgiving, or do all these type of REST services behave the same (desmos, tableau, etc).     I'll post back my results!

     

    Thanks for help, cheers!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • kas.lewis
    kas.lewis over 9 years ago in reply to Former Member

    Hello Chris,

     

    Sorry about the VERY SLOW response. I see what you are going through, that was part of the fun trying to understand how plot.ly reallly works. I have retried what you did and for ME it works but there is a trick. I did it all in HEX.

     

    image

     

    I ended up using three tools in all, Hercules to to the TCP testing stuff (both as client with plot.ly and as server with the CC3100), HxDEN to generate all the hex code (this is a HEX-ASCII editor so going from one to the other is relatively simple and then I used Notepad++ as for me that was the simplest way to take all the hex and remove the spaces. Let me know if this works for you at all, at least with Hercules. When it came to connecting with the CC3100 I didn't need to do the HEX trick and my feeling is I did it because it made life easier with EOL type stuff and other finicky stuff that differs between Windows and Linux not because it was the only way it worked..

     

    Kas

     

     

     

    P.S. I have included the code I used with plot.ly below as it may give you some insight as to how I went about getting thing moving. That being said I can't currently post data points to plot.ly and I'm not sure with a quick look why that is. Good Luck.

     

    **Initial REST REQUEST**

     

    POST /clientresp HTTP/1.1

    Host: 107.21.214.199

    User-Agent: MSP430F5529/0.5.1

    Content-Length: 243

     

     

    version=2.2&origin=plot&platform=Stellaris&un=Kas&key=ehebi0jb9k&args=[{"y": [], "x": [], "type": "scatter", "stream": {"token": "jtf0j96b06", "maxpoints": 500}}]&kwargs={"fileopt": "overwrite", "filename": "test plot", "world_readable": true}

     

     

    HEX VERSION WITH LINE BREAKS:

     

    50 4F 53 54 20 2F 63 6C 69 65 6E 74 72 65 73 70 20 48 54 54 50 2F 31 2E 31 0D 0A 48 6F 73 74 3A 20 31 30 37 2E 32 31 2E 32 31 34 2E 31 39 39 0D 0A 55 73 65 72 2D 41 67 65 6E 74 3A 20 53 74 65 6C 6C 61 72 69 73 2F 30 2E 35 2E 31 0D 0A 43 6F 6E 74 65 6E 74 2D 4C 65 6E 67 74 68 3A 20 32 34 33 0D 0A 0D 0A 76 65 72 73 69 6F 6E 3D 32 2E 32 26 6F 72 69 67 69 6E 3D 70 6C 6F 74 26 70 6C 61 74 66 6F 72 6D 3D 53 74 65 6C 6C 61 72 69 73 26 75 6E 3D 4B 61 73 26 6B 65 79 3D 65 68 65 62 69 30 6A 62 39 6B 26 61 72 67 73 3D 5B 7B 22 79 22 3A 20 5B 5D 2C 20 22 78 22 3A 20 5B 5D 2C 20 22 74 79 70 65 22 3A 20 22 73 63 61 74 74 65 72 22 2C 20 22 73 74 72 65 61 6D 22 3A 20 7B 22 74 6F 6B 65 6E 22 3A 20 22 6A 74 66 30 6A 39 36 62 30 36 22 2C 20 22 6D 61 78 70 6F 69 6E 74 73 22 3A 20 35 30 30 7D 7D 5D 26 6B 77 61 72 67 73 3D 7B 22 66 69 6C 65 6F 70 74 22 3A 20 22 6F 76 65 72 77 72 69 74 65 22 2C 20 22 66 69 6C 65 6E 61 6D 65 22 3A 20 22 74 65 73 74 20 70 6C 6F 74 22 2C 20 22 77 6F 72 6C 64 5F 72 65 61 64 61 62 6C 65 22 3A 20 74 72 75 65 7D 0D 0A

    504F5354202F636C69656E747265737020485454502F312E310D0A486F73743A203130372E32312E3231342E3139390D0A557365722D4167656E743A205374656C6C617269732F302E352E310D0A436F6E74656E742D4C656E6774683A203234330D0A0D0A76657273696F6E3D322E32266F726967696E3D706C6F7426706C6174666F726D3D5374656C6C6172697326756E3D4B6173266B65793D6568656269306A62396B26617267733D5B7B2279223A205B5D2C202278223A205B5D2C202274797065223A202273636174746572222C202273747265616D223A207B22746F6B656E223A20226A7466306A3936623036222C20226D6178706F696E7473223A203530307D7D5D266B77617267733D7B2266696C656F7074223A20226F7665727772697465222C202266696C656E616D65223A20227465737420706C6F74222C2022776F726C645F7265616461626C65223A20747275657D0D0A

     

     

    **Streaming Request**

     

    POST / HTTP/1.1

    Host: stream.plot.ly

    User-Agent: Python

    Transfer-Encoding: chunked

    Connection: keep-alive

    plotly-streamtoken: jtf0j96b06

     

     

    HEX VERSION WITH LINE BREAKS:

     

    504f5354202f20485454502f312e310d0a486f73743a2073747265616d2e706c6f742e6c790d0a557365722d4167656e743a20507974686f6e0d0a5472616e736665722d456e636f64696e673a206368756e6b65640d0a436f6e6e656374696f6e3a206b6565702d616c6976650d0a706c6f746c792d73747265616d746f6b656e3a206a7466306a39366230360d0a0d0a

     

     

    **Streaming Post**

     

    3135

    {"x":1,"y":5}

    3135

    {"x":2,"y":5}

    3135

    {"x":3,"y":5}

    3135

    {"x":4,"y":6}

     

     

    HEX WITH LINE BREAKS:

     

    333133350d0a7b2278223a312c2279223a357d0d0a333133350d0a7b2278223a322c2279223a357d0d0a333133350d0a7b2278223a332c2279223a357d0d0a333133350d0a7b2278223a342c2279223a367d0d0a

     

     

     

     

     

     

     

     

    POST /clientresp HTTP/1.1\r\nHost: 107.21.214.199\r\nUser-Agent: MSP430F5529/0.5.1\r\nContent-Length: 243\r\n

     

     

    version=2.2&origin=plot&platform=Stellaris&un=Kas&key=ehebi0jb9k&args=[{"y": [], "x": [], "type": "scatter", "stream": {"token": "jtf0j96b06", "maxpoints": 500}}]&kwargs={"fileopt": "overwrite", "filename": "test plot", "world_readable": true}

     

     

    POST / HTTP/1.1\r\nHost: stream.plot.ly\r\nUser-Agent: Python\r\nTransfer-Encoding: chunked\r\nConnection: keep-alive\r\nplotly-streamtoken: jtf0j96b06\r\n\r\n\r\n

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 10 years ago in reply to kas.lewis

    Ahh, I see, I was thinking that just to use the tool to verify what I'm sending

     

    But even using it as a TCP client, first connecting, and then transmitting the strings line-by-line, I see the same thing as I do with the MSP430, namely that plot.ly server never sends a response.   I would think that even if the strings have a problem (bad username, bad length, etc), I should get some response, instead after a minute or so, plot.ly finally sends a timeout response.

     

    I've tried sending different values for the string, but no luck, can you see any reason why the data isn't being recognized?

     

    image

     

    Thanks!

    Chris

     

    POST /clientresp HTTP/1.1\r\nHost: stream.plot.ly\r\nTransfer-Encoding: chunked\r\nContent-Length: 253\r\n\r\n

    version=2.3&origin=plot&platform=arduino&un=username&key=1234567890&args=[[0, 1, 2], [3, 4, 5], [1, 2, 3], [6, 6, 5]]

    &kwargs={\"filename\": \"plot from api\", \"fileopt\": \"overwrite\",\"style\": {\"type\": \"bar\"},\"traces\": [1],\"layout\": {\"title\": \"experimental data\"},\"world_readable\": true}\r\n

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • kas.lewis
    kas.lewis over 10 years ago in reply to Former Member

    Hey,

     

    They way I tested the plot.ly server with my code and eventually got it mostly working was to use Hercules. I set up a test graph and sent made up data to my graph using Hercules that way you can see both what you are sending and what plot.ly is sending back to you and then if that goes well you can corilate what you send with what appears on the plot.ly graph. I hope that helps.

     

    Kas

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 10 years ago in reply to kas.lewis

    I was using the program 'SocketTestv3' to make sure the cc3100 was actually transmitting.. but I also see data using the Hercules program.  

    image

     

    (Note, I've logged into Plot.ly and I'm using my actual key , token, username listed in the 'Settings' link)

     

    Do you know if there's a way to see the (ascii?) response from plotly after this packetTx setup call?    Maybe the PlotLy server is rejecting the POST because it doesn't like the username/key/token/length?

     

    Also, assuming the response is ok, and data starts getting posted, where is the data viewable (url)?  https://plot.ly/organize/home ?   Maybe it's on the site somewhere and I'm not going to the right place!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube