wiki:Telemetry/sensgw
Last modified 3 years ago Last modified on 09/06/2014 04:34:53 PM

Sensor gateway (Arduino based)

Arduino compatible sensor gateway - sensgw is to be used for interfacing a range of sensors to wlan slovenija nodes, enabling a simple and low-cost platform for sensors and actuators ranging from temperature, pressure and humidity to power consumption and lightning strikes. A

The development of telemetry and telecontrol systems is split into sensors&devices and telemetry&telecontrol platform, the latter providing connectivity to the router. It implements I2C and 1WIRE communication protocols for sensors and UART communication with the router. Follow the development in ticket #1068.

Two versions of the device are out in the wild.

Developed by musti@wlan-si.net Musti.

version 0.2

The first prototype, only 15 units out it the wild. It constructed to be pin compatible with the RED USB-UART CP2102 converter, schematic how to connect it to BLACK USB-UART CP2102 converter is below.

Known issues: PNP transistor footprint for I2C power is incorrectly wired, transistors need to be soldered sideways to accommodate for that.

Schematic: []

version 0.5

The second prototype, quite some PCBs made in collaboration with UCL EE Fleming society as a part of the Build Your Arduino workshop, where this version is used as a reference design.

Changes: Transistor pinout fixed, made pin compatible with BLACK USB-UART CP2102 module and added MPL115A2 pressure temperature sensor footprint on the bottom side.

001 002

The connection of USB-UART and sensor gateway and the connection of sensor gateway to TP-Link routers as above.

Schematic: wlansiarduino0V5.pdf

Hardware design

Connectors of this design consist of DIP20 footprint (long sides of the board) used for interfacing the data pins. The 6-pin connector is UART interface designed to be used with CP2102 USB-UART module (black PCB version) from ebay. The 5 pin connector on the other side is I2C bus with the pinout GND,SDA,SCL,IRQ,VCC, where IRQ is the line used for any sensor on bus to send an interrupt. VCC for the I2C port is managed via PNP transistor (pull it low to turn on) controlled via D4.

1Wire interface is on D3, pins left and right of it provide VCC and GND.

Software support

The software support implemented at the moment is only for testing and development. It enables the data from the sengw platform to be collected and plotted by the nodewatcher.

A three-step process is put into place for this very simple communication, however all of these tools are packaged and can be simply installed with opkg. This description clarifies the operation a bit.

  • sensgw communicates via UART at 115200 baud, and responds to queries of format ACOM /x and accepts commands of format ACOM /x v, where x is the request for specific measured values and v is the value. All commands are \n terminated, and so should be replies.
  • readsensor handles the UART communication at the router level and can be called with a shell command
  • simpleserial is the nodewatcher script handling the information to be published, defining the number of measured values and their titles
  • Not a software package, but configuration: On the router, you will also have to edit /etc/inittab, and comment (put # in front of) the line containing ttyATH0. Afterwards, the router should be rebooted.

Sensor gateway programming

Sensor gateway is Arduino compatible and programmed it this environment. The source for the basic example is available at https://github.com/SloMusti/sensgw

Instructions for setting up the development environment.

Currently defined UART queries and commands for sensgw

These raw uart commands are supported in the default configuration. The commands sent byreadsensor as shown:

readsensor -d /dev/ttyATH0 -i 0

sends ACOM /0 - test read, return version

readsensor -d /dev/ttyATH0 -i 0 -s 1

sends ACOM /0 1 - test write

All the commands supported in the example Arduino code:

  • ACOM /0 - get version
  • ACOM /1 - get pressure
  • ACOM /2 - get temperature
  • ACOM /3 - get temperature from DS18B20, if connected
  • ACOM /0 1 - test write
  • ACOM /1 1 - turn on the LED
  • ACOM /1 0 - turn off the LED

Setting up the environment

Install the Arduino environment. Download the example code and install all the required libraries. In the menu Tools|Board, select the board Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328.

Setup instructions

Sensor gateway system requires three components to be installed, follow the instructions below for TP-Link routers.

  • Make sure you use the newest wlan slovenija firmware
  • Edit /etc/inittab and comment out the line with ttyATH0 using the following command OLD, not applicable anymore
    sed -i 's/\(ttyATH0:.*\)/#\1/' /etc/inittab
    

Newer firmware versions require you to comment out ::askconsole:/bin/ash –login

  • Install simpleserial and readsensor packages
    opkg install http://bindist.wlan-si.net/profiles/nextgen/ar71xx/readsensor_0.1-1_ar71xx.ipk
    opkg install http://bindist.wlan-si.net/profiles/nextgen/ar71xx/nodewatcher-simpleserial_0.1-2_ar71xx.ipk
    
  • Configure simpleserial for your sensors.
vi /etc/nodewatcher.d/simpleserial.sh
# Configuration
SENSOR_MEASURE_CACHE="/var/nodewatcher.simpleserial_measure"
SENSOR_TIMEOUT=100
SENSOR_NAMES="\
Pressure-(kPa) \
Temperature-(C) \
Temperature-1W-(C) \
"
SENSOR_START_ID=0
  • Change the sensor count to the number of sensor functions you have.
  • Make sure the timeout is sufficient for your functions to reply with data.
  • Configure names as shown, the name must not contain a space.
  • Reboot

Gotchas

  • ERROR: Timed out while parsing sensor response! - did you forget to edit /etc/inittab?

Arduino software

Code for sensgw compatible with simpleserial will be released soon after some additional testing.

Attachments