Based on the responses from the “ReadSensorTable” command in my Economatics Smart Box SB-04, I’ve concluded that the following official sensor exist :
Index
Name
Val1
Val2
Units
3
Temp range 1
Tmp
Temp
degC
4
Voltage range 1
V
Volts
mV
5
Temp range 2
Tmp
Temp
degC
6
Voltage range 2
V
Volts
volts
7
Temp range 3
Tmp
Temp
degC
8
Voltage range 3
V
Volts
volts
9
Temp range 4
Tmp
Temp
degC
10
Sound (standard)
Snd
Sound
?
11
pH
pH
pH
?
13
Position
Pos
Postn
deg
17
Light (standard)
Lt
Light
?
21
R’Humidity
Hmd
Humid
%RH
22
Sound range 1
Snd
Sound
dbA
23
Light range 1
Lt
Light
Lux
24
Sound range 2
Snd
Sound
dbA
25
Light range 2
Lt
Light
Lux
26
Barometric Pressure
Atm
Atmos
mBars
27
Light range 3
Lt
Light
Lux
28
User adaptor
UA
User
?
29
0-1 Volt adapator
V
Adapt
?
30
Temp (low range)
Tmp
Temp
degC
31
Light gate
LG
LGate
?
33
Temp (standard)
Tmp
Temp
degC
There is more data being fed back by the box regarding these sensor types, but it is a little bit of a pig to understand as my terminal is reading it as escape characters. I suspect it would be easier to understand if I had some official sensors myself. I suspect that some experimentation is in order! I’ll connect a variable voltage to the detection pin and watch what sensor types the box detects at each voltage. With an ADC connected to my computer I might be able to automate the process… but that is probably more effort than it is worth.
Working with the Economatics Smart Box Serial Interface on a Modern Computer
Well, I had all sorts of fancy plans for how I would reverse engineer the serial protocol to control my ebay purchase “Smart Box” (some of which I will document at some point as they’re useful). Ultimately, I had so much difficulty installing MS .net 1.1 in Wine / PlayOnLinux that I went back to trawling the internet looking for alternative software to wire tap.
Smart Box
I struck gold when I found the following website :
The website includes a download of example code, the core of which is in VB6 and includes many serial commands for controlling the Smart Box (SB-04 version – I understand that older versions work differently, so be warned!), as well as an instruction manual that goes some way to explaining how the box data formats work.
After a bit of messing about in Python, it was fairly trivial to test a number of commands and witness the results. The only major feature I’m not currently sure about is the Analogue Inputs – I don’t know what the pinout is of the 5 pin DIN sockets, and so can’t easily test them. Perhaps a bit of circuit board investigation will help with this.
In summary, I have found the following :
Description
Command
Parameter
Response
Python Example
Set All Motors
10
8 bit value. Note, each pair of bits represents a motor. 01=left, 10=right and 00=stop
n/a
ser.write(chr(10)+chr(0b01010101)) # rotate all motors to the left
Motor <x> Left
12
1 to 4
n/a
ser.write(chr(12)+chr(1)) # rotate motor ‘A’ to the left
Motor <x> Right
13
1 to 4
n/a
ser.write(chr(13)+chr(1)) # rotate motor ‘A’ to the right
Motor <x> Stop
14
1 to 4
n/a
ser.write(chr(14)+chr(1)) # stop motor ‘A’
Set All Digital Outputs
20
8 bit value
n/a
ser.write(chr(20)+chr(0b11111111)) # turn all digital outputs on
Get Analogue <x>
40 (TBC)
1 to 4
8 bit value??
ser.write(chr(40)+chr(1)) # send me analogue input ‘A’
Set Low Resolution Analogue
45 (TBC)
n/a
n/a
ser.write(chr(45)) # set low resolution analogue mode
Get All Digital Inputs
90
n/a
8 bit value. Note the command seems to respond with three bytes, although the first identifies the status of each input.
ser.write(chr(90)) # send me the status of the digital inputs
Get Digital Input <x>
91 (TBC)
1 to 8
0 or 1 (in 8 bit value)
ser.write(chr(45)+chr(1)) # send me the status of digital input 0
The following example switches on motor ‘A’ for 5 seconds, stops it for 0.5 seconds, runs it backwards for 2 seconds and then stops it. Note the serial port will need setting – I have used ‘/dev/ttyUSB0’ as this is the correct port for my USB to RS232 adapter on my Linux machine.
#!/usr/bin/python
# https://elephantandchicken.co.uk/stuffandnonsense
# 04/03/2020
import time
import serial
# This example tests motor output A
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
ser.write(chr(12)+chr(1))
time.sleep(5)
ser.write(chr(14)+chr(1))
time.sleep(0.5)
ser.write(chr(13)+chr(1))
time.sleep(2)
ser.write(chr(14)+chr(1))
ser.close()
The following example reads the status of all digital inputs (aka “Digital Sensors”) 20 times.
#!/usr/bin/python
# https://elephantandchicken.co.uk/stuffandnonsense
# 04/03/2020
import time
import serial
# This example reads in the digital sensors and displays their status
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
# Flash Digital Outputs to show that the program is running
ser.write(chr(20)+chr(255)) # all on
time.sleep(0.1)
ser.write(chr(20)+chr(0)) # all off
time.sleep(0.1)
i = 0
while i < 20:
ser.write(chr(90)+chr(1)) # request digital input status
time.sleep(1) # wait (ages) for the response
readVal = 0 # clear variables
readByte = 0
readByte = ord(ser.read(1)) # read the first waiting byte in the buffer
while ser.inWaiting() > 0: # if there is more data in the buffer
readVal = ord(ser.read(1)) # read it to clear it
print "result : ",format(readByte, '08b') # print the first byte in boolean format
i+=1 # increment counter for the while loop
ser.close()
I still have some more work to do, regarding confirming exactly how these commands work (for example, what are the second and third bytes from the digital read response?). Additionally, I suspect that it is possible to set the voltages, but don’t know how. I’m (absolutely) guessing that command 11 might be motor speed.
Additionally, please contact me if you know any more details of the control scheme, or the analogue port pinout.
For the last long while, I’ve been tracking the temperature in our conservatory. This started when we had a pigeon living in there and I realised it was getting very warm during the day. Firstly, I started tracking the temperature, then I added a fan to an existing catflap to help cool the area, (then I removed the pigeon) and ultimately, the system now runs on an ESP8266 which monitors the temperature, switches the fan on for low and high temperatures (drawing air from the more thermally moderate house), provides a web interface for control and generates a status webpage using dynamically created SVG images.
Temperature Plot
An Orange Pi Nano computer is scheduled to fetch these images over the internal network every now and then, and uploads them to my website. I have been also saving the resultant 24 hour plots for each (most – I’ve had a couple of power and or internet outages) day.
Historic data is crudely stored here (I need to add pages, possibly automatically because I’m lazy. I think I worked out how at the time (show number ranges x through y, multiples… something like that. Perhaps need to learn how to pass parameters to php as I don’t really do internet stuff), but never implemented it.
In the future, I plan on modifying the code to reduce the work done by the ESP8266 to just fan control and temperature logging, with more of the intelligence / image generation offloaded to the Orange Pi Linux SBC. I will then consider creating more sensor nodes, using sleep functions to minimise power consumption to a level suitable for battery and / or solar power and ultimately, put other sensors around the house and in the garden shed.
Temperatures in the house might enable me to control our central heating boiler in a more intelligent fashion than it already is, while the garden shed would be a good source of the ambient temperature in our location (handy for passive cooling with ambient air for example, using fans fitted to the fresh air bricks in the house).