To continue with this post I have changed the Transmitting and Receiving firmware
The aim is still to setup a water monitoring system using 2 x JeeNodes and Raspberry Pi
Can anyone recommend the best way to get a minimum working system in emoncms with Jeenodes.
For instance I have the RPI running ok with the standard image and can login and run emoncms.
I need a remote reader Jeenode at the water meter sending to a Jeenode connected to the RPI.
I have tried the following:
Water-meter Jeenode
using g_transmittingData.ino . group 210, node 10
RPI with Jeenode
using a_FixedPackets.ino group 210, node 15,
emoncms seems to be seeing some input it shows "ok" when I test inputs, but feeds don't show on graphs.
If I can get this to work hopefully I can then look at more advanced implementations.
Basicall how can I get the readings from the Jeenodes to show on a emoncms graph.?
Thanks
Re: Using Jeenode and RPI- How to setup minimum base-station and simple RF-remote such as send variable voltage
Have changed firmware but still no success.
Re: Using Jeenode and RPI- How to setup minimum base-station and simple RF-remote such as send variable voltage
What is the format of the data that you are sending? The Input API help in emoncms gives the formats that are acceptable. If you do not include your API read&write key, emoncms will not accept the data.
Re: Using Jeenode and RPI- How to setup minimum base-station and simple RF-remote such as send variable voltage
Thanks for replying Robert.
I don't understand enough to properly answer your question, but if I give you more info maybe you will be able to direct me.
Because I already have 2x JeeNodes , which have an on-board RFM12B I would like to use them rather than make a emonTx or LCD board, and I have a RPI with the emoncms image downloaded and running.
One JN is connected to the water-meter reading the reed-switch the other JN is connected to the RPI as ttyUSB0.
The data only needs to be one byte which are the counts of the reed-switch closings for 1 minute and sent via RF to the RPI.
Questions:
What Sketches do I need to put into the water-meter JN and the RPI JN.?
For instance maybe for a trial I could use the test2.ino sketch from JeLabs in the water-meter which captures one bye of reading from the digital.input port and sends a packet via RF.
The RPI Sketch maybe I could be the RF12Demo.ino from Jeelabs which reads the RF packet and prints to the terminal.
Would this be enough for to do a basic set up so that my localhost/emoncms could show some readings.
Do I need to add the API key to every byte of data sent from the water-meter.?
Any suggestions welcomed.
Len
Re: Using Jeenode and RPI- How to setup minimum base-station and simple RF-remote such as send variable voltage
I can't identify for certain the Jeelabs sketch you are referring to. As far as I can tell, you have a sketch that is detecting the switch operating and is generating a message - a single byte in your case - and outputting that via the RFM12B. You need to send a longer message than that which emonCMS can validate and interpret.
The easiest way to interface to emoncms is to send it a message in the format it understands. That is what I was referring to. Log in to emoncms and go to http://emoncms.org/input/api. and right at the top of the page are examples that you can type in your web browser.
If you look at one of the NanodeRF or OKG Base sketches, you can see how that string is built up. For example:
str.reset();
str.print(basedir); str.print("/input/post.json?");
str.print("apikey="); str.print(apikey);
str.print("&node="); str.print(node_id);
str.print("&csv=");
for (byte i=0; i<n; i+=2)
{
int num = ((unsigned char)rf12_data[i+1] << 8 | (unsigned char)rf12_data[i]);
if (i) str.print(",");
str.print(num);
}
str.print("\0"); // End of json string
:You need to do something like that, using your own APIKEY of course.
Your RPi is of course already running emonCMS, so it should all work instantly once you send it the data it is expecting.
Re: Using Jeenode and RPI- How to setup minimum base-station and simple RF-remote such as send variable voltage
Hi Len,
you are almost there ... communication between a node (be it an emontx/jeenode/arduino/external program) to emoncms happens through either an API (Application Programming Interface) or using a php script that retrieves the data and uses the emoncms framewrok to store it.
This means that in order to have some data stored in emoncms you have to:
If you feel like experimenting with a direct script you should have a look at the rfm12php script about including the emoncms framework and reading from the serial (not easy if you are not into software development)
If you feel like you just need to read the data, store it in emoncms and forget about the bad experience in programming :) then a good starting point could be this post http://openenergymonitor.org/emon/node/1418
where another user added the functionality to store data from a serial device.
#!/usr/bin/perl -w
# Reads data from a Current Cost device via serial port.
use strict;
use Device::SerialPort qw( :PARAM :STAT 0.07 );
use LWP::UserAgent;
my $key = "your_emoncms api key_here";
my $PORT = "/dev/ttyUSB0";
my $meas = 0;
my $sumW = 0;
my $sumT = 0;
my $watts;
my $temp;
my $wget;
my $ob = Device::SerialPort->new($PORT) || die "Can't open $PORT: $!\n";
$ob->baudrate(57600);
$ob->write_settings;
open(SERIAL, "+>$PORT");
while (my $line = <SERIAL>) {
if ($line =~ m!<tmpr> *([\-\d.]+)</tmpr>.*<ch1><watts>0*(\d+)</watts></ch1>!) {
my $watts = $2;
my $temp = $1;
#print "SUCCESS $meas: ... $watts, $temp\n";
$meas++;
$sumW += $watts;
$sumT += $temp;
}
if ($meas == 10) { #time to send
$watts = $sumW/10;
$temp = $sumT/10;
#print "AVERAGE: ... $watts, $temp\n";
my $emon_ua = LWP::UserAgent->new;
my $emon_url = "http://localhost/emoncms3/api/post?apikey=$key\&json={power:$watts,temp:$temp}";
my $emon_response = $emon_ua->get($emon_url);
if ($emon_response->is_error) {
die $emon_response->status_line;
}
}
}
You will have to change the script to suit you serial parameters, the link to your emoncms instance and the decoding of the serial communication
If you fell like this is still too much for your programming skills try and post the output from the serial port and I'll see if we can hack something together ...
Re: Using Jeenode and RPI- How to setup minimum base-station and simple RF-remote such as send variable voltage
Is the API stuff required if I only want to run the emoncms server on my RPi only. ?
I don't particularly need to send it to emoncms.org , yet.
For a test run just a connection between the watermeter and the localhost RPi is fine.
I have tried the following setup water-meter -> RPi , but can't get any active inputs going on the localhost-emoncms
A Sketch for the RPi base-station from the NanodeRf b_MultiNode.
#include <JeeLib.h> //https://github.com/jcw/jeelib
void setup ()
{
Serial.begin(9600);
Serial.println("RPi Server");
rf12_initialize(15, RF12_868MHZ, 100);
}
void loop ()
{
if (rf12_recvDone() && rf12_crc == 0 && (rf12_hdr & RF12_HDR_CTL) == 0)
{
int node_id = (rf12_hdr & 0x1F);
// Get the packet length (number of integers sent is n/2)
byte n = rf12_len;
Serial.print("Node: ");
Serial.print(node_id);
Serial.print(" data: ");
// Go throught the packet 2 bytes at a time
for (byte i=0; i<n; i+=2)
{
// Create an integer from each block of two bytes (using bitwise math)
int num = ((unsigned char)rf12_data[i+1] << 8 | (unsigned char)rf12_data[i]);
// Print the output as CSV
if (i) Serial.print(",");
Serial.print(num);
}
Serial.println();
}
}
A Sketch for the water-meter adapted from JCW's Housemon test2
#include <JeeLib.h>
#include <Ports.h> // needed to aviod Linker error
typedef struct { int counts,battery;} PayloadTX;
PayloadTX watermeter;
void setup () {
Serial.begin(9600);
Serial.println("Water-meter");
rf12_initialize(10, RF12_868MHZ, 100);
}
void loop () {
watermeter.counts = analogRead(0); // simulate watermeter count
watermeter.battery =map(analogRead(6),0,1023,0,660);// not active yet
int i = 0; while (!rf12_canSend() && i<10) {rf12_recvDone(); i++;}
rf12_sendStart (0, &watermeter, sizeof watermeter);
}
Re: Using Jeenode and RPI- How to setup minimum base-station and simple RF-remote such as send variable voltage
Hi, thanks for your reply.I have also sent a reply to Robert Wall, in this string. Some of it may apply to your suggestions.
If it is applicable,I don't know how to send Perl commands, do I need to download a Perl interpreter.
Please notice I don't particularly need to send to emoncms.org , the localhost RPi will do for a test.
Len
Re: Using Jeenode and RPI- How to setup minimum base-station and simple RF-remote such as send variable voltage
Hi Len, don't take it the wrong way please, but I think you would be better off just ordering a rfm12pi module and using the standard raspberry module...the feel is that you want to accomplish something that is way over your actual experience with linux and programming.
It is not simply a matter of uploading a sketch and running a shell command, you need to understand the process you need to apply on order to move data from a node to the cms, and as I stated the api 'stuff' is actually the easiest of the two ways you can use to send data to emoncms (be it your local instance or the main emoncms server).
The sketch you are using on the receiver writes data to the serial port, emoncms listens for data on a network socket, hence you need another layer that retrieves the data from the serial port and forwards it to emoncms. It cannot get simpler than that, other than using the rfm12pi hardware for which this intermediate layer has already been written/tested.
Regards
Re: Using Jeenode and RPI- How to setup minimum base-station and simple RF-remote such as send variable voltage
Len, I don't understand. Didn't you say you were already running a local RPi with emoncms on it? and running OK?
In that case all you need to do is expand the string your JeeNode sends to something like
"/emoncms/input/post.json?apikey=yourbiglongapikeyhexnumber&node=10&csv=123"
Then your intermediate JeeNode just has to forward that byte-for-byte. (Unless of course you want to send just the value from JeeNode1 to JeeNode2, in which case JeeNode2 must assemble the message and send it.)
Re: Using Jeenode and RPI- How to setup minimum base-station and simple RF-remote such as send variable voltage
Robert,
I think the problem is that the receiving jeenode communicates through serial with the pi, and won't be able to directly post the data to emoncms but only to the serial (actually the receiving sketch Len posted is already doing that and forwarding to the serial the data in csv format). He needs a script that reads fromthe serial and posts to emoncms like the one I posted that needs to be adapted to the csv format. If I have time later today I'll try and modify it together with instructions about how to run it.
Re: Using Jeenode and RPI- How to setup minimum base-station and simple RF-remote such as send variable voltage
Ah, I'd missed the bit where Len is using the second Jeenode as the RF receiver for the Pi. :-(
Re: Using Jeenode and RPI- How to setup minimum base-station and simple RF-remote such as send variable voltage
Well, it compensates for understanding a google translation from portuguese in another thread and correctly debugging the code at the first try :)