It’s surprising how much better my 3D printer works when I tightened up the grub screw of the Z-axis that had come loose.
Month: July 2014
MQTT and RRDTool
I mentioned in one of my earlier posts that Xively was nice as a quick test setup, but in the end I would like to have my data locally.
To this end I have installed Mosquitto as an MQTT server on a spare Linux machine in the office. I changed the nRF receiver Arduino to send the sensor data to topics in Mosquitto. I used the PubSubClient for the MQTT connection.
The format of the topics are
“/sensors/radio/<device-id>/<sensor-number>/<type>”
device-id is the address of the remote sensor device
sensor-number is the sensor on the device 1, 2, 3 … etc
type is the type of the sensor temperature, light, battery, etc
This is working as expected, but the data is more or less thrown away unless we have something to subscribe to it!
So on the subscription side i wanted something up and running quick, so I found this snippet of perl code that subscribes to a topic extracts data from the message content and updates an RRD database. For the moment it just does the temperature data.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#!/usr/bin/perl -w use strict; use FileHandle; use Switch; my $subclient = "/usr/bin/mosquitto_sub -t /sensors/radio/+/+/temperature -q 0"; open(SUB, "$subclient|"); SUB->autoflush(1); while (my $line = <SUB>) { if ($line =~ m/sensor:(.*)\s+input:(\d+)\s+value:(.*)/) { my $sensor = $1; my $input = $2; my $value = $3; system("rrdtool update $sensor-$input.rrd N:$value"); print "$sensor-$input = $value\r\n"; } else { print "NO MATCH $line\r\n"; } } |
I then have a script that runs every so often to create some graphs from the rrd data.
The results can be seen here.
You Can Never Have Enough Sensors
Day 1
What to do today now the lawns weeds have been mowed? The solar powered sensor is back out in the garden and seems to be working and recharging its battery in the sun today. The receiver is pumping the data into Xively nicely. I have these bits laying about …
- 2 x Arduino TwentyTens
- 2 x nRF24L01 modules
- 2 x ProtoShields
- 2 x 10K NTC sensors
- 2 x Dallas 18B20 temperature sensors
- 2 x Light sensors
- 1 x DHT11 humidity sensor
- 1 x BMP085 pressure sensor
- Plenty of time
Yes its pretty obvious – more RF sensors. Might also be handy to do some indoor range testing and a network/mesh of the nRF modules.
Day 2
Today I partially assembled the two prototype boards. So far the LDR and DS18B20 are fully functional, and the nRF module is soldered in place but not yet wired up. Looks neat and tidy.
Of course now it is partially assembled its always nice to know if everything is working. So here is some simple test code. Same story and usual, Google for some existing libraries, no need to write your own.
I ended up with these OneWire and Dallas Temperature
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#include "Arduino.h" #include <OneWire.h> #include <DallasTemperature.h> #define LDR_PIN A0 #define LED_PIN 13 #define ONE_WIRE_PIN 2 uint8_t result; int ldrValue; float temperature; OneWire oneWire(ONE_WIRE_PIN); DallasTemperature sensors(&oneWire); DeviceAddress sensor; void setup() { Serial.begin(9600); pinMode(LED_PIN, OUTPUT); Serial.println("SENSOR TEST"); sensors.begin(); oneWire.reset_search(); oneWire.search(sensor); Serial.print("Device 0 Address: "); printAddress(sensor); Serial.println(); sensors.setResolution(sensor, 12); } void loop() { ldrValue = analogRead(LDR_PIN); Serial.print("LDR: "); Serial.println(ldrValue); sensors.requestTemperatures(); temperature = sensors.getTempC(sensor); Serial.print("DS18B20: "); Serial.println(temperature); delay(5000); } void printAddress(DeviceAddress deviceAddress) { for (uint8_t i = 0; i < 8; i++) { if (deviceAddress[i] < 16) { Serial.print("0"); } Serial.print(deviceAddress[i], HEX); } } |
And the output (including other debugging not in the code)
1 2 3 4 5 6 7 8 9 10 11 |
SENSOR TEST Locating devices...Found 1 devices. Parasite power is: OFF Device 0 Address: 2807F383040000BC Device 0 Resolution: 12 LDR: 352 DS18B20: 23.87 LDR: 351 DS18B20: 23.87 LDR: 352 DS18B20: 23.87 |
Day 3
Another day with progress. Today I wired up the nRF modules and added some more code to send the readings to the receiver. Other than a snafu with one incorrectly wired pin, it all went without other issues.
Here is what the protoshield looks like now. Still pretty neat. I added the 10uF cap to the 3.3V line, cant remember why or if it is really needed, but my receiver has one so I figured it can’t hurt to have it installed. Yes the wires I have used (single cores from security cable) are really too think for anything too elegant but it was all I had laying about.
Latest is now live on the Xively Stream.
- 1000 is the external sensor in the garden
- 07f3 & d1ad are the new internal sensors
Next up, Add the screw terminal and send readings for the remote NTC temperature sensor …
Isn’t it Annoying
When you have a job you have the cash but no time to get things done. When you don’t have a job you have plenty of time to get things done but no cash to do anything.