OEM Gateway: Serial Port > Emoncms Link

In the past we have recommended our simple EmoncmsPythonLink to post data to emoncms which is received on a serial port (this could be an Arduino or USB device such a JeeLink plugged into a Raspberry Pi).

The OEM Gateway by Jerome that we use extensively on the Raspberrry Pi to post data received by the RFM12Pi to emoncms can also (easily) be used to post data received an a serial port to emoncms. Using the OEM Gateay to do this rather than the Emoncms Python Link is a much more robust solution with better error logging.

I have recently setup a Raspberry Pi with an Arduino connected to receive RF data from my honey bee hive temperature monitor and post to emoncms. I found using the OEM gateway in conjunction with ino to compile and upload code for the Arduino remotely over ssh directly on the Raspberry Pi to be invaluable for remote bug fixing.

Here's how to use the OEM Gateway to post data to a local or remote emoncms from data received on a serial port:

1. Fist setup the Arduino / JeeLink  to write to the serial port using Serial.print() in the following format 

NodeID val1 val2
NodeID val1 val2

Example for temperature and relative humidity fluctuating around 19°C and 60% posting as node 11

11 19.2 60.1
11 19.5 60.0
11 19.3 60.4
(No restriction on number size and decimal part.)

2. Follow the excellent instruction on Jerome's Github for how to setup the OEM gateway 

https://github.com/Jerome-github/oem_gateway


3. Rename the oemgateway.conf file and edit it as follows adding in your USB port and API keys for local or remote emoncms or both.

####################
# Gateway settings #
####################
[gateway]
# loglevel must be one of DEBUG, INFO, WARNING, ERROR, and CRITICAL
# see here : http://docs.python.org/2/library/logging.html
loglevel = DEBUG

#############
# Listeners #
#############
[listeners]

# This listener manages the serail
[[Serial]]
    type = OemGatewaySerialListener
    [[[init_settings]]]
        com_port = /dev/ttyUSB0
    [[[runtime_settings]]]

###########
# Buffers #
###########
[buffers]

# The two following buffers instantiate the same class, 
# that formats the data for an emoncms instance.
# One sends the data to a local instance, the other one
# to a distant one.
# If active is set to False, the buffer neither records nor sends any data,
# but it holds unsent data until active becomes True.
[[emoncms_local]]
    type = OemGatewayEmoncmsBuffer
    [[[init_settings]]]
    [[[runtime_settings]]]
        domain = localhost
        apikey =xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        protocol = http://
        active = False
        path = /emoncms

[[emoncms_remote]]
    type = OemGatewayEmoncmsBuffer
    [[[init_settings]]]
    [[[runtime_settings]]]
        domain = emoncms.org
        apikey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        protocol = http://
        active = True
        path = 


4. Start the gateway with instruction to use the config from the config file 

$ ./oemgateway --config-file oemgateway.conf


The instructions on Jerome's Github can be followed to set the oemgateway script to run as a deamon service automatically at startup if required. To engage in discussion regarding this post, please post on our Community Forum.