Author Topic: Pachube integration  (Read 14367 times)

JRussell

  • Newbie
  • *
  • Posts: 6
  • I'm a llama!
    • View Profile
Pachube integration
« on: November 04, 2011, 08:47:08 AM »
Hi all!

I am interested in transfering data from a tri plc to an online web data service site called Pachube www.pachube.com, where the data can be graphed and view by the online community.

Pachube can pull or have data pushed to it using XML, JSON, or CSV. The PLC manual says the Fserver is compatible with enterprise software using "web query" methods. Since I am not a programmer I can't quite figure out if this connection will work or not.

It seems like the CSV would work since Excel can query the Fserver for data but I would not rather have excel running on the host computer but rather upload data directly to Pachube.

Could anybody just let me know if Fserver is compatible with XML or JSON? Any advice would be very helpful. Thanks!

ps pachube code info is here
http://community.pachube.com/quickstart

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Pachube integration
« Reply #1 on: November 04, 2011, 10:03:15 AM »
Any of the Nano-10, FMD or F-series PLC is able to open a socket connection to the webserver such as pachube.com and you then send command to the server using the PRINT #4 command and obtain response from the server using the INPUT$(4) command, as long as the length per line is within the TBASIC string limit of 70 characters you should have no trouble.

It appears that the CSV data format used by pachube.com would be the simplest way to send data to the service. If you are ambitious you can also send command in the JSON or XML format but you will have to create the formatted strings using TBASIC line by line since there is no automatic XML formatter in the programming language.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

JRussell

  • Newbie
  • *
  • Posts: 6
  • I'm a llama!
    • View Profile
Re:Pachube integration
« Reply #2 on: November 04, 2011, 11:30:48 AM »
Thanks! Glad to hear it should work. I might need a little walkthrough on this.

To open the socket connection would I use the TCPCONNECT tag? i.e.:

PRINT #4 <TCPCONNECT [IP address:portno] of Pachube>

Pachube says that if custom headers aren't supported my PUT request for CSV should look like this:

"PUT /v2/feeds/18834.csv?key=ENTER_YOUR_PACHUBE_API_KEY_HERE HTTP/1.1
Host: api.pachube.com  
Content-Length: 28
Connection: close

0,value1
1,value2
2,value3"

so how would I structure the PRINT #4 and INPUT$(4) commands to comply with the PUT command?

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Pachube integration
« Reply #3 on: November 04, 2011, 09:15:32 PM »
After sending <TCPCONNECT> You may need to wait for a short while before STATUS(3) become 1 to indicate a successful connection.

Does Pachube send any data after you first connect to it? If it does
then you use the INPUT$(4) to read the response data (provided it is CR or CR+LF-terminated).

If not, then you can continue to send the rest of the string using the PRINT #4 command - this may be a bit slow because each PRINT #4 call will send a small packet to the server. You may be able to combine the short strings together with a CHR$(13)+CHR$(10) and assign to a string variable first, then use the PRINT #4 command to send out the string variable.

The best way to experiment is to open a telnet window to the server and manually enter the various strings required by the server and observe if there is any data sent by the server, then handle it accordingly.


Email: support@triplc.com
Tel: 1-877-TRI-PLCS

easys

  • Newbie
  • Posts: 3
  • I'm a llama!
    • View Profile
Re:Pachube integration
« Reply #4 on: November 28, 2011, 01:46:54 PM »
Glad to see this thread. I too am interested in getting a nano-10 PLC to write to the Pachube service. As per suggestions, I managed to put data into the Pachube service via Telnet successfully, then tried the same via the PRINT #4 statements. Two problems become show stoppers.

1. The total string size via PRINT #4 is limited to 70 characters, while the complete text for the Pachube transaction is much greater than this; 187 characters in my 1 channel example
2. Splitting the text into multiple PRINT #4 lines does not work as each PRINT #4 adds a <CR> character at the end corrupting the transaction text required by Pachube

Are there any workarounds for this? Could there be a PRINT #4 statement that does not insert the <CR>? It would be really awesome if the nano-10 can be used with the Pachube or similar services

JRussell

  • Newbie
  • *
  • Posts: 6
  • I'm a llama!
    • View Profile
Re:Pachube integration
« Reply #5 on: November 28, 2011, 02:53:34 PM »
I was able to upload to pachube using the print#4 commands. Here is an example of my function:
Print #4 "PUT /v2/feeds/38530.csv HTTP/1.1"
Print #4 "Host: api.pachube.com"
print #4 "x-PachubeApiKey: xxxxxxxxxxxx"
print #4 "Content-Length: 7"
print #4 "Connection: close"
print #4 ""
print #4 "flow,";F;

I was using CSV and was getting this to work without adding <CR>. I'm not using the nano but the F1616 but the programming should still be the same.

easys

  • Newbie
  • Posts: 3
  • I'm a llama!
    • View Profile
Re:Pachube integration
« Reply #6 on: November 28, 2011, 03:30:00 PM »
Thanks for the code snippet. I tweaked my code a little and its now working. Thank you very much for your help.

JRussell

  • Newbie
  • *
  • Posts: 6
  • I'm a llama!
    • View Profile
Re:Pachube integration
« Reply #7 on: November 28, 2011, 03:50:35 PM »
no problem. I'm curious, what kind of data are you uploading to Pachube? I'm uploading water flow meters and tank water levels for greywater and rainwater catchment systems.

easys

  • Newbie
  • Posts: 3
  • I'm a llama!
    • View Profile
Re:Pachube integration
« Reply #8 on: November 28, 2011, 04:01:38 PM »
For the present, I'm testing with a dummy variable (time in seconds). Eventually, I want to interface the Nano-10 to legacy plant e.g trade waste systems that currently run PLC's capable of Modbus RTU and in effect provide a Pachube logging gateway function through the Nano-10. The variables of interest would be pH, temperature, tank levels etc. The other alternative I am considering is one of the Arduino boards with Ethernet/SD card logging and RS485 ports which are also able to log to Pachube type services inexpensively. The Nano-10 having all the basic interfaces and with 24V I/O appears more attractive in industrial context