SOLVED - Reading data from serial input to emoncms

I'm stuck.

I have a thermistor wired into an Arduino.  The sketch calculates the temperature and outputs the value in °C on the serial.

Works great, I can see the value in the Arduino Serial Monitor.

If I connect the Arduino to the Raspberry Pi I can read the data using GNU screen.

What I can't seem to figure out is how I can read the data from the serial into emoncms using the API.

If anyone can point me in the right direction that would be great.  I think I could use the code here https://github.com/mharizanov/TinySensor/tree/master/perl_gateway

The issue is that I can't figure out what's going on.  If someone could help explain that would be great.

Robert Wall's picture

Re: SOLVED - Reading data from serial input to emoncms

Caveat: I'm no Perl expert, here's how I would go about it:

It looks to me as if that script is reading data from the serial port and posting it to emoncms in exactly the same format that all the other base sketches generate.

Therefore, I think you need to replace the 'middle bit' of the script - the top part of the while loop from after you've got the serial data from the port down to the call to post2emoncms - so that you end up with a call to post2emoncms that contains just your temperature data from whatever node you care to call it. Martin has included two examples, the only snag I can see that prevents you from using the first almost exactly as it stands, is the node number won't be present in your input string unless you put it there in the Arduino. (i.e. you need to look at how the data for the RFM12B module is assembled in the emonTx sketches and incorporate that). You get to decide, in the Arduino, the format of the temperature data you're sending to the Pi, hence you will make that too fit the format of the emonTx sketches.

In the Perl script, you need to end up with a string like:

"http://127.0.0.1/emoncms3/api/post?apikey=********************************&node=12&csv=223"

I think emoncms can't handle non-integer input data, so that temperature is 22.3 °C from node 12 (You multiplied the value by 10 in the script or in the Arduino, and need to multiply by 0.1 inside emoncms).

Hope that helps.

 

ukmoose's picture

Re: SOLVED - Reading data from serial input to emoncms

You don't say if you wish to do this on perl or the choice was because you found the script.

if it was the latter it might be worth looking at doing this with a python script,

The reason  I suggest this is the python community for the raspberry Pi appears to be far more active.

it would also be worth looking at this link:

http://openenergymonitor.org/emon/node/810 where Glyn appears to have done what you ask.

You'll need to point any script you use at the address of the emoncms database you want to use and supply your api code

StuntMonkeh's picture

Re: SOLVED - Reading data from serial input to emoncms

I was looking at the Perl script because I was struggling to find anything.  I looked for hours, just all in the wrong places it would seem.

Its working now, thanks for pointing me in the right direction.  Like you said Glyn had already done it.

I just had to tweak the serial output to output the word 'temperature:' before the actual temperature reading or else I would get a new feed for each temperature!

Thanks for helping.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.