User Tools

Site Tools


record_temperature_from_lexibook_asm30_sensor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
record_temperature_from_lexibook_asm30_sensor [2016/04/02 11:17]
sgripon [Reverse engineering Lexibook ASM30 temperature sensor]
record_temperature_from_lexibook_asm30_sensor [2016/04/04 13:24] (current)
sgripon [The arduino sketch]
Line 5: Line 5:
 ===== Needed hardware ===== ===== Needed hardware =====
  
-  * Arduino Uno R3 board (available on [[http://​www.amazon.fr/​dp/​B008GRTSV6/​ref=pe_386181_40444391_TE_item|Amazon]]) with USB cable +  * Arduino Uno R3 board (available on [[http://​www.amazon.fr/​dp/​B008GRTSV6/​ref=pe_386181_40444391_TE_item|Amazon]]) with USB cable {{ :​arduino.jpg?​200|}} 
-  * 433Mhz RF transmitter and receiver (available on [[http://​www.ebay.com/​itm/​433Mhz-RF-transmitter-and-receiver-kit-for-Arduino-ARM-WL-MCU-Raspberry-pi-new-/​370685120131?​ssPageName=ADME:​X:​AAQ:​US:​1123|eBay]])+  * 433Mhz RF transmitter and receiver (available on [[http://​www.ebay.com/​itm/​433Mhz-RF-transmitter-and-receiver-kit-for-Arduino-ARM-WL-MCU-Raspberry-pi-new-/​370685120131?​ssPageName=ADME:​X:​AAQ:​US:​1123|eBay]]) ​{{ ::​rf433.jpg?​200|}}
   * Lexibook ASM30 temperature sensor: I had one since many years and I noticed it communicates with 433RF signals with the base   * Lexibook ASM30 temperature sensor: I had one since many years and I noticed it communicates with 433RF signals with the base
 +
 +
  
 ===== Assembly ===== ===== Assembly =====
Line 18: Line 20:
 Then I suppose you have the Arduino connected with a USB cable to a PC running the Arduino development environment. Then I suppose you have the Arduino connected with a USB cable to a PC running the Arduino development environment.
  
 +{{ :​arduino-rf433_receiver_bb.png?​300 |}}
 ===== Reverse engineering Lexibook ASM30 temperature sensor ===== ===== Reverse engineering Lexibook ASM30 temperature sensor =====
  
Line 25: Line 28:
  
 Analysing the timings show several things : Analysing the timings show several things :
-  * There is a short timing (<500each other pulse +  * There is a short timing (<500µsevery other pulse 
-  * Some pulse have medium duration (around ​1900+  * Some pulses ​have medium duration (around ​1900µs
-  * Some pulse have long duration (around ​4500+  * Some pulses ​have long duration (around ​4500µs
-  * The full frame is sent 3 times with a timing >9500 between frames+  * The full frame is sent 3 times with a timing >9500µs ​between frames
  
-My asumption was a short pulse was a separator, a medium pulse was a "​0"​ bit and a long pulse a "​1"​ bit. So I tried to decode bytes knowing the expected temperature which is displayed on the sensor itself: so easy, the 3rd byte is the temperature x10.+My asumption was a short pulse was a separator, a medium pulse was a "​0"​ bit and a long pulse a "​1"​ bit. So I tried to decode bytes knowing the expected temperature which is displayed on the sensor itself: so easy, the 3rd byte is the temperature x10 simply encoded in decimal.
  
 So now, this is what I found: So now, this is what I found:
Line 38: Line 41:
   * 2 next bits are the channel you can choose on the sensor itself: 1, 2 or 3. This is to be able to know the source of the temperature when you have several sensors.   * 2 next bits are the channel you can choose on the sensor itself: 1, 2 or 3. This is to be able to know the source of the temperature when you have several sensors.
   * Last 2 bits are always "​00",​ probably stop bits   * Last 2 bits are always "​00",​ probably stop bits
 +
 +===== The arduino sketch =====
 +
 +The following sketch reads the temperature and outputs to the serial line in JSON format. In this sketch, I use RFControl library as is, so it is not very optimized for my needs. However, for now it works and it is enough!
 +
 +<file c++ SmartHomeBox_sgripon.ino>​
 +#include <​RFControl.h>​
 +
 +// Save current temperature and channel
 +int temperature = 0;
 +int channel = 0;
 +
 +void setup() {
 +  ​
 +  // Initialize serial line
 +  Serial.begin(115200);​
 +
 +  // Start receiving RF signals
 +  RFControl::​startReceiving(0);​
 +}
 +
 +// The function prints current data to the serial line
 +void printData() {
 +    Serial.print("​{ ");
 +    Serial.print("​\"​temp\":​ ");
 +    Serial.print(temperature);​
 +    Serial.print(",​ \"​channel\":​ ");
 +    Serial.print(channel);​
 +    Serial.print("​ }\n");
 +}
 +
 +void loop() {
 +  ​
 +  // Decode data when received
 +  if(RFControl::​hasData()) {
 +    unsigned int *timings;
 +    unsigned int timings_size;​
 +    unsigned int pulse_length_divider = RFControl::​getPulseLengthDivider();​
 +    RFControl::​getRaw(&​timings,​ &​timings_size);​
 +
 +    int iTemperatureTmp = 0;
 +    int iChannelTmp = 0;
 +    ​
 +    for(int i=0; i < timings_size;​ i++) {
 +      unsigned long timing = timings[i] * pulse_length_divider;​
 +
 +      // Temperature is at bit 16*2 coded in decimal x 10 on 8 bits
 +      if( (i >= 16*2) && (i < (16*2 + 8*2)) ) {
 +        if(i == 16*2) iTemperatureTmp = 0;
 +
 +        if(timing < 1000) {
 +          // bit separator, do nothing
 +        }
 +        else if(timing < 2000) {
 +          iTemperatureTmp = iTemperatureTmp<<​1;​
 +        }
 +        else if(timing < 5000) {
 +          iTemperatureTmp = iTemperatureTmp<<​1;​
 +          iTemperatureTmp++;​
 +        }
 +      }
 +      // Sensor Channel is after byte 3, on 2 bits, decimal encoded
 +      else if((i >= 24*2) && i <= 26*2) {
 +        if(i == 24*2) channel = 0;
 +        if(timing < 1000) {
 +          // bit separator, do nothing
 +        }
 +        else if(timing < 2000) {
 +          iChannelTmp = iChannelTmp<<​1;​
 +        }
 +        else if(timing < 5000) {
 +          iChannelTmp = iChannelTmp<<​1;​
 +          iChannelTmp++;​
 +        }
 +      }
 +      // Other data
 +      else {
 +        // Do nothing for now
 +      }
 +    }
 +
 +    temperature = iTemperatureTmp;​
 +    channel = iChannelTmp;​
 +        ​
 +    RFControl::​continueReceiving();​
 +  }
 +  ​
 +  printData(); ​
 +}
 +</​file>​
 +===== Next Step =====
 +
 +  * [[add_temperature_sensor_in_domoticz|Add temperature sensor in Domoticz]] using a respberry pi.
 +
 ===== References ===== ===== References =====
   * RFControl RF 433MHz sniffer library for Arduino: [[https://​github.com/​pimatic/​RFControl|RFControl]]   * RFControl RF 433MHz sniffer library for Arduino: [[https://​github.com/​pimatic/​RFControl|RFControl]]
record_temperature_from_lexibook_asm30_sensor.1459588638.txt.gz · Last modified: 2016/04/02 11:17 by sgripon