Using Raspberry Pi as a base station for TinyTX

The guys at OpenEnergyMonitor were kind enough to send me a prototype of their new RFM12Pi board a few weeks ago, this handy little kit allows our favourite low power radio board to be connected to the immensely popular Raspberry Pi.  This makes setting up a tiny little server for receiving data from the OEM emonTX or my own TinyTX sensor boards very easy and negates the need for a separate internet gateway device such as a NanodeRF. If you want a local back end solution rather than a remote server it’s ideal.

While everyone else was struggling with interrupt issues when trying to get the RFM12B to work directly with the Pi, Martin went instead for the simple method of using an ATtiny84 to receive the data from the RF module and then spit it out to the Pi’s UART. A PHP script on the Pi then receives this, correctly formats it and sends it on to emoncms. Simple but effective and allows the tried and tested JeeLib RF12 library to be used on the ATtiny.

The board comes as a kit which shouldn’t take more than 10 minutes to put together and then just plugs onto the GPIO headers of the Raspberry Pi. Assuming you already have the Raspbian Linux distro installed on your Pi all you need to do is install emoncms (+ Apache, PHP and MySQL if not already installed), the PECL PHP serial module and the Raspberry Pi emoncms Module and you will be receiving data from your nodes in no time. Follow the complete setup instructions here.

If you are using ACKs like I am with the TinyTX then you will need to make a small edit in raspberrypi_run.php otherwise your node numbers will all be increased by 32.

Just change the line:

$url = “/emoncms/input/post?apikey=”.$apikey.”&node=”.$values[1].”&csv=”.$msubs;

to:

$url = “/emoncms/input/post?apikey=”.$apikey.”&node=”.($values[1]-32).”&csv=”.$msubs;

This is a bit of a quick and dirty fix that won’t be any good if you have a mix of nodes that use ACKs and some that don’t but it does the job for me. Update: See comments below for a better fix that works with both, does mean updating the code on the ATtiny84 though.

I’ve been using emoncms for over 12 months now and it makes a fantastic back end for the TinyTX and similar sensors and has seen some great improvements in that time. If you want a local dedicated back end for your system I can highly recommend the RFM12Pi board and Raspberry Pi combo.

RFM12Pi Kit Completed Board Fitted to Raspberry Pi

 

