update temp_sensor and adapt gateway to it
This commit is contained in:
parent
d1cd5d6560
commit
d622d70dc0
@ -12,6 +12,8 @@
|
|||||||
platform = atmelavr
|
platform = atmelavr
|
||||||
board = pro16MHzatmega328
|
board = pro16MHzatmega328
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
lib_extra_dirs =
|
||||||
|
../libraries
|
||||||
lib_deps =
|
lib_deps =
|
||||||
sui77/rc-switch@^2.6.3
|
sui77/rc-switch@^2.6.3
|
||||||
bblanchon/ArduinoJson@6.16.1
|
bblanchon/ArduinoJson@6.16.1
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <Adafruit_Sensor.h>
|
#include <Adafruit_Sensor.h>
|
||||||
#include <DHT.h>
|
#include <DHT.h>
|
||||||
|
#include "Tiny.h"
|
||||||
|
|
||||||
#define RESET_PIN 10
|
#define RESET_PIN 10
|
||||||
#define SEND_PIN 11
|
#define SEND_PIN 11
|
||||||
@ -64,6 +65,20 @@ void readRcSwitch(JsonDocument& jsonDoc) {
|
|||||||
motion["basement"] = value == 1879048230L ? "on" : "off";
|
motion["basement"] = value == 1879048230L ? "on" : "off";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (GET_TYPE(value) == SensorType::TEMPERATURE) {
|
||||||
|
JsonObject sensor = jsonDoc.createNestedObject("sensor");
|
||||||
|
sensor["id"] = ID(value);
|
||||||
|
sensor["temperature"] = GET_TEMP(value);
|
||||||
|
sensor["voltage"] = GET_VCC(value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (GET_TYPE(value) == SensorType::CONTACT) {
|
||||||
|
JsonObject sensor = jsonDoc.createNestedObject("contact");
|
||||||
|
sensor["id"] = ID(value);
|
||||||
|
sensor["state"] = GET_STATE(value) ? "on" : "off";
|
||||||
|
sensor["voltage"] = GET_VCC(value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
JsonObject rcSwitch = jsonDoc.createNestedObject("rcSwitch");
|
JsonObject rcSwitch = jsonDoc.createNestedObject("rcSwitch");
|
||||||
rcSwitch["protocol"] = mySwitch.getReceivedProtocol();
|
rcSwitch["protocol"] = mySwitch.getReceivedProtocol();
|
||||||
|
|||||||
@ -3,12 +3,12 @@
|
|||||||
#include <TinySensor.h>
|
#include <TinySensor.h>
|
||||||
#include <RCSwitch.h>
|
#include <RCSwitch.h>
|
||||||
|
|
||||||
class TempSensor: public TinySensor {
|
class TempSensor : public TinySensor {
|
||||||
SensorType sensorType = TEMPERATURE;
|
SensorType sensorType = TEMPERATURE;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TempSensor(short id, short senderPin) :
|
TempSensor(short id, short senderPin) :
|
||||||
TinySensor(id, senderPin) {
|
TinySensor(id, senderPin) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendTempAndVoltage(int temp) {
|
void sendTempAndVoltage(int temp) {
|
||||||
|
|||||||
@ -1,7 +1,20 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ContactSensor.h>
|
#define ID(value) (value & 0x1F)
|
||||||
#include <TempSensor.h>
|
#define STATE(value) ((value & 0x1) << 5)
|
||||||
|
#define VCC(value) ((value & 0x1FFF) << 6)
|
||||||
|
#define TEMP(value) (((unsigned long)value & 0x1FF) << 19)
|
||||||
|
#define TYPE(value) (((unsigned long)value & 0xF) << 28)
|
||||||
|
|
||||||
|
#define GET_TYPE(value) (((unsigned long)value >> 28) & 0xF)
|
||||||
|
#define GET_TEMP(value) (((unsigned long)value >> 19) & 0x1FF)
|
||||||
|
#define GET_VCC(value) ((value >> 6) & 0x1FFF)
|
||||||
|
#define GET_STATE(value) ((value >> 5) & 0x1)
|
||||||
|
|
||||||
|
typedef enum SensorType {
|
||||||
|
TEMPERATURE = 6,
|
||||||
|
CONTACT = 7
|
||||||
|
};
|
||||||
|
|
||||||
enum SensorId : int {
|
enum SensorId : int {
|
||||||
WINDOW1 = 1,
|
WINDOW1 = 1,
|
||||||
|
|||||||
@ -1,18 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <RCSwitch.h>
|
#include <RCSwitch.h>
|
||||||
|
#include "Tiny.h"
|
||||||
#define ID(value) (value & 0x1F)
|
|
||||||
#define STATE(value) ((value & 0x1) << 5)
|
|
||||||
#define VCC(value) ((value & 0x1FFF) << 6)
|
|
||||||
#define TEMP(value) (((unsigned long)value & 0x1FF) << 19)
|
|
||||||
#define TYPE(value) (((unsigned long)value & 0xF) << 28)
|
|
||||||
|
|
||||||
typedef enum SensorType {
|
|
||||||
TEMPERATURE = 6,
|
|
||||||
CONTACT = 7
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class TinySensor {
|
class TinySensor {
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@ -1,14 +1,16 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <Tiny.h>
|
#include <TempSensor.h>
|
||||||
#include <TinyPower.h>
|
#include <TinyPower.h>
|
||||||
#include <SoftwareSerial_Tiny.h>
|
#include <SoftwareSerial_Tiny.h>
|
||||||
|
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
#define SEND_INTERVAL (int)(5*60/8)
|
#define SEND_INTERVAL (int)(5*60/8)
|
||||||
|
#define SEND_VCC_INTERVAL (int)(60*60/8)
|
||||||
|
|
||||||
// Pins
|
// Pins
|
||||||
#define SENDER PIN_B4
|
#define TEMP_POSITIVE PIN_B3
|
||||||
#define TEMP_PIN A1
|
#define SENDER PIN_B2
|
||||||
|
#define TEMP_PIN A2
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
#define RxD PIN_B3
|
#define RxD PIN_B3
|
||||||
@ -21,7 +23,6 @@ int readTemp();
|
|||||||
TempSensor sensor = TempSensor(TEMP_SENSOR, SENDER);
|
TempSensor sensor = TempSensor(TEMP_SENSOR, SENDER);
|
||||||
|
|
||||||
volatile int counter = 0;
|
volatile int counter = 0;
|
||||||
volatile bool shouldSend = true;
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
@ -31,21 +32,28 @@ void setup() {
|
|||||||
#endif
|
#endif
|
||||||
sensor.setup();
|
sensor.setup();
|
||||||
analogReference(INTERNAL);
|
analogReference(INTERNAL);
|
||||||
|
pinMode(TEMP_POSITIVE, OUTPUT);
|
||||||
|
digitalWrite(TEMP_POSITIVE, LOW);
|
||||||
|
|
||||||
TinyPower::setup();
|
TinyPower::setup();
|
||||||
TinyPower::enableWdt(WDTO_8S);
|
TinyPower::enableWdt(WDTO_8S);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (shouldSend) {
|
if (counter % SEND_VCC_INTERVAL == 0) {
|
||||||
shouldSend = false;
|
sensor.sendTempAndVoltage(readTemp());
|
||||||
|
counter = 0;
|
||||||
|
} else if (counter % SEND_INTERVAL == 0) {
|
||||||
sensor.sendTemp(readTemp());
|
sensor.sendTemp(readTemp());
|
||||||
}
|
}
|
||||||
TinyPower::sleep();
|
TinyPower::sleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
int readTemp() {
|
int readTemp() {
|
||||||
|
digitalWrite(TEMP_POSITIVE, HIGH);
|
||||||
|
delay(10);
|
||||||
int reading = analogRead(TEMP_PIN);
|
int reading = analogRead(TEMP_PIN);
|
||||||
|
digitalWrite(TEMP_POSITIVE, LOW);
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
AttinySerial.println(reading);
|
AttinySerial.println(reading);
|
||||||
#endif
|
#endif
|
||||||
@ -69,8 +77,4 @@ ISR(PCINT0_vect) {
|
|||||||
|
|
||||||
ISR(WDT_vect) {
|
ISR(WDT_vect) {
|
||||||
counter++;
|
counter++;
|
||||||
if (counter % SEND_INTERVAL == 0) {
|
|
||||||
shouldSend = true;
|
|
||||||
counter = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user