Skip to content

Commit

Permalink
Add HM-WDS40-TH-I example
Browse files Browse the repository at this point in the history
  • Loading branch information
psi-4ward committed Nov 23, 2019
1 parent 19ecad7 commit af8b433
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 0 deletions.
161 changes: 161 additions & 0 deletions examples/HM-WDS40-TH-I/HM-WDS40-TH-I.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
//- -----------------------------------------------------------------------------------------------------------------------
// AskSin++
// 2016-10-31 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
//- -----------------------------------------------------------------------------------------------------------------------

// define this to read the device id, serial and device type from bootloader section
// #define USE_OTA_BOOTLOADER

#define EXTRAMILLIS 730 // 730 millisecond extra time to better hit the slot
#define EI_NOTEXTERNAL // Disable all external interruptes
#include <EnableInterrupt.h>
#include <AskSinPP.h>
#include <LowPower.h>
#include <Register.h>
#include <MultiChannelDevice.h>
#include <Weather.h>

#define LED_PIN 4
#define CONFIG_BUTTON_PIN 8

// === Festlegung welcher Sensor benutzt wird ===
#define SENSOR_BME280
//#define SENSOR_DHT22
//#define SENSOR_SHT10
//#define SENSOR_SHT31
//#define SENSOR_SI7021

// === Festelgung der Clock ===
// RTC Clock Benutzen (zB HMSensor mit verbautem 32kHz Quarz)
#define USE_RTC

// === Batteriespannungsmessung ===
// Interne Messung (Batteriespannung am AVR)
//#define BAT_SENSOR BatterySensor
//#define BAT_VOLT_LOW 21 // 2.1V
//#define BAT_VOLT_CRITICAL 19 // 1.9V
// Externe Messung (Batteriespannung über GPIO Pins) (TLV61224 StepUp can handle 0.7V)
#define BAT_VOLT_LOW 20 // 2.0V
#define BAT_VOLT_CRITICAL 13 // 1.3V
#define BAT_SENSOR BatterySensorUni<17,7,3000>

// === Sensor Offset Einstellungen ===
// OFFSET für Temperatur -> gemessene Temp +/- Offset = Angezeigte Temp.
#define OFFSETtemp 0 //z.B -50 ≙ -5°C / 50 ≙ +5°C
// OFFSET für Luftfeuchte -> gemessene Luftf. +/- Offset = Angezeigte Luftf.
#define OFFSEThumi 0 //z.B -10 ≙ -10%RF / 10 ≙ +10%RF

// number of available peers per channel
#define PEERS_PER_CHANNEL 6

// all library classes are placed in the namespace 'as'
using namespace as;

// define all device properties
const struct DeviceInfo PROGMEM devinfo = {
{0x34,0x56,0x79}, // Device ID
"papa111111", // Device Serial
{0x00,0x3f}, // Device Model: HM-WDS40-TH-I
0x10, // Firmware Version
as::DeviceType::THSensor, // Device Type
{0x01,0x00} // Info Bytes
};


#ifdef SENSOR_BME280
#include <sensors/Bme280.h>
typedef Bme280 SensorType;
#endif
#ifdef SENSOR_DHT22
#include <sensors/Dht.h>
typedef Dht<4,DHT22> SensorType;
#endif
#ifdef SENSOR_SHT10
#include <sensors/Sht10.h>
typedef Sht10<A4, A5> SensorType;
#endif
#ifdef SENSOR_SHT31
#include <sensors/Sht31.h>
typedef Sht31<> SensorType;
#endif
#ifdef SENSOR_SI7021
#include <sensors/Si7021.h>
typedef Si7021 SensorType;
#endif

/**
* Configure the used hardware
*/
typedef AvrSPI<10,11,12,13> SPIType;
typedef Radio<SPIType,2> RadioType;
typedef StatusLed<LED_PIN> LedType;
#ifdef USE_RTC
typedef AskSinRTC<LedType,BAT_SENSOR,RadioType> Hal;
#else
typedef AskSin<LedType,BAT_SENSOR,RadioType> Hal;
#endif

/*
* Define List0 registers
*/
DEFREGISTER(WeatherRegsList0,MASTERID_REGS,DREG_BURSTRX)
typedef RegList0<WeatherRegsList0> WeatherList0;

/*
* Sensors class is used by the WeatherChannel to measure the data. It has to implement
* temperature() and humidity().
*/
class Sensors : public Alarm {
SensorType sensor;
public:
Sensors () {}
// init the used hardware
void init () { sensor.init(); }
// return how many milliseconds the measure should start in front of sending the message
uint16_t before () const { return 4000; }
// get the data
virtual void trigger (__attribute__ ((unused)) AlarmClock& clock) {
DPRINTLN("Measure... ");
sensor.measure();
DPRINT("T: ");DDEC(sensor.temperature()+OFFSETtemp);DPRINT(" H: ");DDECLN(sensor.humidity()+OFFSEThumi);
}
uint16_t temperature () { return sensor.temperature()+OFFSETtemp; }
uint8_t humidity () { return sensor.humidity()+OFFSEThumi; }
};

#ifdef USE_RTC
typedef WeatherChannel<Hal,RTC,Sensors,PEERS_PER_CHANNEL,EXTRAMILLIS,WeatherList0> ChannelType;
#else
typedef WeatherChannel<Hal,SysClock,Sensors,PEERS_PER_CHANNEL,EXTRAMILLIS,WeatherList0> ChannelType;
#endif
typedef MultiChannelDevice<Hal,ChannelType,1,WeatherList0> WeatherType;

Hal hal;
WeatherType sdev(devinfo,0x20);
ConfigButton<WeatherType> cfgBtn(sdev);

void setup () {
DINIT(57600,ASKSIN_PLUS_PLUS_IDENTIFIER);
sdev.init(hal);
buttonISR(cfgBtn,CONFIG_BUTTON_PIN);
// Measure Battery every 1h
hal.initBattery(60UL*60,BAT_VOLT_LOW,BAT_VOLT_CRITICAL);
sdev.initDone();
DDEVINFO(sdev);
}

void loop() {
bool worked = hal.runready();
bool poll = sdev.pollRadio();
if( worked == false && poll == false ) {
if( hal.battery.critical() ) {
// this call will never return
hal.activity.sleepForever(hal);
}
#ifdef USE_RTC
hal.sleep<>();
#else
hal.activity.savePower<Sleep<>>(hal);
#endif
}
}
20 changes: 20 additions & 0 deletions examples/HM-WDS40-TH-I/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[platformio]
src_dir = .

[env:pro8MHzatmega328]
platform = atmelavr
framework = arduino
board = pro8MHzatmega328
monitor_speed = 57600

lib_deps =
AskSinPP
EnableInterrupt
Low-Power
# Enable the sensors you want to use:
# BME280
# DHT sensor library
# Adafruit Unified Sensor
# Sensirion
# Adafruit SHT31 Library
# Si7021

0 comments on commit af8b433

Please sign in to comment.