15 thoughts on “Using Raspberry Pi as a base station for TinyTX

  1. Hi Nathan,
    maybe just doing logical AND with 0x1F is a better approach to clear the ACK bit.

    Also, did you know that the RFM2Pi board can send data, not only receive? You can use that to send out time to emonGLCD for example

  2. Hi Martin,

    Yep, that’s the answer, cheers. Changed line 250 of TinySensor_RF12_Demo.ino to:
    mySerial.print((int) rf12_hdr & 0x1F);
    updated the ATtiny84 and it now works for nodes that want an ACK as well as those that don’t.

    Not looked at sending yet but if I decide to switch to the Pi as my full time base station I will want to so good to know it can be done.

    Cheers,
    Nathan

  3. AM interested in knowing more about sending if anyone has any pointers .. would like to be able to send commands to my wireless plugs and wireless boiler control. Can I run this in conjunction with receiving data? Was looking at something such as https://github.com/r10r/rcswitch-pi to allow me to control remote plugs.

    Thanks

    Nick

  4. Hi Nathan,

    I purchased a RFM12PI to send data from my tinytx nodes to my Raspberry PI via RFM12B radios. I am using the RFM12PI (new version with Atmega 328) with the pre-installed firmware without any modifications.

    I wrote a scetch which sends the data and the RFM12PI does receive the data. My problem is that the tinytx nodes never receive any ACKs from the RFM12PI.

    I use the following code for my Arduino nodes:

    for (byte i = 0; i <= 5; ++i) { // tx and wait for ack up to 5 times
    rf12_sleep(-1); // Wake up RF module
    while (!rf12_canSend())
    rf12_recvDone();
    rf12_sendStart(RF12_HDR_ACK, &paylod, sizeof paylod);
    rf12_sendWait(2); // Wait for RF to finish sending while in standby mode
    boolean acked = waitForAck(); // Wait for ACK
    rf12_sleep(0); // Put RF module to sleep
    if (acked) {
    return;
    } // Return if ACK received
    Sleepy::loseSomeTime(5000); // If no ack received wait 5s and try again
    }

    static byte waitForAck() {
    MilliTimer ackTimer;
    while (!ackTimer.poll(5000)) { // try to receie an ACK for max. 5 seconds
    if (rf12_recvDone() && rf12_crc == 0 &&
    rf12_hdr == (RF12_HDR_DST | RF12_HDR_CTL | myNodeID)) {
    return 1;
    }
    }
    return 0;
    }

    I also tried a less strict check for the header – no success either:

    static byte waitForAck() {
    MilliTimer ackTimer;
    while (!ackTimer.poll(5000)) { // try to receie an ACK for max. 5 seconds
    if (rf12_recvDone() && rf12_crc == 0) {
    return 1;
    }
    }
    return 0;
    }

    The function waitForAck always returns 0. Unfortunately I can not debug the code except by "LED debugging) which makes it quite hard to trace the problem.

    Does Anybody have any ideas?

    How can I check whether the RFM12PI is sending the ACKs as requested?

    Thx, chris

  5. In minicom I see the “->ACK”. However I never receive any ACKs with my sensors.
    I tried with and without collect mode enabled.
    What exactly is the collect mode doing and what is it for?

    In the meantime I sort of bricked my RFM12PI. In order to trace the problem at the RFM12PI-side I uploaded a modified firmware to the RFM12PI via avrdude on the RaspberryPi. The uploading process was successfull. However I then wanted to upload another version and now uploading does not work any more.

    When I run the following command:
    avrdude -v -c arduino -p ATMEGA328P -P /dev/ttyAMA0 -b 38400 -U flash:w:RF12_Demo_atmega328.cpp.hex

    Then I get the following output:
    avrdude-original: Version 5.11.1, compiled on May 23 2012 at 11:08:25
    Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
    Copyright (c) 2007-2009 Joerg Wunsch

    System wide configuration file is “/etc/avrdude.conf”
    User configuration file is “/root/.avrduderc”
    User configuration file does not exist or is not a regular file, skipping

    Using Port : /dev/ttyAMA0
    Using Programmer : arduino
    Overriding Baud Rate : 38400
    done with autoreset
    avrdude-original: stk500_recv(): programmer is not responding

    I also soldered an ISP header to the RFM12PI board and tried to upload the original code using the Arduino IDE (1.0.5) and my USBasp programmer. With this configuration I can successfully install the bootloader at least. The output I get is as follows:

    avrdude: warning: cannot set sck period. please check for usbasp firmware update.
    avrdude: warning: cannot set sck period. please check for usbasp firmware update.
    avrdude: warning: cannot set sck period. please check for usbasp firmware update.
    avrdude: warning: cannot set sck period. please check for usbasp firmware update.
    avrdude: WARNING: no end of file record found for Intel Hex file “E:\Arduino-1.0.5\hardware\arduino\bootloaders\optiboot\optiboot_atmega328_384_8.hex”
    avrdude: WARNING: no end of file record found for Intel Hex file “E:\Arduino-1.0.5\hardware\arduino\bootloaders\optiboot\optiboot_atmega328_384_8.hex”

    However I can not upload any scetches. If I try then I get an error saying that the com port Com1 is not defined suggesting to select the correct com port from the menu. However the respective menu is empty as I do not have any Arduinos connected via USB.

    Any ideas how I can get the brick back to life?

    Thx, chris

  6. All collect mode does is enable or disable the sending of a reply back to the node, collect mode 1 = no ACK replies are sent, collect mode 0 = they are sent.

    I’ve no idea what is wrong with your RFM12Pi but when you are trying to flash the bootloader over ISP it appears there is a problem with the optiboot hex file, have you tried downloading the Arduino IDE again in case something is corrupt?

  7. Hi Nathan,
    What lovely little sensors just waiting to be spread around the home you created 🙂

    I have an emonTx with a RaspberryPI base gathering energy and temperature data and would love to augment that with a few tinyTX’s spread throughout the house.

    In order for them to work together is this still a must?
    “Yep, that’s the answer, cheers. Changed line 250 of TinySensor_RF12_Demo.ino to:
    mySerial.print((int) rf12_hdr & 0x1F);
    updated the ATtiny84 and it now works for nodes that want an ACK as well as those that don’t.”

    Could you give some more details about that change and where it s supposed to be made? I’m very much a beginner at all this.

    Thank you very much,
    Alex

  8. Depends which version of the RFM12Pi you have, the later ATmega328 based versions all had that fix as should the original ATtiny84 based version post Jan 2013. If it is older than that then you will probably have to make the change or just put the latest version of the code from here on it: https://github.com/mharizanov/RFM2Pi/blob/master/firmware/RFM2Pi_RF12_Demo/TinySensor_RF12_Demo/TinySensor_RF12_Demo.ino

    You would need to use an ISP programmer or an Arduino with the Arduino-ISP sketch to load it on to the ATTiny on the RFM12Pi.

  9. Dear Nathan,

    thus far everything works fine. Now I am trying to use 5 tinytx dht22. Nodes fro 16 to 20.
    Surprisingly Minicom does show only node 16. Trying with and without ACK (1c in minicom shows node 16 every some seconds.
    Where is my mistake??
    Secondly if I may ask wich flood/water sensor do you use?

    Thanks for your help. Regards Walter

  10. Hallo,
    elyob asked the following question some weeks ago. Is there any solution for this?
    Kind regards
    Mathias
    elyob (@elyob)
    says:
    December 9, 2012 at 11:17 pm
    AM interested in knowing more about sending if anyone has any pointers .. would like to be able to send commands to my wireless plugs and wireless boiler control. Can I run this in conjunction with receiving data? Was looking at something such as https://github.com/r10r/rcswitch-pi to allow me to control remote plugs.

    Thanks

    Nick

  11. Hi Nathan,

    what Sketch did you use to send data from your tinytx with DHT22 to the RFM12Pi? I´ve only found the precompiled demo but i want to have a look at the source.

    Is Perl Script for collecting the data from UART still needed?

  12. Hi. Great site.
    What is the purpose of the RFM12Pi module at all. I might miss that part.. Can’t you just connect the RFM12/RFM69 module directly to the pi using SPI?

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.