mirror of
https://github.com/anklimov/lighthub
synced 2026-09-13 13:44:04 +00:00
Merge pull request #40 from anklimov/develop
Develop to master MANY stability improvements, Wifi, compilation for all platforms, include ESP32, new sensors, Embedded MAC address for ESPx and DUE, New RGB conversion algorithm and Node-Red compatibility Release-Candidate for 2.0 Merge
This commit is contained in:
+3
-1
@@ -3,10 +3,12 @@
|
||||
.clang_complete
|
||||
.gcc-flags.json
|
||||
CMakeListsPrivate.txt
|
||||
custom-build-flags/*
|
||||
build_flags_due.sh
|
||||
build_flags_esp32.sh
|
||||
build_flags_esp8266.sh
|
||||
build_flags_stm32.sh
|
||||
build_flags_due-5500.sh
|
||||
build_flags_mega2560.sh
|
||||
build_flags_controllino.sh
|
||||
build_flags_controllino.sh
|
||||
build_flags_nrf52840.sh
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#! /bin/bash
|
||||
export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short)
|
||||
export FLAGS="$FLAGS -DDMX_DISABLE"
|
||||
#export FLAGS="$FLAGS -DDMX_DISABLE"
|
||||
export FLAGS="$FLAGS -DMODBUS_DISABLE"
|
||||
export FLAGS="$FLAGS -DOWIRE_DISABLE"
|
||||
export FLAGS="$FLAGS -DDHT_DISABLE"
|
||||
#export FLAGS="$FLAGS -DOWIRE_DISABLE"
|
||||
#export FLAGS="$FLAGS -DDHT_DISABLE"
|
||||
export FLAGS="$FLAGS -DCOUNTER_DISABLE"
|
||||
#export FLAGS="$FLAGS -std=gnu++11"
|
||||
CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_esp32.sh
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#! /bin/bash
|
||||
export FLAGS="$FLAGS -DMODBUS_DISABLE"
|
||||
export FLAGS="$FLAGS -DCOUNTER_DISABLE"
|
||||
#export FLAGS="$FLAGS -DCOUNTER_DISABLE"
|
||||
export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short)
|
||||
CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_esp8266.sh
|
||||
if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then
|
||||
|
||||
@@ -3,10 +3,11 @@ export FLAGS="$FLAGS -DWiz5500"
|
||||
export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short)
|
||||
export FLAGS="$FLAGS -DDMX_DISABLE"
|
||||
export FLAGS="$FLAGS -DMODBUS_DISABLE"
|
||||
export FLAGS="$FLAGS -DOWIRE_DISABLE"
|
||||
#export FLAGS="$FLAGS -DOWIRE_DISABLE"
|
||||
export FLAGS="$FLAGS -std=gnu++11"
|
||||
export FLAGS="$FLAGS -DWIFI_MANAGER_DISABLE"
|
||||
export FLAGS="$FLAGS -DCOUNTER_DISABLE"
|
||||
export FLAGS="$FLAGS -DCSSHDC_DISABLE"
|
||||
|
||||
CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_nrf52840.sh
|
||||
if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then
|
||||
|
||||
@@ -6,6 +6,8 @@ export FLAGS="$FLAGS -DMODBUS_DISABLE"
|
||||
export FLAGS="$FLAGS -DOWIRE_DISABLE"
|
||||
export FLAGS="$FLAGS -DDHT_DISABLE"
|
||||
export FLAGS="$FLAGS -DCOUNTER_DISABLE"
|
||||
export FLAGS="$FLAGS -DNO_HOMIE"
|
||||
export FLAGS="$FLAGS -DCSSHDC_DISABLE"
|
||||
if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then
|
||||
source $CUSTOM_BUILD_FLAGS_FILE
|
||||
fi
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Executable
BIN
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Executable
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Executable
BIN
Binary file not shown.
@@ -3,14 +3,14 @@
|
||||
# first make your own copy of template
|
||||
# cp build_flags_template.sh build_flags_ENVNAME.sh
|
||||
# then edit, change or comment something
|
||||
export FLAGS="$FLAGS -DMY_CONFIG_SERVER=lazyhome.ru"
|
||||
#export FLAGS="$FLAGS -DWATCH_DOG_TICKER_DISABLE"
|
||||
#export FLAGS="$FLAGS -DUSE_1W_PIN=12"
|
||||
#export FLAGS="$FLAGS -DSD_CARD_INSERTED"
|
||||
export FLAGS="$FLAGS -DSERIAL_BAUD=115200"
|
||||
#export FLAGS="$FLAGS -DWiz5500"
|
||||
#export FLAGS="$FLAGS -DDISABLE_FREERAM_PRINT"
|
||||
export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:ff"
|
||||
# export FLAGS="$FLAGS -DMY_CONFIG_SERVER=lazyhome.ru"
|
||||
# export FLAGS="$FLAGS -DWATCH_DOG_TICKER_DISABLE"
|
||||
# export FLAGS="$FLAGS -DUSE_1W_PIN=12"
|
||||
# export FLAGS="$FLAGS -DSD_CARD_INSERTED"
|
||||
# export FLAGS="$FLAGS -DSERIAL_BAUD=115200"
|
||||
# export FLAGS="$FLAGS -DWiz5500"
|
||||
# export FLAGS="$FLAGS -DDISABLE_FREERAM_PRINT"
|
||||
# export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:ff"
|
||||
# export FLAGS="$FLAGS -DDMX_DISABLE"
|
||||
# export FLAGS="$FLAGS -DMODBUS_DISABLE"
|
||||
# export FLAGS="$FLAGS -DOWIRE_DISABLE"
|
||||
@@ -24,9 +24,10 @@
|
||||
# export FLAGS="$FLAGS -DDHCP_RETRY_INTERVAL=60000"
|
||||
# export FLAGS="$FLAGS -DRESTART_LAN_ON_MQTT_ERRORS"
|
||||
# export FLAGS="$FLAGS -DW5500_CS_PIN=53"
|
||||
#export FLAGS="$FLAGS -DSYSLOG_ENABLE"
|
||||
#export FLAGS="$FLAGS -DDEVICE_NAME=MYDEVICE"
|
||||
#export FLAGS="$FLAGS -DDHT_COUNTER_DISABLE"
|
||||
#export FLAGS="$FLAGS -DWITH_PRINTEX_LIB"
|
||||
export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short)
|
||||
# export FLAGS="$FLAGS -DSYSLOG_ENABLE"
|
||||
# export FLAGS="$FLAGS -DDEVICE_NAME=MYDEVICE"
|
||||
# export FLAGS="$FLAGS -DDHT_DISABLE"
|
||||
# export FLAGS="$FLAGS -DCOUNTER_DISABLE"
|
||||
# export FLAGS="$FLAGS -DWITH_PRINTEX_LIB"
|
||||
# export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short)
|
||||
echo $FLAGS
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
#include "abstractin.h"
|
||||
#include <PubSubClient.h>
|
||||
#include "utils.h"
|
||||
#include <aJSON.h>
|
||||
#include "inputs.h"
|
||||
|
||||
extern PubSubClient mqttClient;
|
||||
|
||||
int abstractIn::publish(long value, char* subtopic)
|
||||
{
|
||||
char valstr[16];
|
||||
printUlongValueToStr(valstr, value);
|
||||
return publish(valstr,subtopic);
|
||||
};
|
||||
|
||||
int abstractIn::publish(float value, char* subtopic)
|
||||
{
|
||||
char valstr[16];
|
||||
printFloatValueToStr(value, valstr);
|
||||
return publish(valstr,subtopic);
|
||||
};
|
||||
|
||||
int abstractIn::publish(char * value, char* subtopic)
|
||||
{
|
||||
char addrstr[MQTT_TOPIC_LENGTH];
|
||||
if (in)
|
||||
{
|
||||
aJsonObject *emit = aJson.getObjectItem(in->inputObj, "emit");
|
||||
if (emit)
|
||||
{
|
||||
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
||||
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||
strncat(addrstr,subtopic,sizeof(addrstr));
|
||||
if (mqttClient.connected())
|
||||
{
|
||||
mqttClient.publish(addrstr, value, true);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "Arduino.h"
|
||||
|
||||
class Input;
|
||||
class abstractIn {
|
||||
public:
|
||||
abstractIn(Input * _in){in=_in;};
|
||||
virtual int Setup(int addr) = 0;
|
||||
virtual int Poll() = 0;
|
||||
|
||||
protected:
|
||||
Input * in;
|
||||
int publish(long value, char* subtopic = NULL);
|
||||
int publish(float value, char* subtopic = NULL );
|
||||
int publish(char * value, char* subtopic = NULL);
|
||||
friend Input;
|
||||
};
|
||||
+13
-6
@@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
const char state_P[] PROGMEM = "$state";
|
||||
const char disconnected_P[] PROGMEM = "disconnected";
|
||||
@@ -7,9 +8,15 @@ const char homie_P[] PROGMEM = "$homie";
|
||||
const char homiever_P[] PROGMEM = "2.1.0";
|
||||
|
||||
const char name_P[] PROGMEM = "$name";
|
||||
const char nameval_P[] PROGMEM = "LightHub";
|
||||
const char nameval_P[] PROGMEM = "LightHub ";
|
||||
|
||||
const char nodes_P[] PROGMEM = "$nodes";
|
||||
const char localip_P[] PROGMEM = "$localip";
|
||||
const char mac_P[] PROGMEM = "$mac";
|
||||
const char fwname_P[] PROGMEM = "$fw/name";
|
||||
const char fwversion_P[] PROGMEM = "$fw/version";
|
||||
const char implementation_P[] PROGMEM = "$implementation";
|
||||
const char interval_P[] PROGMEM = "$stats/interval";
|
||||
const char color_P[] PROGMEM = "color";
|
||||
|
||||
const char datatype_P[] PROGMEM = "$datatype";
|
||||
@@ -22,10 +29,10 @@ const char format_P[] PROGMEM = "$format";
|
||||
const char true_P[] PROGMEM = "true";
|
||||
const char false_P[] PROGMEM = "false";
|
||||
|
||||
const char enumformat_P[] PROGMEM = "ON,OFF,HALT,REST,XON,XOFF,TOGGLE";
|
||||
const char enumformat_P[] PROGMEM = "ON,OFF,HALT,REST,XON,XOFF,TOGGLE";
|
||||
const char intformat_P[] PROGMEM = "0-100";
|
||||
|
||||
const char stats_P[] PROGMEM = "$stats";
|
||||
const char statsval_P[] PROGMEM = "uptime,freeheap";
|
||||
const char uptime_P[] PROGMEM = "uptime";
|
||||
const char freeheap_P[] PROGMEM = "freeheap";
|
||||
const char stats_P[] PROGMEM = "$stats";
|
||||
const char statsval_P[] PROGMEM = "uptime,freeheap";
|
||||
const char uptime_P[] PROGMEM = "uptime";
|
||||
const char freeheap_P[] PROGMEM = "freeheap";
|
||||
|
||||
+201
-119
@@ -26,17 +26,21 @@ e-mail anklimov@gmail.com
|
||||
#ifndef DHT_DISABLE
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
#include <DHTesp.h>
|
||||
|
||||
#else
|
||||
#include "DHT.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
extern PubSubClient mqttClient;
|
||||
extern aJsonObject *root;
|
||||
extern int8_t ethernetIdleCount;
|
||||
|
||||
#ifndef COUNTER_DISABLE
|
||||
#if !defined(DHT_DISABLE) || !defined(COUNTER_DISABLE)
|
||||
static volatile unsigned long nextPollMillisValue[5];
|
||||
static volatile int nextPollMillisPin[5] = {0,0,0,0,0};
|
||||
#endif
|
||||
|
||||
#ifndef COUNTER_DISABLE
|
||||
#if defined(ARDUINO_ARCH_AVR)
|
||||
static volatile long counter_value[6];
|
||||
#endif
|
||||
@@ -49,7 +53,7 @@ static volatile long counter_value[6];
|
||||
static volatile long counter_value[6];
|
||||
#endif
|
||||
|
||||
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32F1)
|
||||
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32)
|
||||
static short counter_irq_map[54];
|
||||
static long counter_value[54];
|
||||
static int counters_count;
|
||||
@@ -91,7 +95,7 @@ void Input::Parse()
|
||||
store = NULL;
|
||||
inType = 0;
|
||||
pin = 0;
|
||||
if (inputObj && (inputObj->type == aJson_Object)) {
|
||||
if (inputObj && (inputObj->type == aJson_Object) && root) {
|
||||
aJsonObject *itemBuffer;
|
||||
itemBuffer = aJson.getObjectItem(inputObj, "T");
|
||||
if (itemBuffer) inType = static_cast<uint8_t>(itemBuffer->valueint);
|
||||
@@ -106,25 +110,81 @@ void Input::Parse()
|
||||
}
|
||||
}
|
||||
|
||||
int Input::poll() {
|
||||
if (!isValid()) return -1;
|
||||
if (0) ;
|
||||
void Input::setup()
|
||||
{
|
||||
if (!isValid() || (!root)) return;
|
||||
|
||||
#ifndef DHT_DISABLE
|
||||
else if (inType & IN_DHT22)
|
||||
dht22Poll();
|
||||
else if (inType & IN_COUNTER)
|
||||
counterPoll();
|
||||
else if (inType & IN_UPTIME)
|
||||
uptimePoll();
|
||||
#ifndef CSSHDC_DISABLE
|
||||
in_ccs811 ccs811(this);
|
||||
in_hdc1080 hdc1080(this);
|
||||
|
||||
if (inType == IN_CCS811)
|
||||
ccs811.Setup(pin);
|
||||
else if (inType == IN_HDC1080)
|
||||
hdc1080.Setup(pin);
|
||||
// TODO rest types setup
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
int Input::poll(short cause) {
|
||||
|
||||
if (!isValid()) return -1;
|
||||
#ifndef CSSHDC_DISABLE
|
||||
in_ccs811 ccs811(this);
|
||||
in_hdc1080 hdc1080(this);
|
||||
#endif
|
||||
|
||||
switch (cause) {
|
||||
case CHECK_INPUT: //Fast polling
|
||||
switch (inType)
|
||||
{
|
||||
case IN_PUSH_ON:
|
||||
case IN_PUSH_ON | IN_ACTIVE_HIGH:
|
||||
case IN_PUSH_TOGGLE :
|
||||
case IN_PUSH_TOGGLE | IN_ACTIVE_HIGH:
|
||||
contactPoll();
|
||||
break;
|
||||
case IN_ANALOG:
|
||||
case IN_ANALOG | IN_ACTIVE_HIGH:
|
||||
analogPoll();
|
||||
break;
|
||||
|
||||
// No fast polling
|
||||
case IN_DHT22:
|
||||
case IN_COUNTER:
|
||||
case IN_UPTIME:
|
||||
case IN_CCS811:
|
||||
case IN_HDC1080:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case CHECK_SENSOR: //Slow polling
|
||||
switch (inType)
|
||||
{
|
||||
#ifndef CSSHDC_DISABLE
|
||||
case IN_CCS811:
|
||||
ccs811.Poll();
|
||||
break;
|
||||
case IN_HDC1080:
|
||||
hdc1080.Poll();
|
||||
break;
|
||||
#endif
|
||||
else if (inType & IN_ANALOG)
|
||||
analogPoll();
|
||||
else
|
||||
contactPoll();
|
||||
return 0;
|
||||
|
||||
// contactPoll();
|
||||
#ifndef DHT_DISABLE
|
||||
case IN_DHT22:
|
||||
dht22Poll();
|
||||
break;
|
||||
#endif
|
||||
#ifndef COUNTER_DISABLE
|
||||
case IN_COUNTER:
|
||||
counterPoll();
|
||||
break;
|
||||
case IN_UPTIME:
|
||||
uptimePoll();
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef COUNTER_DISABLE
|
||||
@@ -160,10 +220,12 @@ void Input::counterPoll() {
|
||||
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
||||
if (emit) {
|
||||
char valstr[10];
|
||||
char addrstr[100] = "";
|
||||
strcat(addrstr, emit->valuestring);
|
||||
char addrstr[MQTT_TOPIC_LENGTH];
|
||||
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
||||
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||
sprintf(valstr, "%d", counterValue);
|
||||
mqttClient.publish(addrstr, valstr);
|
||||
if (mqttClient.connected() && !ethernetIdleCount)
|
||||
mqttClient.publish(addrstr, valstr);
|
||||
setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT);
|
||||
debugSerial<<F(" NextPollMillis=")<<nextPollTime();
|
||||
}
|
||||
@@ -208,70 +270,8 @@ void Input::attachInterruptPinIrq(int realPin, int irq) {
|
||||
}
|
||||
|
||||
|
||||
void Input::dht22Poll() {
|
||||
if (nextPollTime() > millis())
|
||||
return;
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
DHTesp dhtSensor;
|
||||
dhtSensor.setup(pin, DHTesp::DHT22);
|
||||
TempAndHumidity dhtSensorData = dhtSensor.getTempAndHumidity();
|
||||
float temp = roundf(dhtSensorData.temperature * 10) / 10;
|
||||
float humidity = roundf(dhtSensorData.humidity);
|
||||
#else
|
||||
DHT dht(pin, DHT22);
|
||||
float temp = dht.readTemperature();
|
||||
float humidity = dht.readHumidity();
|
||||
#endif
|
||||
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
||||
debugSerial << F("IN:") << pin << F(" DHT22 type. T=") << temp << F("°C H=") << humidity << F("%");
|
||||
if (emit && temp && humidity && temp == temp && humidity == humidity) {
|
||||
char addrstr[100] = "";
|
||||
#ifdef WITH_DOMOTICZ
|
||||
if(getIdxField()){
|
||||
publishDataToDomoticz(DHT_POLL_DELAY_DEFAULT, emit, "{\"idx\":%s,\"svalue\":\"%.1f;%.0f;0\"}", getIdxField(), temp, humidity);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
char valstr[10];
|
||||
strcat(addrstr, emit->valuestring);
|
||||
strcat(addrstr, "T");
|
||||
printFloatValueToStr(temp, valstr);
|
||||
mqttClient.publish(addrstr, valstr);
|
||||
addrstr[strlen(addrstr) - 1] = 'H';
|
||||
printFloatValueToStr(humidity, valstr);
|
||||
mqttClient.publish(addrstr, valstr);
|
||||
|
||||
setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT);
|
||||
debugSerial << F(" NextPollMillis=") << nextPollTime() << endl;
|
||||
} else
|
||||
setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT / 3);
|
||||
}
|
||||
|
||||
unsigned long Input::nextPollTime() const {
|
||||
for(int i=0;i<5;i++){
|
||||
if(nextPollMillisPin[i]==pin)
|
||||
return nextPollMillisValue[i];
|
||||
else if(nextPollMillisPin[i]==0) {
|
||||
nextPollMillisPin[i]=pin;
|
||||
return nextPollMillisValue[i] = 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Input::setNextPollTime(unsigned long pollTime) {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (nextPollMillisPin[i] == pin) {
|
||||
nextPollMillisValue[i] = pollTime;
|
||||
return;
|
||||
} else if (nextPollMillisPin[i] == 0) {
|
||||
nextPollMillisPin[i] == pin;
|
||||
nextPollMillisValue[i] = pollTime;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Input::uptimePoll() {
|
||||
if (nextPollTime() > millis())
|
||||
@@ -288,7 +288,8 @@ void Input::uptimePoll() {
|
||||
char valstr[11];
|
||||
// printUlongValueToStr(valstr,millis());
|
||||
printUlongValueToStr(valstr, millis());
|
||||
mqttClient.publish(emit->valuestring, valstr);
|
||||
if (mqttClient.connected() && !ethernetIdleCount)
|
||||
mqttClient.publish(emit->valuestring, valstr);
|
||||
}
|
||||
setNextPollTime(millis() + UPTIME_POLL_DELAY_DEFAULT);
|
||||
}
|
||||
@@ -324,16 +325,94 @@ void Input::onCounterChanged5() {
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(DHT_DISABLE) || !defined(COUNTER_DISABLE)
|
||||
unsigned long Input::nextPollTime() const {
|
||||
for(int i=0;i<5;i++){
|
||||
if(nextPollMillisPin[i]==pin)
|
||||
return nextPollMillisValue[i];
|
||||
else if(nextPollMillisPin[i]==0) {
|
||||
nextPollMillisPin[i]=pin;
|
||||
return nextPollMillisValue[i] = 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Input::setNextPollTime(unsigned long pollTime) {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (nextPollMillisPin[i] == pin) {
|
||||
nextPollMillisValue[i] = pollTime;
|
||||
return;
|
||||
} else if (nextPollMillisPin[i] == 0) {
|
||||
nextPollMillisPin[i] == pin;
|
||||
nextPollMillisValue[i] = pollTime;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef DHT_DISABLE
|
||||
|
||||
void Input::dht22Poll() {
|
||||
if (nextPollTime() > millis())
|
||||
return;
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
DHTesp dhtSensor;
|
||||
dhtSensor.setup(pin, DHTesp::DHT22);
|
||||
TempAndHumidity dhtSensorData = dhtSensor.getTempAndHumidity();
|
||||
float temp = roundf(dhtSensorData.temperature * 10) / 10;
|
||||
float humidity = roundf(dhtSensorData.humidity);
|
||||
#else
|
||||
DHT dht(pin, DHT22);
|
||||
dht.begin();
|
||||
float temp = dht.readTemperature();
|
||||
float humidity = dht.readHumidity();
|
||||
#endif
|
||||
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
||||
aJsonObject *item = aJson.getObjectItem(inputObj, "item");
|
||||
if (item) thermoSetCurTemp(item->valuestring, temp);
|
||||
debugSerial << F("IN:") << pin << F(" DHT22 type. T=") << temp << F("°C H=") << humidity << F("%")<<endl;
|
||||
if (emit && temp && humidity && temp == temp && humidity == humidity) {
|
||||
char addrstr[MQTT_TOPIC_LENGTH] = "";
|
||||
#ifdef WITH_DOMOTICZ
|
||||
if(getIdxField()){
|
||||
publishDataToDomoticz(DHT_POLL_DELAY_DEFAULT, emit, "{\"idx\":%s,\"svalue\":\"%.1f;%.0f;0\"}", getIdxField(), temp, humidity);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
char valstr[10];
|
||||
|
||||
strncpy(addrstr, emit->valuestring, sizeof(addrstr));
|
||||
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||
strcat(addrstr, "T");
|
||||
printFloatValueToStr(temp, valstr);
|
||||
if (mqttClient.connected() && !ethernetIdleCount)
|
||||
mqttClient.publish(addrstr, valstr);
|
||||
addrstr[strlen(addrstr) - 1] = 'H';
|
||||
printFloatValueToStr(humidity, valstr);
|
||||
if (mqttClient.connected() && !ethernetIdleCount)
|
||||
mqttClient.publish(addrstr, valstr);
|
||||
|
||||
setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT);
|
||||
debugSerial << F(" NextPollMillis=") << nextPollTime() << endl;
|
||||
} else
|
||||
setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT / 3);
|
||||
}
|
||||
#endif
|
||||
|
||||
void Input::contactPoll() {
|
||||
boolean currentInputState;
|
||||
#if defined(ARDUINO_ARCH_STM32F1)
|
||||
/*
|
||||
#if defined(ARDUINO_ARCH_STM32)
|
||||
WiringPinMode inputPinMode;
|
||||
#endif
|
||||
|
||||
#if defined(__SAM3X8E__)||defined(ARDUINO_ARCH_AVR)||defined(ARDUINO_ARCH_ESP8266)||defined(ARDUINO_ARCH_ESP32)
|
||||
|
||||
#endif
|
||||
*/
|
||||
uint32_t inputPinMode;
|
||||
uint8_t inputOnLevel;
|
||||
if (inType & IN_ACTIVE_HIGH) {
|
||||
@@ -372,12 +451,14 @@ void Input::analogPoll() {
|
||||
short Noize = ANALOG_NOIZE;
|
||||
short simple = 0;
|
||||
|
||||
#if defined(ARDUINO_ARCH_STM32F1)
|
||||
/*
|
||||
#if defined(ARDUINO_ARCH_STM32)
|
||||
WiringPinMode inputPinMode;
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__SAM3X8E__)||defined(ARDUINO_ARCH_AVR)||defined(ARDUINO_ARCH_ESP8266)||defined(ARDUINO_ARCH_ESP32)
|
||||
#endif
|
||||
#endif */
|
||||
uint32_t inputPinMode;
|
||||
if (inType & IN_ACTIVE_HIGH) {
|
||||
inputPinMode = INPUT;
|
||||
@@ -437,22 +518,33 @@ void Input::onContactChanged(int newValue) {
|
||||
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
||||
if (emit) {
|
||||
#ifdef WITH_DOMOTICZ
|
||||
if (getIdxField()) {
|
||||
(newValue)? publishDataToDomoticz(0, emit, "{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"On\"}", getIdxField())
|
||||
: publishDataToDomoticz(0,emit,"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",getIdxField());
|
||||
} else
|
||||
if (getIdxField())
|
||||
{ (newValue) ? publishDataToDomoticz(0, emit, "{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"On\"}",
|
||||
: publishDataToDomoticz(0,emit,"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",getIdxField()); getIdxField())
|
||||
: publishDataToDomoticz(0, emit,
|
||||
"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",
|
||||
getIdxField());
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
char addrstr[MQTT_TOPIC_LENGTH];
|
||||
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
||||
if (mqttClient.connected() && !ethernetIdleCount)
|
||||
{
|
||||
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||
if (newValue) { //send set command
|
||||
if (!scmd) mqttClient.publish(emit->valuestring, "ON", true);
|
||||
if (!scmd) mqttClient.publish(addrstr, "ON", true);
|
||||
else if (strlen(scmd->valuestring))
|
||||
mqttClient.publish(emit->valuestring, scmd->valuestring, true);
|
||||
mqttClient.publish(addrstr, scmd->valuestring, true);
|
||||
} else { //send reset command
|
||||
if (!rcmd) mqttClient.publish(emit->valuestring, "OFF", true);
|
||||
else if (strlen(rcmd->valuestring))mqttClient.publish(emit->valuestring, rcmd->valuestring, true);
|
||||
if (!rcmd) mqttClient.publish(addrstr, "OFF", true);
|
||||
else if (strlen(rcmd->valuestring))mqttClient.publish(addrstr, rcmd->valuestring, true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // emit
|
||||
if (item) {
|
||||
//debugSerial <<F("Controlled item:")<< item->valuestring <<endl;
|
||||
Item it(item->valuestring);
|
||||
if (it.isValid()) {
|
||||
if (newValue) { //send set command
|
||||
@@ -468,7 +560,6 @@ void Input::onContactChanged(int newValue) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Input::onAnalogChanged(int newValue) {
|
||||
debugSerial << F("IN:") << (pin) << F("=") << newValue << endl;
|
||||
aJsonObject *item = aJson.getObjectItem(inputObj, "item");
|
||||
@@ -483,9 +574,13 @@ void Input::onAnalogChanged(int newValue) {
|
||||
// : publishDataToDomoticz(0,emit,"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",getIdxField());
|
||||
// } else
|
||||
//#endif
|
||||
char strVal[16];
|
||||
itoa(newValue,strVal,10);
|
||||
mqttClient.publish(emit->valuestring, strVal, true);
|
||||
char addrstr[MQTT_TOPIC_LENGTH];
|
||||
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
||||
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||
char strVal[16];
|
||||
itoa(newValue,strVal,10);
|
||||
if (mqttClient.connected() && !ethernetIdleCount)
|
||||
mqttClient.publish(addrstr, strVal, true);
|
||||
}
|
||||
|
||||
if (item) {
|
||||
@@ -497,20 +592,6 @@ void Input::onAnalogChanged(int newValue) {
|
||||
}
|
||||
|
||||
|
||||
void Input::printUlongValueToStr(char *valstr, unsigned long value) {
|
||||
char buf[11];
|
||||
int i=0;
|
||||
for(;value>0;i++){
|
||||
unsigned long mod = value - ((unsigned long)(value/10))*10;
|
||||
buf[i]=mod+48;
|
||||
value = (unsigned long)(value/10);
|
||||
}
|
||||
|
||||
for(int n=0;n<=i;n++){
|
||||
valstr[n]=buf[i-n-1];
|
||||
}
|
||||
valstr[i]='\0';
|
||||
}
|
||||
bool Input::publishDataToDomoticz(int pollTimeIncrement, aJsonObject *emit, const char *format, ...)
|
||||
{
|
||||
#ifdef WITH_DOMOTICZ
|
||||
@@ -521,7 +602,8 @@ bool Input::publishDataToDomoticz(int pollTimeIncrement, aJsonObject *emit, cons
|
||||
vsnprintf(valstr, sizeof(valstr) - 1, format, args);
|
||||
va_end(args);
|
||||
debugSerial << valstr;
|
||||
mqttClient.publish(emit->valuestring, valstr);
|
||||
if (mqttClient.connected() && !ethernetIdleCount)
|
||||
mqttClient.publish(emit->valuestring, valstr);
|
||||
if (pollTimeIncrement)
|
||||
setNextPollTime(millis() + pollTimeIncrement);
|
||||
debugSerial << F(" NextPollMillis=") << nextPollTime() << endl;
|
||||
|
||||
+13
-3
@@ -17,8 +17,9 @@ GIT: https://github.com/anklimov/lighthub
|
||||
e-mail anklimov@gmail.com
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <aJSON.h>
|
||||
#include "modules/in_ccs811_hdc1080.h"
|
||||
|
||||
#define IN_ACTIVE_HIGH 2 // High level = PUSHED/ CLOSED/ ON othervise :Low Level. Use INPUT mode instead of INPUT_PULLUP for digital pin
|
||||
#define IN_ANALOG 64 // Analog input
|
||||
@@ -26,14 +27,22 @@ e-mail anklimov@gmail.com
|
||||
|
||||
#define IN_PUSH_ON 0 // PUSH - ON, Release - OFF (ovverrided by pcmd/rcmd) - DEFAULT
|
||||
#define IN_PUSH_TOGGLE 1 // Used for push buttons. Every physicall push toggle logical switch on/off. Toggle on leading edge
|
||||
|
||||
#define IN_DHT22 4
|
||||
#define IN_CCS811 5
|
||||
#define IN_HDC1080 6
|
||||
|
||||
#define IN_COUNTER 8
|
||||
#define IN_UPTIME 16
|
||||
|
||||
|
||||
#define SAME_STATE_ATTEMPTS 3
|
||||
#define ANALOG_STATE_ATTEMPTS 6
|
||||
#define ANALOG_NOIZE 1
|
||||
|
||||
#define CHECK_INPUT 1
|
||||
#define CHECK_SENSOR 2
|
||||
|
||||
// in syntaxis
|
||||
// "pin": { "T":"N", "emit":"out_emit", item:"out_item", "scmd": "ON,OFF,TOGGLE,INCREASE,DECREASE", "rcmd": "ON,OFF,TOGGLE,INCREASE,DECREASE", "rcmd":"repeat_command" }
|
||||
|
||||
@@ -69,6 +78,7 @@ extern aJsonObject *inputs;
|
||||
|
||||
typedef union {
|
||||
long int aslong;
|
||||
uint32_t timestamp;
|
||||
struct {
|
||||
int8_t logicState;
|
||||
int8_t bounce;
|
||||
@@ -95,7 +105,8 @@ public:
|
||||
void onContactChanged(int newValue);
|
||||
void onAnalogChanged(int newValue);
|
||||
|
||||
int poll();
|
||||
int poll(short cause);
|
||||
void setup();
|
||||
|
||||
static void inline onCounterChanged(int i);
|
||||
static void onCounterChanged0();
|
||||
@@ -126,7 +137,6 @@ protected:
|
||||
|
||||
void uptimePoll();
|
||||
|
||||
void printUlongValueToStr(char *valstr, unsigned long value);
|
||||
bool publishDataToDomoticz(int , aJsonObject *, const char *format, ...);
|
||||
|
||||
char* getIdxField();
|
||||
|
||||
+131
-32
@@ -17,6 +17,7 @@ GIT: https://github.com/anklimov/lighthub
|
||||
e-mail anklimov@gmail.com
|
||||
|
||||
*/
|
||||
|
||||
#include "options.h"
|
||||
#include "item.h"
|
||||
#include "aJSON.h"
|
||||
@@ -32,7 +33,28 @@ e-mail anklimov@gmail.com
|
||||
#endif
|
||||
#include <PubSubClient.h>
|
||||
|
||||
const char ON_P[] PROGMEM = "ON";
|
||||
const char OFF_P[] PROGMEM = "OFF";
|
||||
const char REST_P[] PROGMEM = "REST";
|
||||
const char TOGGLE_P[] PROGMEM = "TOGGLE";
|
||||
const char HALT_P[] PROGMEM = "HALT";
|
||||
const char XON_P[] PROGMEM = "XON";
|
||||
const char XOFF_P[] PROGMEM = "XOFF";
|
||||
const char INCREASE_P[] PROGMEM = "INCREASE";
|
||||
const char DECREASE_P[] PROGMEM = "DECREASE";
|
||||
const char TRUE_P[] PROGMEM = "true";
|
||||
const char FALSE_P[] PROGMEM = "false";
|
||||
|
||||
const char SET_P[] PROGMEM = "set";
|
||||
const char TEMP_P[] PROGMEM = "temp";
|
||||
const char MODE_P[] PROGMEM = "mode";
|
||||
const char SETPOINT_P[] PROGMEM = "setpoint";
|
||||
const char POWER_P[] PROGMEM = "power";
|
||||
const char VOL_P[] PROGMEM = "vol";
|
||||
const char HEAT_P[] PROGMEM = "heat";
|
||||
const char HSV_P[] PROGMEM = "hsv";
|
||||
const char RGB_P[] PROGMEM = "rgb";
|
||||
const char RPM_P[] PROGMEM = "rpm";
|
||||
|
||||
short modbusBusy = 0;
|
||||
extern aJsonObject *pollingItem;
|
||||
@@ -41,6 +63,7 @@ extern aJsonObject *pollingItem;
|
||||
//int modbusSet(int addr, uint16_t _reg, int _mask, uint16_t value);
|
||||
|
||||
extern PubSubClient mqttClient;
|
||||
extern int8_t ethernetIdleCount;
|
||||
//extern char outprefix[];
|
||||
//const char outprefix[] PROGMEM = OUTTOPIC;
|
||||
|
||||
@@ -51,19 +74,39 @@ int txt2cmd(char *payload) {
|
||||
int cmd = -1;
|
||||
|
||||
// Check for command
|
||||
if (strcmp(payload, "ON") == 0) cmd = CMD_ON;
|
||||
else if (strcmp(payload, "OFF") == 0) cmd = CMD_OFF;
|
||||
else if (strcmp(payload, "REST") == 0) cmd = CMD_RESTORE;
|
||||
else if (strcmp(payload, "TOGGLE") == 0) cmd = CMD_TOGGLE;
|
||||
else if (strcmp(payload, "HALT") == 0) cmd = CMD_HALT;
|
||||
else if (strcmp(payload, "XON") == 0) cmd = CMD_XON;
|
||||
else if (strcmp(payload, "XOFF") == 0) cmd = CMD_XOFF;
|
||||
else if (strcmp(payload, "INCREASE") == 0) cmd = CMD_UP;
|
||||
else if (strcmp(payload, "DECREASE") == 0) cmd = CMD_DN;
|
||||
else if (*payload == '-' || (*payload >= '0' && *payload <= '9')) cmd = 0;
|
||||
else if (*payload == '{') cmd = -2;
|
||||
else if (*payload == '#') cmd = -3;
|
||||
if (strcmp_P(payload, ON_P) == 0) cmd = CMD_ON;
|
||||
else if (strcmp_P(payload, OFF_P) == 0) cmd = CMD_OFF;
|
||||
else if (strcmp_P(payload, REST_P) == 0) cmd = CMD_RESTORE;
|
||||
else if (strcmp_P(payload, TOGGLE_P) == 0) cmd = CMD_TOGGLE;
|
||||
else if (strcmp_P(payload, HALT_P) == 0) cmd = CMD_HALT;
|
||||
else if (strcmp_P(payload, XON_P) == 0) cmd = CMD_XON;
|
||||
else if (strcmp_P(payload, XOFF_P) == 0) cmd = CMD_XOFF;
|
||||
else if (strcmp_P(payload, TRUE_P) == 0) cmd = CMD_ON;
|
||||
else if (strcmp_P(payload, FALSE_P) == 0) cmd = CMD_OFF;
|
||||
else if (strcmp_P(payload, INCREASE_P) == 0) cmd = CMD_UP;
|
||||
else if (strcmp_P(payload, DECREASE_P) == 0) cmd = CMD_DN;
|
||||
else if (*payload == '-' || (*payload >= '0' && *payload <= '9')) cmd = CMD_NUM; //0
|
||||
else if (*payload == '{') cmd = CMD_JSON;
|
||||
else if (*payload == '#') cmd = CMD_RGB;
|
||||
else if (strncmp_P(payload, HSV_P, 3) == 0) cmd = CMD_HSV;
|
||||
else if (strncmp_P(payload, RGB_P, strlen (RGB_P)) == 0) cmd = CMD_RGB;
|
||||
return cmd;
|
||||
}
|
||||
|
||||
|
||||
int txt2subItem(char *payload) {
|
||||
int cmd = -1;
|
||||
if (!payload || !strlen(payload)) return 0;
|
||||
// Check for command
|
||||
if (strcmp_P(payload, SET_P) == 0) cmd = S_SET;
|
||||
else if (strcmp_P(payload, TEMP_P) == 0) cmd = S_TEMP;
|
||||
else if (strcmp_P(payload, MODE_P) == 0) cmd = S_MODE;
|
||||
else if (strcmp_P(payload, SETPOINT_P) == 0) cmd = S_SETPOINT;
|
||||
else if (strcmp_P(payload, POWER_P) == 0) cmd = S_POWER;
|
||||
else if (strcmp_P(payload, VOL_P) == 0) cmd = S_VOL;
|
||||
else if (strcmp_P(payload, HEAT_P) == 0) cmd = S_HEAT;
|
||||
else if (strcmp_P(payload, HSV_P) == 0) cmd = S_HSV;
|
||||
else if (strcmp_P(payload, RGB_P) == 0) cmd = S_RGB;
|
||||
return cmd;
|
||||
}
|
||||
|
||||
@@ -200,24 +243,46 @@ boolean Item::getEnableCMD(int delta) {
|
||||
|
||||
int Item::Ctrl(char * payload, boolean send, char * subItem){
|
||||
if (!payload) return 0;
|
||||
// debugSerial<<F("'")<<payload<<F("'")<<endl;
|
||||
|
||||
char* subsubItem = NULL;
|
||||
int subItemN = 0;
|
||||
int subsubItemN = 0;
|
||||
bool isSet = false;
|
||||
|
||||
if (subItem && strlen(subItem))
|
||||
{
|
||||
if (subsubItem = strchr(subItem, '/'))
|
||||
{
|
||||
*subsubItem = 0;
|
||||
subsubItem++;
|
||||
subsubItemN = txt2subItem(subsubItem);
|
||||
}
|
||||
subItemN = txt2subItem(subItem);
|
||||
if (subItemN==S_SET || subsubItemN==S_SET) isSet = true;
|
||||
} else isSet = true; /// To be removed - old compatmode
|
||||
|
||||
if (isSet)
|
||||
{
|
||||
int cmd = txt2cmd(payload);
|
||||
debugSerial<<F("Txt2Cmd:")<<cmd<<endl;
|
||||
switch (cmd) {
|
||||
case 0: {
|
||||
case CMD_NUM:
|
||||
case CMD_HSV:
|
||||
{
|
||||
short i = 0;
|
||||
int Par[3];
|
||||
|
||||
while (payload && i < 3)
|
||||
Par[i++] = getInt((char **) &payload);
|
||||
|
||||
return Ctrl(0, i, Par, send, subItem);
|
||||
return Ctrl(0, i, Par, send, subItemN);
|
||||
}
|
||||
break;
|
||||
|
||||
case -1: //Not known command
|
||||
case -2: //JSON input (not implemented yet
|
||||
break;
|
||||
#if not defined(ARDUINO_ARCH_ESP32) and not defined(ESP8266) and not defined(ARDUINO_ARCH_STM32F1) and not defined(DMX_DISABLE)
|
||||
#if not defined(ARDUINO_ARCH_ESP32) and not defined(ESP8266) and not defined(ARDUINO_ARCH_STM32) and not defined(DMX_DISABLE)
|
||||
case -3: //RGB color in #RRGGBB notation
|
||||
{
|
||||
CRGB rgb;
|
||||
@@ -227,7 +292,7 @@ int Item::Ctrl(char * payload, boolean send, char * subItem){
|
||||
Par[0] = map(hsv.h, 0, 255, 0, 365);
|
||||
Par[1] = map(hsv.s, 0, 255, 0, 100);
|
||||
Par[2] = map(hsv.v, 0, 255, 0, 100);
|
||||
return Ctrl(0, 3, Par, send, subItem);
|
||||
return Ctrl(0, 3, Par, send, subItemN);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -236,20 +301,21 @@ int Item::Ctrl(char * payload, boolean send, char * subItem){
|
||||
|
||||
// if (item.getEnableCMD(500) || lanStatus == 4)
|
||||
return Ctrl(cmd, 0, NULL,
|
||||
send, subItem); //Accept ON command not earlier then 500 ms after set settings (Homekit hack)
|
||||
send, subItemN); //Accept ON command not earlier then 500 ms after set settings (Homekit hack)
|
||||
// else debugSerial<<F("on Skipped"));
|
||||
|
||||
break;
|
||||
default: //some known command
|
||||
return Ctrl(cmd, 0, NULL, send, subItem);
|
||||
return Ctrl(cmd, 0, NULL, send, subItemN);
|
||||
|
||||
} //ctrl
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, char * subItem) {
|
||||
int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int subItemN) {
|
||||
|
||||
debugSerial<<F(" MEM=")<<freeRam()<<F(" Item=")<<itemArr->name<<F(" Sub=")<<subItem<<F(" Cmd=")<<cmd<<F(" Par= ");
|
||||
debugSerial<<F("RAM=")<<freeRam()<<F(" Item=")<<itemArr->name<<F(" Sub=")<<subItemN<<F(" Cmd=")<<cmd<<F(" Par= ");
|
||||
if (!itemArr) return -1;
|
||||
int Par[MAXCTRLPAR] = {0, 0, 0};
|
||||
if (Parameters)
|
||||
@@ -514,6 +580,8 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, char * subItem
|
||||
|
||||
|
||||
|
||||
int rgbSaturation =map(Par[1], 0, 100, 0, 255);
|
||||
int rgbValue = map(Par[2], 0, 100, 0, 255);
|
||||
switch (itemType) {
|
||||
|
||||
#ifdef _dmxout
|
||||
@@ -521,14 +589,30 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, char * subItem
|
||||
DmxWrite(iaddr, map(Par[0], 0, 100, 0, 255));
|
||||
break;
|
||||
case CH_RGBW: //Colour RGBW
|
||||
// Saturation 0 - Only white
|
||||
// 0..50 - white + RGB
|
||||
//50..100 RGB
|
||||
{
|
||||
int k;
|
||||
DmxWrite(iaddr + 3, k = map((100 - Par[1]) * Par[2], 0, 10000, 0, 255));
|
||||
debugSerial<<F("W:")<<k<<endl;
|
||||
if (Par[1]<50) { // Using white
|
||||
DmxWrite(iaddr + 3, map((50 - Par[1]) * Par[2], 0, 5000, 0, 255));
|
||||
int rgbvLevel = map (Par[1],0,50,0,255*2);
|
||||
rgbValue = map(Par[2], 0, 100, 0, rgbvLevel);
|
||||
rgbSaturation = map(Par[1], 0, 50, 255, 100);
|
||||
if (rgbValue>255) rgbValue = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
//rgbValue = map(Par[2], 0, 100, 0, 255);
|
||||
rgbSaturation = map(Par[1], 50, 100, 100, 255);
|
||||
DmxWrite(iaddr + 3, 0);
|
||||
}
|
||||
//DmxWrite(iaddr + 3, k = map((100 - Par[1]) * Par[2], 0, 10000, 0, 255));
|
||||
//debugSerial<<F("W:")<<k<<endl;
|
||||
}
|
||||
case CH_RGB: // RGB
|
||||
{
|
||||
CRGB rgb = CHSV(map(Par[0], 0, 365, 0, 255), map(Par[1], 0, 100, 0, 255), map(Par[2], 0, 100, 0, 255));
|
||||
CRGB rgb = CHSV(map(Par[0], 0, 365, 0, 255), rgbSaturation, rgbValue);
|
||||
DmxWrite(iaddr, rgb.r);
|
||||
DmxWrite(iaddr + 1, rgb.g);
|
||||
DmxWrite(iaddr + 2, rgb.b);
|
||||
@@ -569,7 +653,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, char * subItem
|
||||
while (i) {
|
||||
Item it(i->valuestring);
|
||||
// it.copyPar(itemVal);
|
||||
it.Ctrl(cmd, n, Par, send); //// was true
|
||||
it.Ctrl(cmd, n, Par, send,subItemN); //// was true
|
||||
i = i->next;
|
||||
} //while
|
||||
} //if
|
||||
@@ -577,17 +661,29 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, char * subItem
|
||||
break;
|
||||
case CH_RELAY: {
|
||||
int k;
|
||||
short inverse = 0;
|
||||
|
||||
if (iaddr < 0) {
|
||||
iaddr = -iaddr;
|
||||
inverse = 1;
|
||||
}
|
||||
pinMode(iaddr, OUTPUT);
|
||||
digitalWrite(iaddr, k = ((cmd == CMD_ON || cmd == CMD_XON) ? HIGH : LOW));
|
||||
|
||||
if (inverse)
|
||||
digitalWrite(iaddr, k = ((cmd == CMD_ON || cmd == CMD_XON) ? LOW : HIGH));
|
||||
else
|
||||
digitalWrite(iaddr, k = ((cmd == CMD_ON || cmd == CMD_XON) ? HIGH : LOW));
|
||||
debugSerial<<F("Pin:")<<iaddr<<F("=")<<k<<endl;
|
||||
break;
|
||||
case CH_THERMO:
|
||||
///thermoSet(name,cmd,Par1); all cativities done - update temp & cmd
|
||||
}
|
||||
case CH_THERMO:
|
||||
///thermoSet(name,cmd,Par1); all activities done - update temp & cmd
|
||||
break;
|
||||
}
|
||||
|
||||
case CH_PWM: {
|
||||
int k;
|
||||
short inverse = 0;
|
||||
|
||||
if (iaddr < 0) {
|
||||
iaddr = -iaddr;
|
||||
inverse = 1;
|
||||
@@ -959,13 +1055,15 @@ int Item::checkFM() {
|
||||
else aJson.addNumberToObject(out, "pwr", 0);
|
||||
|
||||
if (ftemp > FM_OVERHEAT_CELSIUS && set) {
|
||||
mqttClient.publish("/alarm/ovrht", itemArr->name);
|
||||
if (mqttClient.connected() && !ethernetIdleCount)
|
||||
mqttClient.publish("/alarm/ovrht", itemArr->name);
|
||||
Ctrl(CMD_OFF); //Shut down
|
||||
}
|
||||
} else
|
||||
debugSerial << F("Modbus polling error=") << _HEX(result);
|
||||
outch = aJson.print(out);
|
||||
mqttClient.publish(addrstr, outch);
|
||||
if (mqttClient.connected() && !ethernetIdleCount)
|
||||
mqttClient.publish(addrstr, outch);
|
||||
free(outch);
|
||||
aJson.deleteItem(out);
|
||||
modbusBusy = 0;
|
||||
@@ -1204,7 +1302,8 @@ int Item::SendStatus(short cmd, short n, int *Par, boolean deffered) {
|
||||
return -1;
|
||||
}
|
||||
debugSerial<<F("Pub: ")<<addrstr<<F("->")<<valstr<<endl;
|
||||
mqttClient.publish(addrstr, valstr,true);
|
||||
if (mqttClient.connected() && !ethernetIdleCount)
|
||||
mqttClient.publish(addrstr, valstr,true);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
+24
-6
@@ -19,6 +19,17 @@ e-mail anklimov@gmail.com
|
||||
*/
|
||||
#include "options.h"
|
||||
|
||||
#define S_SET 1
|
||||
#define S_TEMP 2
|
||||
#define S_MODE 3
|
||||
#define S_SETPOINT 4
|
||||
#define S_POWER 5
|
||||
#define S_VOL 6
|
||||
#define S_HEAT 7
|
||||
#define S_HSV 8
|
||||
#define S_RGB 9
|
||||
#define S_RPM 10
|
||||
|
||||
#define CH_DIMMER 0 //DMX 1 ch
|
||||
#define CH_RGBW 1 //DMX 4 ch
|
||||
#define CH_RGB 2 //DMX 3 ch
|
||||
@@ -32,6 +43,12 @@ e-mail anklimov@gmail.com
|
||||
#define CH_AC_HAIER 10 //AC Haier
|
||||
#define CH_WHITE 127//
|
||||
|
||||
#define CMD_NUM 0
|
||||
#define CMD_UNKNOWN -1
|
||||
#define CMD_JSON -2
|
||||
#define CMD_RGB -3
|
||||
#define CMD_HSV -4
|
||||
|
||||
#define CMD_ON 1
|
||||
#define CMD_OFF 2
|
||||
#define CMD_RESTORE 3 //on only if was turned off by CMD_HALT
|
||||
@@ -39,8 +56,8 @@ e-mail anklimov@gmail.com
|
||||
#define CMD_HALT 5 //just Off
|
||||
#define CMD_XON 6 //just on
|
||||
#define CMD_XOFF 7 //off only if was previously turned on by CMD_XON
|
||||
#define CMD_UP 8 //just on
|
||||
#define CMD_DN 9 //off only if was previously turned on by CMD_XON
|
||||
#define CMD_UP 8 //increase
|
||||
#define CMD_DN 9 //decrease
|
||||
#define CMD_SET 0xe
|
||||
#define CMD_MASK 0xf
|
||||
|
||||
@@ -68,6 +85,7 @@ e-mail anklimov@gmail.com
|
||||
#include "aJSON.h"
|
||||
|
||||
extern aJsonObject *items;
|
||||
extern short thermoSetCurTemp(char *name, float t);
|
||||
|
||||
int txt2cmd (char * payload);
|
||||
|
||||
@@ -105,7 +123,7 @@ class Item
|
||||
Item(char * name);
|
||||
Item(aJsonObject * obj);
|
||||
boolean isValid ();
|
||||
virtual int Ctrl(short cmd, short n=0, int * Parameters=NULL, boolean send=true, char * subItem=NULL);
|
||||
virtual int Ctrl(short cmd, short n=0, int * Parameters=NULL, boolean send=true, int subItem=0);
|
||||
virtual int Ctrl(char * payload, boolean send=true, char * subItem=NULL);
|
||||
|
||||
int getArg(short n=0);
|
||||
@@ -117,9 +135,9 @@ class Item
|
||||
//void setVal(uint8_t n, int par);
|
||||
void setVal(long int par);
|
||||
//void copyPar (aJsonObject *itemV);
|
||||
inline int On (){Ctrl(CMD_ON);};
|
||||
inline int Off(){Ctrl(CMD_OFF);};
|
||||
inline int Toggle(){Ctrl(CMD_TOGGLE);};
|
||||
inline int On (){return Ctrl(CMD_ON);};
|
||||
inline int Off(){return Ctrl(CMD_OFF);};
|
||||
inline int Toggle(){return Ctrl(CMD_TOGGLE);};
|
||||
int Poll();
|
||||
int SendStatus(short cmd, short n=0, int * Par=NULL, boolean deferred = false);
|
||||
|
||||
|
||||
+229
-120
@@ -79,26 +79,26 @@ EthernetClient ethClient;
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
WiFiClient ethClient;
|
||||
|
||||
#if not defined(WIFI_MANAGER_DISABLE)
|
||||
WiFiManager wifiManager;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
WiFiClient ethClient;
|
||||
NRFFlashStorage EEPROM;
|
||||
|
||||
#if not defined(WIFI_MANAGER_DISABLE)
|
||||
WiFiManager wifiManager;
|
||||
#endif
|
||||
|
||||
#ifdef ARDUINO_ARCH_STM32F1
|
||||
#include "HttpClient.h"
|
||||
//#include <EthernetClient.h>
|
||||
//#include "UIPEthernet.h"
|
||||
//#include "UIPUdp.h"
|
||||
//#include <SPI.h>
|
||||
#include <Ethernet_STM.h>
|
||||
|
||||
#include "Dns.h"
|
||||
//#include "utility/logging.h"
|
||||
#include <EEPROM.h>
|
||||
#endif
|
||||
|
||||
#ifdef ARDUINO_ARCH_STM32
|
||||
EthernetClient ethClient;
|
||||
NRFFlashStorage EEPROM;
|
||||
#endif
|
||||
|
||||
#ifdef NRF5
|
||||
@@ -117,6 +117,7 @@ lan_status lanStatus = INITIAL_STATE;
|
||||
|
||||
|
||||
const char configserver[] PROGMEM = CONFIG_SERVER;
|
||||
const char verval_P[] PROGMEM = QUOTE(PIO_SRC_REV);
|
||||
|
||||
|
||||
unsigned int UniqueID[5] = {0,0,0,0,0};
|
||||
@@ -140,15 +141,17 @@ aJsonObject *dmxArr = NULL;
|
||||
aJsonObject *udpSyslogArr = NULL;
|
||||
#endif
|
||||
|
||||
unsigned long nextPollingCheck = 0;
|
||||
unsigned long nextInputCheck = 0;
|
||||
unsigned long nextLanCheckTime = 0;
|
||||
unsigned long nextThermostatCheck = 0;
|
||||
uint32_t nextPollingCheck = 0;
|
||||
uint32_t nextInputCheck = 0;
|
||||
uint32_t nextLanCheckTime = 0;
|
||||
uint32_t nextThermostatCheck = 0;
|
||||
uint32_t nextSensorCheck =0;
|
||||
|
||||
aJsonObject *pollingItem = NULL;
|
||||
|
||||
bool owReady = false;
|
||||
bool configOk = false;
|
||||
int8_t ethernetIdleCount =0;
|
||||
|
||||
#ifdef _modbus
|
||||
ModbusMaster node;
|
||||
@@ -166,6 +169,28 @@ int mqttErrorRate;
|
||||
void watchdogSetup(void) {} //Do not remove - strong re-definition WDT Init for DUE
|
||||
#endif
|
||||
|
||||
void cleanConf()
|
||||
{
|
||||
if (!root) return;
|
||||
debugSerial<<F("Deleting conf. RAM was:")<<freeRam();
|
||||
aJson.deleteItem(root);
|
||||
root = NULL;
|
||||
inputs = NULL;
|
||||
items = NULL;
|
||||
topics = NULL;
|
||||
mqttArr = NULL;
|
||||
#ifdef _dmxout
|
||||
dmxArr = NULL;
|
||||
#endif
|
||||
#ifdef _owire
|
||||
owArr = NULL;
|
||||
#endif
|
||||
#ifndef MODBUS_DISABLE
|
||||
modbusArr = NULL;
|
||||
#endif
|
||||
debugSerial<<F(" is ")<<freeRam()<<endl;
|
||||
}
|
||||
|
||||
void mqttCallback(char *topic, byte *payload, unsigned int length) {
|
||||
debugSerial<<F("\n[")<<topic<<F("] ");
|
||||
if (!payload) return;
|
||||
@@ -246,7 +271,7 @@ else
|
||||
|
||||
|
||||
void printMACAddress() {
|
||||
debugSerial<<F("Configured MAC:");
|
||||
debugSerial<<F("MAC:");
|
||||
for (byte i = 0; i < 6; i++)
|
||||
#ifdef WITH_PRINTEX_LIB
|
||||
(i < 5) ?debugSerial<<hex <<(mac[i])<<F(":"):debugSerial<<hex<<(mac[i])<<endl;
|
||||
@@ -322,6 +347,14 @@ lan_status lanLoop() {
|
||||
|
||||
|
||||
{
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
if (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
wifiInitialized=false;
|
||||
lanStatus = INITIAL_STATE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__)
|
||||
wdt_dis();
|
||||
if (lanStatus > 0)
|
||||
@@ -385,6 +418,7 @@ void onMQTTConnect(){
|
||||
setTopic(topic,sizeof(topic),T_DEV);
|
||||
strncat_P(topic, name_P, sizeof(topic));
|
||||
strncpy_P(buf, nameval_P, sizeof(buf));
|
||||
strncat_P(buf,(verval_P),sizeof(buf));
|
||||
mqttClient.publish(topic,buf,true);
|
||||
|
||||
//strncpy_P(topic, outprefix, sizeof(topic));
|
||||
@@ -407,8 +441,8 @@ void onMQTTConnect(){
|
||||
aJsonObject * item = items->child;
|
||||
while (items && item)
|
||||
if (item->type == aJson_Array && aJson.getArraySize(item)>0) {
|
||||
strncat(buf,item->name,sizeof(buf));
|
||||
strncat(buf,",",sizeof(buf));
|
||||
/// strncat(buf,item->name,sizeof(buf));
|
||||
/// strncat(buf,",",sizeof(buf));
|
||||
|
||||
switch ( aJson.getArrayItem(item, I_TYPE)->valueint) {
|
||||
case CH_THERMO:
|
||||
@@ -460,7 +494,7 @@ void onMQTTConnect(){
|
||||
//strncpy_P(topic, outprefix, sizeof(topic));
|
||||
setTopic(topic,sizeof(topic),T_DEV);
|
||||
strncat_P(topic, nodes_P, sizeof(topic));
|
||||
mqttClient.publish(topic,buf,true);
|
||||
/// mqttClient.publish(topic,buf,true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -474,8 +508,11 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
||||
char *password = passwordBuf;
|
||||
int syslogPort = 514;
|
||||
char syslogDeviceHostname[16];
|
||||
if (mqttArr && (aJson.getArraySize(mqttArr))) deviceName = aJson.getArrayItem(mqttArr, 0)->valuestring;
|
||||
|
||||
if (mqttArr && (aJson.getArraySize(mqttArr)))
|
||||
{
|
||||
deviceName = aJson.getArrayItem(mqttArr, 0)->valuestring;
|
||||
debugSerial<<F("Device Name:")<<deviceName<<endl;
|
||||
}
|
||||
#ifdef SYSLOG_ENABLE
|
||||
//debugSerial<<"debugSerial:";
|
||||
delay(100);
|
||||
@@ -523,11 +560,11 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
||||
|
||||
|
||||
debugSerial<<F("\nAttempting MQTT connection to ")<<servername<<F(":")<<port<<F(" user:")<<user<<F(" ...");
|
||||
wdt_dis(); //potential unsafe for ethernetIdle(), but needed to avoid cyclic reboot if mosquitto out of order
|
||||
// wdt_dis(); //potential unsafe for ethernetIdle(), but needed to avoid cyclic reboot if mosquitto out of order
|
||||
if (mqttClient.connect(deviceName, user, password,willTopic,MQTTQOS1,true,willMessage)) {
|
||||
mqttErrorRate = 0;
|
||||
debugSerial<<F("connected as ")<<deviceName <<endl;
|
||||
wdt_en();
|
||||
// wdt_en();
|
||||
configOk = true;
|
||||
// ... Temporary subscribe to status topic
|
||||
char buf[MQTT_TOPIC_LENGTH];
|
||||
@@ -577,21 +614,44 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
||||
}
|
||||
|
||||
void onInitialStateInitLAN() {
|
||||
#if defined(ARDUINO_ARCH_ESP8266) and defined(WIFI_MANAGER_DISABLE)
|
||||
if(!wifiInitialized) {
|
||||
WiFi.mode(WIFI_STA);
|
||||
debugSerial<<F("WIFI AP/Password:")<<QUOTE(ESP_WIFI_AP)<<F("/")<<QUOTE(ESP_WIFI_PWD);
|
||||
wifi_set_macaddr(STATION_IF,mac);
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
#if defined(WIFI_MANAGER_DISABLE)
|
||||
if(WiFi.status() != WL_CONNECTED) {
|
||||
WiFi.mode(WIFI_STA); // ESP 32 - WiFi.disconnect(); instead
|
||||
debugSerial<<F("WIFI AP/Password:")<<QUOTE(ESP_WIFI_AP)<<F("/")<<QUOTE(ESP_WIFI_PWD)<<endl;
|
||||
|
||||
wifi_set_macaddr(STATION_IF,mac); //ESP32 to check
|
||||
|
||||
WiFi.begin(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD));
|
||||
int wifi_connection_wait = 10000;
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED && wifi_connection_wait > 0) {
|
||||
delay(500);
|
||||
wifi_connection_wait -= 500;
|
||||
debugSerial<<".";
|
||||
}
|
||||
wifiInitialized = true;
|
||||
}
|
||||
#else
|
||||
// Wifi Manager
|
||||
if (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
wifiManager.setTimeout(30);
|
||||
#if defined(ESP_WIFI_AP) and defined(ESP_WIFI_PWD)
|
||||
wifiInitialized = wifiManager.autoConnect(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD));
|
||||
#else
|
||||
wifiInitialized = wifiManager.autoConnect();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
/*
|
||||
#if defined(ARDUINO_ARCH_ESP32) and defined(WIFI_MANAGER_DISABLE)
|
||||
if(!wifiInitialized) {
|
||||
// WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
debugSerial<<F("WIFI AP/Password:")<<QUOTE(ESP_WIFI_AP)<<F("/")<<QUOTE(ESP_WIFI_PWD);
|
||||
debugSerial<<F("WIFI AP/Password:")<<QUOTE(ESP_WIFI_AP)<<F("/")<<QUOTE(ESP_WIFI_PWD)<<endl;
|
||||
WiFi.begin(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD));
|
||||
|
||||
int wifi_connection_wait = 10000;
|
||||
@@ -603,19 +663,20 @@ void onInitialStateInitLAN() {
|
||||
wifiInitialized = true;
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
debugSerial<<F("WiFi connected. IP address: ")<<WiFi.localIP();
|
||||
debugSerial<<F("WiFi connected. IP address: ")<<WiFi.localIP()<<endl;
|
||||
lanStatus = HAVE_IP_ADDRESS;//1;
|
||||
} else
|
||||
{
|
||||
debugSerial<<F("Problem with WiFi!");
|
||||
nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL/5;
|
||||
nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__)||defined(ARDUINO_ARCH_STM32F1)
|
||||
#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__)||defined(ARDUINO_ARCH_STM32)
|
||||
#ifdef W5500_CS_PIN
|
||||
Ethernet.w5500_cspin = W5500_CS_PIN;
|
||||
debugSerial<<F("Use W5500 pin: ");
|
||||
@@ -649,7 +710,7 @@ void onInitialStateInitLAN() {
|
||||
#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__)
|
||||
res = Ethernet.begin(mac, 12000);
|
||||
#endif
|
||||
#if defined(ARDUINO_ARCH_STM32F1)
|
||||
#if defined(ARDUINO_ARCH_STM32)
|
||||
res = Ethernet.begin(mac);
|
||||
#endif
|
||||
wdt_en();
|
||||
@@ -675,25 +736,6 @@ void onInitialStateInitLAN() {
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ARDUINO_ARCH_STM32F1
|
||||
void softRebootFunc() {
|
||||
nvic_sys_reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__)
|
||||
void (*softRebootFunc)(void) = 0;
|
||||
|
||||
void printCurentLanConfig();
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
void softRebootFunc(){
|
||||
debugSerial<<F("ESP.restart();");
|
||||
ESP.restart();
|
||||
}
|
||||
#endif
|
||||
|
||||
void resetHard() {
|
||||
#ifdef RESET_PIN
|
||||
@@ -719,7 +761,7 @@ void Changed(int i, DeviceAddress addr, float currentTemp) {
|
||||
|
||||
SetBytes(addr, 8, addrstr);
|
||||
addrstr[17] = 0;
|
||||
|
||||
if (!root) return;
|
||||
printFloatValueToStr(currentTemp,valstr);
|
||||
debugSerial<<endl<<F("T:")<<valstr<<F("<");
|
||||
aJsonObject *owObj = aJson.getObjectItem(owArr, addrstr);
|
||||
@@ -738,7 +780,8 @@ void Changed(int i, DeviceAddress addr, float currentTemp) {
|
||||
char valstr[50];
|
||||
sprintf(valstr, "{\"idx\":%s,\"svalue\":\"%.1f\"}", idx->valuestring, currentTemp);
|
||||
debugSerial << valstr;
|
||||
mqttClient.publish(owEmitString, valstr);
|
||||
if (mqttClient.connected() && !ethernetIdleCount)
|
||||
mqttClient.publish(owEmitString, valstr);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -746,7 +789,8 @@ void Changed(int i, DeviceAddress addr, float currentTemp) {
|
||||
//strcpy_P(addrstr, outprefix);
|
||||
setTopic(addrstr,sizeof(addrstr),T_OUT);
|
||||
strncat(addrstr, owEmitString, sizeof(addrstr));
|
||||
mqttClient.publish(addrstr, valstr);
|
||||
if (mqttClient.connected() && !ethernetIdleCount)
|
||||
mqttClient.publish(addrstr, valstr);
|
||||
}
|
||||
// And translate temp to internal items
|
||||
owItem = aJson.getObjectItem(owObj, "item")->valuestring;
|
||||
@@ -796,12 +840,11 @@ void cmdFunctionKill(int arg_cnt, char **args) {
|
||||
|
||||
void cmdFunctionReboot(int arg_cnt, char **args) {
|
||||
debugSerial<<F("Soft rebooting...");
|
||||
//// softRebootFunc();
|
||||
softRebootFunc();
|
||||
}
|
||||
|
||||
void applyConfig() {
|
||||
if (!root) return;
|
||||
|
||||
#ifdef _dmxin
|
||||
int itemsCount;
|
||||
dmxArr = aJson.getObjectItem(root, "dmxin");
|
||||
@@ -815,7 +858,7 @@ void applyConfig() {
|
||||
aJsonObject *dmxoutArr = aJson.getObjectItem(root, "dmx");
|
||||
if (dmxoutArr && aJson.getArraySize(dmxoutArr) >=1 ) {
|
||||
DMXoutSetup(maxChannels = aJson.getArrayItem(dmxoutArr, 1)->valueint);
|
||||
debugSerial<<F("DMX out started. Channels: ")<<maxChannels;
|
||||
debugSerial<<F("DMX out started. Channels: ")<<maxChannels<<endl;
|
||||
}
|
||||
#endif
|
||||
#ifdef _modbus
|
||||
@@ -851,7 +894,9 @@ void applyConfig() {
|
||||
if (item->type == aJson_Array && aJson.getArraySize(item)>1) {
|
||||
Item it(item);
|
||||
if (it.isValid()) {
|
||||
short inverse = 0;
|
||||
int pin=it.getArg();
|
||||
if (pin<0) {pin=-pin; inverse = 1;}
|
||||
int cmd = it.getCmd();
|
||||
switch (it.itemType) {
|
||||
case CH_THERMO:
|
||||
@@ -860,6 +905,9 @@ void applyConfig() {
|
||||
{
|
||||
int k;
|
||||
pinMode(pin, OUTPUT);
|
||||
if (inverse)
|
||||
digitalWrite(pin, k = ((cmd == CMD_ON) ? LOW : HIGH));
|
||||
else
|
||||
digitalWrite(pin, k = ((cmd == CMD_ON) ? HIGH : LOW));
|
||||
debugSerial<<F("Pin:")<<pin<<F("=")<<k<<F(",");
|
||||
}
|
||||
@@ -872,6 +920,8 @@ void applyConfig() {
|
||||
}
|
||||
inputs = aJson.getObjectItem(root, "in");
|
||||
mqttArr = aJson.getObjectItem(root, "mqtt");
|
||||
|
||||
inputSetup();
|
||||
#ifdef SYSLOG_ENABLE
|
||||
udpSyslogArr = aJson.getObjectItem(root, "syslog");
|
||||
#endif
|
||||
@@ -898,6 +948,7 @@ void printConfigSummary() {
|
||||
printBool(udpSyslogArr);
|
||||
#endif
|
||||
debugSerial << endl;
|
||||
debugSerial<<F("RAM=")<<freeRam()<<endl;
|
||||
}
|
||||
|
||||
void cmdFunctionLoad(int arg_cnt, char **args) {
|
||||
@@ -905,26 +956,27 @@ void cmdFunctionLoad(int arg_cnt, char **args) {
|
||||
// restoreState();
|
||||
}
|
||||
|
||||
|
||||
int loadConfigFromEEPROM()
|
||||
{
|
||||
char ch;
|
||||
debugSerial<<F("loading Config");
|
||||
debugSerial<<F("Loading Config from EEPROM")<<endl;
|
||||
|
||||
ch = EEPROM.read(EEPROM_offset);
|
||||
if (ch == '{') {
|
||||
aJsonEEPROMStream as = aJsonEEPROMStream(EEPROM_offset);
|
||||
aJson.deleteItem(root);
|
||||
cleanConf();
|
||||
root = aJson.parse(&as);
|
||||
if (!root) {
|
||||
debugSerial<<F("\nload failed");
|
||||
debugSerial<<F("load failed")<<endl;
|
||||
return 0;
|
||||
}
|
||||
debugSerial<<F("\nLoaded\n");
|
||||
debugSerial<<F("Loaded")<<endl;
|
||||
applyConfig();
|
||||
ethClient.stop(); //Refresh MQTT connect to get retained info
|
||||
return 1;
|
||||
} else {
|
||||
debugSerial<<F("\nNo stored config\n");
|
||||
debugSerial<<F("No stored config")<<endl;
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
@@ -949,6 +1001,7 @@ int mqttConfigRequest(int arg_cnt, char **args)
|
||||
strncat(buf, "/req/conf", 25);
|
||||
debugSerial<<buf;
|
||||
mqttClient.publish(buf, "1");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -957,7 +1010,7 @@ int mqttConfigResp(char *as) {
|
||||
root = aJson.parse(as);
|
||||
|
||||
if (!root) {
|
||||
debugSerial<<F("\nload failed");
|
||||
debugSerial<<F("\nload failed\n");
|
||||
return 0;
|
||||
}
|
||||
debugSerial<<F("\nLoaded");
|
||||
@@ -1003,6 +1056,7 @@ void cmdFunctionIp(int arg_cnt, char **args)
|
||||
|
||||
case 1: //dynamic IP
|
||||
saveFlash(OFFSET_IP,ip0);
|
||||
debugSerial<<F("Set dynamic IP\n");
|
||||
/*
|
||||
IPAddress current_ip = Ethernet.localIP();
|
||||
IPAddress current_mask = Ethernet.subnetMask();
|
||||
@@ -1107,10 +1161,8 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
|
||||
#if defined(ARDUINO_ARCH_AVR)
|
||||
FILE *configStream;
|
||||
//byte hserver[] = { 192,168,88,2 };
|
||||
wdt_dis();
|
||||
HTTPClient hclient(configServer, 80);
|
||||
HTTPClient hclientPrint(configServer, 80);
|
||||
// FILE is the return STREAM type of the HTTPClient
|
||||
configStream = hclient.getURI(URI);
|
||||
responseStatusCode = hclient.getLastReturnCode();
|
||||
@@ -1123,10 +1175,9 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
char c;
|
||||
aJsonFileStream as = aJsonFileStream(configStream);
|
||||
noInterrupts();
|
||||
aJson.deleteItem(root);
|
||||
cleanConf();
|
||||
root = aJson.parse(&as);
|
||||
interrupts();
|
||||
// debugSerial<<F("Parsed."));
|
||||
hclient.closeStream(configStream); // this is very important -- be sure to close the STREAM
|
||||
|
||||
if (!root) {
|
||||
@@ -1134,12 +1185,9 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
nextLanCheckTime = millis() + 15000;
|
||||
return READ_RE_CONFIG;//-11;
|
||||
} else {
|
||||
// char *outstr = aJson.print(root);
|
||||
// debugSerial<<outstr);
|
||||
// free(outstr);
|
||||
debugSerial<<F("Applying.\n");
|
||||
applyConfig();
|
||||
|
||||
debugSerial<<F("Done.\n");
|
||||
|
||||
}
|
||||
|
||||
@@ -1157,7 +1205,7 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
return READ_RE_CONFIG;//-11;
|
||||
}
|
||||
#endif
|
||||
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_ESP32)
|
||||
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_ESP32)
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
WiFiClient configEthClient;
|
||||
#else
|
||||
@@ -1170,10 +1218,11 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
wdt_res();
|
||||
//debugSerial<<"making GET request");get
|
||||
htclient.beginRequest();
|
||||
htclient.get(URI);
|
||||
responseStatusCode = htclient.get(URI);
|
||||
htclient.endRequest();
|
||||
|
||||
|
||||
if (responseStatusCode == HTTP_SUCCESS)
|
||||
{
|
||||
// read the status code and body of the response
|
||||
responseStatusCode = htclient.responseStatusCode();
|
||||
response = htclient.responseBody();
|
||||
@@ -1184,7 +1233,7 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
//debugSerial<<"GET Response: ");
|
||||
|
||||
if (responseStatusCode == 200) {
|
||||
aJson.deleteItem(root);
|
||||
cleanConf();
|
||||
root = aJson.parse((char *) response.c_str());
|
||||
|
||||
if (!root) {
|
||||
@@ -1193,9 +1242,14 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
} else {
|
||||
debugSerial<<response;
|
||||
applyConfig();
|
||||
debugSerial<<F("Done.\n");
|
||||
}
|
||||
} else {
|
||||
debugSerial<<F("Config retrieving failed\n");
|
||||
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
||||
}
|
||||
} else {
|
||||
debugSerial<<F("Config retrieving failed\n");
|
||||
debugSerial<<F("Connect failed\n");
|
||||
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
||||
}
|
||||
#endif
|
||||
@@ -1211,7 +1265,7 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
if (httpResponseCode == HTTP_CODE_OK) {
|
||||
String response = httpClient.getString();
|
||||
debugSerial<<response;
|
||||
aJson.deleteItem(root);
|
||||
cleanConf();
|
||||
root = aJson.parse((char *) response.c_str());
|
||||
if (!root) {
|
||||
debugSerial<<F("Config parsing failed\n");
|
||||
@@ -1219,7 +1273,11 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
} else {
|
||||
debugSerial<<F("Config OK, Applying\n");
|
||||
applyConfig();
|
||||
debugSerial<<F("Done.\n");
|
||||
}
|
||||
} else {
|
||||
debugSerial<<F("Config retrieving failed\n");
|
||||
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
||||
}
|
||||
} else {
|
||||
debugSerial.printf("[HTTP] GET... failed, error: %s\n", httpClient.errorToString(httpResponseCode).c_str());
|
||||
@@ -1256,10 +1314,16 @@ void setup_main() {
|
||||
setupCmdArduino();
|
||||
printFirmwareVersionAndBuildOptions();
|
||||
|
||||
// scan_i2c_bus();
|
||||
|
||||
#ifdef SD_CARD_INSERTED
|
||||
sd_card_w5100_setup();
|
||||
#endif
|
||||
setupMacAddress();
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
EEPROM.begin(ESP_EEPROM_SIZE);
|
||||
#endif
|
||||
loadConfigFromEEPROM();
|
||||
|
||||
#ifdef _modbus
|
||||
@@ -1281,7 +1345,7 @@ void setup_main() {
|
||||
//owReady = 0;
|
||||
|
||||
#ifdef _owire
|
||||
if (net) net->idle(&owIdle);
|
||||
if (oneWire) oneWire->idle(&owIdle);
|
||||
#endif
|
||||
|
||||
mqttClient.setCallback(mqttCallback);
|
||||
@@ -1290,13 +1354,16 @@ void setup_main() {
|
||||
ArtnetSetup();
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266) and not defined(WIFI_MANAGER_DISABLE)
|
||||
WiFiManager wifiManager;
|
||||
#if (defined(ARDUINO_ARCH_ESP8266) or defined(ARDUINO_ARCH_ESP32)) and not defined(WIFI_MANAGER_DISABLE)
|
||||
// WiFiManager wifiManager;
|
||||
wifiManager.setTimeout(180);
|
||||
|
||||
#if defined(ESP_WIFI_AP) and defined(ESP_WIFI_PWD)
|
||||
wifiManager.autoConnect(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD));
|
||||
wifiInitialized = wifiManager.autoConnect(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD));
|
||||
#else
|
||||
wifiManager.autoConnect();
|
||||
wifiInitialized = wifiManager.autoConnect();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
delay(LAN_INIT_DELAY);//for LAN-shield initializing
|
||||
@@ -1378,6 +1445,7 @@ debugSerial<<endl;
|
||||
|
||||
|
||||
// WDT_Disable( WDT ) ;
|
||||
#if defined(__SAM3X8E__)
|
||||
|
||||
Serial.println(F("Reading 128 bits unique identifier") ) ;
|
||||
ReadUniqueID( UniqueID ) ;
|
||||
@@ -1386,7 +1454,7 @@ debugSerial<<endl;
|
||||
for (byte b = 0 ; b < 4 ; b++)
|
||||
Serial.print ((unsigned int) UniqueID [b], HEX) ;
|
||||
Serial.println () ;
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@@ -1396,51 +1464,57 @@ void publishStat(){
|
||||
long fr = freeRam();
|
||||
char topic[64];
|
||||
char intbuf[16];
|
||||
long ut = millis()/1000;
|
||||
uint32_t ut = millis()/1000UL;
|
||||
if (!mqttClient.connected()) return;
|
||||
|
||||
// debugSerial<<F("\nfree RAM: ")<<fr;
|
||||
setTopic(topic,sizeof(topic),T_DEV);
|
||||
strncat_P(topic, stats_P, sizeof(topic));
|
||||
strncat(topic, "/", sizeof(topic));
|
||||
strncat_P(topic, freeheap_P, sizeof(topic));
|
||||
|
||||
mqttClient.publish(topic,itoa(fr,intbuf,10),true);
|
||||
printUlongValueToStr(intbuf, fr);
|
||||
mqttClient.publish(topic,intbuf,true);
|
||||
|
||||
setTopic(topic,sizeof(topic),T_DEV);
|
||||
strncat_P(topic, stats_P, sizeof(topic));
|
||||
strncat(topic, "/", sizeof(topic));
|
||||
strncat_P(topic, uptime_P, sizeof(topic));
|
||||
|
||||
mqttClient.publish(topic,itoa(ut,intbuf,10),true);
|
||||
printUlongValueToStr(intbuf, ut);
|
||||
mqttClient.publish(topic,intbuf,true);
|
||||
}
|
||||
|
||||
void setupMacAddress() {
|
||||
#if defined(__SAM3X8E__)
|
||||
byte firmwareMacAddress[6];
|
||||
firmwareMacAddress[0]=0xDE;
|
||||
firmwareMacAddress[1]=0xAD;
|
||||
for (byte b = 0 ; b < 4 ; b++)
|
||||
firmwareMacAddress[b+2]=UniqueID [b] ;
|
||||
#else
|
||||
#ifdef DEFAULT_FIRMWARE_MAC
|
||||
byte firmwareMacAddress[6] = DEFAULT_FIRMWARE_MAC;//comma(,) separated hex-array, hard-coded
|
||||
#endif
|
||||
#endif
|
||||
#ifdef CUSTOM_FIRMWARE_MAC
|
||||
byte firmwareMacAddress[6];
|
||||
const char *macStr = QUOTE(CUSTOM_FIRMWARE_MAC);//colon(:) separated from build options
|
||||
parseBytes(macStr, ':', firmwareMacAddress, 6, 16);
|
||||
#endif
|
||||
|
||||
bool isMacValid = false;
|
||||
for (short i = 0; i < 6; i++) {
|
||||
//Check MAC, stored in NVRAM
|
||||
bool isMacValid = false;
|
||||
for (short i = 0; i < 6; i++) {
|
||||
mac[i] = EEPROM.read(i);
|
||||
if (mac[i] != 0 && mac[i] != 0xff) isMacValid = true;
|
||||
}
|
||||
if (!isMacValid) {
|
||||
debugSerial<<F("No MAC configured: set firmware's MAC\n");
|
||||
memcpy(mac, firmwareMacAddress, 6);
|
||||
if (!isMacValid) {
|
||||
debugSerial<<F("No MAC configured: set firmware's MAC\n");
|
||||
|
||||
#if defined (CUSTOM_FIRMWARE_MAC) //Forced MAC from compiler's directive
|
||||
const char *macStr = QUOTE(CUSTOM_FIRMWARE_MAC);//colon(:) separated from build options
|
||||
parseBytes(macStr, ':', mac, 6, 16);
|
||||
|
||||
#elif defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
||||
//Using original MPU MAC
|
||||
WiFi.begin();
|
||||
WiFi.macAddress(mac);
|
||||
|
||||
#elif defined(__SAM3X8E__)
|
||||
//Lets make MAC from MPU serial#
|
||||
mac[0]=0xDE;
|
||||
//firmwareMacAddress[1]=0xAD;
|
||||
for (byte b = 0 ; b < 5 ; b++)
|
||||
mac[b+1]=UniqueID [b] ;
|
||||
|
||||
#elif defined DEFAULT_FIRMWARE_MAC
|
||||
uint8_t defaultMac[6] = DEFAULT_FIRMWARE_MAC;//comma(,) separated hex-array, hard-coded
|
||||
memcpy(mac,defaultMac,6);
|
||||
#endif
|
||||
}
|
||||
|
||||
printMACAddress();
|
||||
}
|
||||
|
||||
@@ -1521,8 +1595,10 @@ void owIdle(void) {
|
||||
#endif
|
||||
}
|
||||
void ethernetIdle(void){
|
||||
ethernetIdleCount++;
|
||||
wdt_res();
|
||||
inputLoop();
|
||||
ethernetIdleCount--;
|
||||
};
|
||||
|
||||
void modbusIdle(void) {
|
||||
@@ -1547,17 +1623,45 @@ void modbusIdle(void) {
|
||||
|
||||
void inputLoop(void) {
|
||||
if (!inputs) return;
|
||||
|
||||
|
||||
if (millis() > nextInputCheck) {
|
||||
aJsonObject *input = inputs->child;
|
||||
while (input) {
|
||||
if ((input->type == aJson_Object)) {
|
||||
Input in(input);
|
||||
in.poll();
|
||||
in.poll(CHECK_INPUT);
|
||||
}
|
||||
input = input->next;
|
||||
}
|
||||
nextInputCheck = millis() + INTERVAL_CHECK_INPUT;
|
||||
}
|
||||
|
||||
if (millis() > nextSensorCheck) {
|
||||
aJsonObject *input = inputs->child;
|
||||
while (input) {
|
||||
if ((input->type == aJson_Object)) {
|
||||
Input in(input);
|
||||
in.poll(CHECK_SENSOR);
|
||||
}
|
||||
input = input->next;
|
||||
}
|
||||
nextSensorCheck = millis() + INTERVAL_CHECK_SENSOR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void inputSetup(void) {
|
||||
if (!inputs) return;
|
||||
|
||||
aJsonObject *input = inputs->child;
|
||||
while (input) {
|
||||
if ((input->type == aJson_Object)) {
|
||||
Input in(input);
|
||||
in.setup();
|
||||
}
|
||||
input = input->next;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef MODBUS_DISABLE
|
||||
@@ -1595,6 +1699,7 @@ bool thermoDisabledOrDisconnected(aJsonObject *thermoExtensionArray, int thermoS
|
||||
void thermoLoop(void) {
|
||||
if (millis() < nextThermostatCheck)
|
||||
return;
|
||||
if (!items) return;
|
||||
bool thermostatCheckPrinted = false;
|
||||
for (aJsonObject *thermoItem = items->child; thermoItem; thermoItem = thermoItem->next) {
|
||||
if (isThermostatWithMinArraySize(thermoItem, 5)) {
|
||||
@@ -1618,17 +1723,19 @@ void thermoLoop(void) {
|
||||
|
||||
debugSerial << endl << thermoItem->name << F(" Set:") << thermoSetting << F(" Cur:") << curTemp
|
||||
<< F(" cmd:") << thermoStateCommand;
|
||||
pinMode(thermoPin, OUTPUT);
|
||||
if (thermoPin<0) pinMode(-thermoPin, OUTPUT); else pinMode(thermoPin, OUTPUT);
|
||||
if (thermoDisabledOrDisconnected(thermoExtensionArray, thermoStateCommand)) {
|
||||
digitalWrite(thermoPin, LOW);
|
||||
if (thermoPin<0) digitalWrite(-thermoPin, LOW); digitalWrite(thermoPin, LOW);
|
||||
// Caution - for water heaters (negative pin#) if some comes wrong (or no connection with termometers output is LOW - valve OPEN)
|
||||
// OFF - also VALVE is OPEN (no teat control)
|
||||
debugSerial<<F(" OFF");
|
||||
} else {
|
||||
if (curTemp < thermoSetting - THERMO_GIST_CELSIUS) {
|
||||
digitalWrite(thermoPin, HIGH);
|
||||
if (thermoPin<0) digitalWrite(-thermoPin, LOW); digitalWrite(thermoPin, HIGH);
|
||||
debugSerial<<F(" ON");
|
||||
} //too cold
|
||||
else if (curTemp >= thermoSetting) {
|
||||
digitalWrite(thermoPin, LOW);
|
||||
if (thermoPin<0) digitalWrite(-thermoPin, HIGH); digitalWrite(thermoPin, LOW);
|
||||
debugSerial<<F(" OFF");
|
||||
} //Reached settings
|
||||
else debugSerial<<F(" -target zone-"); // Nothing to do
|
||||
@@ -1641,15 +1748,17 @@ void thermoLoop(void) {
|
||||
nextThermostatCheck = millis() + THERMOSTAT_CHECK_PERIOD;
|
||||
publishStat();
|
||||
#ifndef DISABLE_FREERAM_PRINT
|
||||
(thermostatCheckPrinted) ? debugSerial<<F("\nfree:")<<freeRam()<<" " : debugSerial<<F(" ")<<freeRam()<<F(" ");
|
||||
(thermostatCheckPrinted) ? debugSerial<<F("\nRAM=")<<freeRam()<<" " : debugSerial<<F(" ")<<freeRam()<<F(" ");
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
short thermoSetCurTemp(char *name, float t) {
|
||||
if (!name || !strlen(name)) return 0;
|
||||
if (items) {
|
||||
aJsonObject *thermoItem = aJson.getObjectItem(items, name);
|
||||
if (!thermoItem) return 0;
|
||||
if (isThermostatWithMinArraySize(thermoItem, 4)) {
|
||||
aJsonObject *extArray = NULL;
|
||||
|
||||
@@ -1670,5 +1779,5 @@ short thermoSetCurTemp(char *name, float t) {
|
||||
att->valueint = (int) T_ATTEMPTS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;}
|
||||
return 0;}
|
||||
|
||||
+17
-7
@@ -16,13 +16,14 @@
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#include <FS.h> //this needs to be first, or it all crashes and burns...
|
||||
#include <EEPROM.h>
|
||||
#include <ESP_EEPROM.h>
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <WiFiManager.h>
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <user_interface.h>
|
||||
#define Ethernet WiFi
|
||||
#endif
|
||||
|
||||
#if defined ARDUINO_ARCH_ESP32
|
||||
@@ -44,14 +45,15 @@
|
||||
#include <NRFFlashStorage.h>
|
||||
#endif
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
#define wdt_res() watchdogReset()
|
||||
#define wdt_en()
|
||||
#define wdt_dis()
|
||||
#ifdef ARDUINO_ARCH_STM32
|
||||
#include "HttpClient.h"
|
||||
#include "UIPEthernet.h"
|
||||
#include <NRFFlashStorage.h>
|
||||
//#include <EEPROM.h>
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_STM32F1)
|
||||
#define wdt_res()
|
||||
#if defined(__SAM3X8E__)
|
||||
#define wdt_res() watchdogReset()
|
||||
#define wdt_en()
|
||||
#define wdt_dis()
|
||||
#endif
|
||||
@@ -78,6 +80,12 @@
|
||||
#define wdt_dis()
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_STM32)
|
||||
#define wdt_res()
|
||||
#define wdt_en()
|
||||
#define wdt_dis()
|
||||
#endif
|
||||
|
||||
//#if defined(ESP8266)
|
||||
//#define wdt_res()
|
||||
//#define wdt_en()
|
||||
@@ -224,6 +232,8 @@ void modbusIdle(void);
|
||||
|
||||
void inputLoop(void);
|
||||
|
||||
void inputSetup(void);
|
||||
|
||||
void pollingLoop(void);
|
||||
|
||||
void thermoLoop(void);
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
#include "modules/in_ccs811_hdc1080.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
#ifndef CSSHDC_DISABLE
|
||||
|
||||
CCS811 ccs811(CCS811_ADDR);
|
||||
ClosedCube_HDC1080 hdc1080;
|
||||
long ccs811Baseline;
|
||||
|
||||
int in_ccs811::Setup(int addr)
|
||||
{
|
||||
#ifdef WAK_PIN
|
||||
pinMode(WAK_PIN,OUTPUT);
|
||||
digitalWrite(WAK_PIN,LOW);
|
||||
#endif
|
||||
|
||||
Serial.println("CCS811 Init");
|
||||
|
||||
Wire.begin(); //Inialize I2C Harware
|
||||
|
||||
//It is recommended to check return status on .begin(), but it is not
|
||||
//required.
|
||||
CCS811Core::status returnCode = ccs811.begin();
|
||||
if (returnCode != CCS811Core::SENSOR_SUCCESS)
|
||||
{
|
||||
Serial.println("CCS811 Init error");
|
||||
printDriverError(returnCode);
|
||||
return 0;
|
||||
}
|
||||
ccs811.setBaseline(62000);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int in_hdc1080::Setup(int addr)
|
||||
{
|
||||
Serial.println("HDC1080 Init ");
|
||||
Wire.begin(); //Inialize I2C Harware
|
||||
// Default settings:
|
||||
// - Heater off
|
||||
// - 14 bit Temperature and Humidity Measurement Resolutions
|
||||
hdc1080.begin(0x40);
|
||||
Serial.print("Manufacturer ID=0x");
|
||||
Serial.println(hdc1080.readManufacturerId(), HEX); // 0x5449 ID of Texas Instruments
|
||||
Serial.print("Device ID=0x");
|
||||
Serial.println(hdc1080.readDeviceId(), HEX); // 0x1050 ID of the device
|
||||
printSerialNumber();
|
||||
return 1;
|
||||
}
|
||||
|
||||
void i2cReset(){
|
||||
Wire.endTransmission(true);
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
SCL_LOW();
|
||||
delay(300);
|
||||
SCL_HIGH();
|
||||
#endif
|
||||
}
|
||||
|
||||
int in_hdc1080::Poll()
|
||||
{
|
||||
float h,t;
|
||||
int reg;
|
||||
|
||||
// #ifdef WAK_PIN
|
||||
// digitalWrite(WAK_PIN,LOW);
|
||||
// #endif
|
||||
|
||||
|
||||
Serial.print("T=");
|
||||
Serial.print(t=hdc1080.readTemperature());
|
||||
Serial.print("C, RH=");
|
||||
Serial.print(h=hdc1080.readHumidity());
|
||||
Serial.print("% Status=");
|
||||
publish(t,"/T");
|
||||
publish(h,"/H");
|
||||
Serial.println(reg=hdc1080.readRegister().rawData,HEX);
|
||||
ccs811.setEnvironmentalData(h,t);
|
||||
|
||||
if (reg==0xff) //ESP I2C glitch
|
||||
{
|
||||
Serial.println("I2C Reset");
|
||||
i2cReset();
|
||||
}
|
||||
|
||||
delay(100);
|
||||
//#ifdef WAK_PIN
|
||||
// digitalWrite(WAK_PIN,HIGH);
|
||||
//#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
int in_ccs811::Poll()
|
||||
{
|
||||
#ifdef WAK_PIN
|
||||
digitalWrite(WAK_PIN,LOW);
|
||||
#endif
|
||||
//Check to see if data is ready with .dataAvailable()
|
||||
if (ccs811.dataAvailable())
|
||||
{
|
||||
//If so, have the sensor read and calculate the results.
|
||||
//Get them later
|
||||
CCS811Core::status returnCode = ccs811.readAlgorithmResults();
|
||||
printDriverError(returnCode);
|
||||
float co2,tvoc;
|
||||
Serial.print(" CO2[");
|
||||
//Returns calculated CO2 reading
|
||||
Serial.print(co2 = ccs811.getCO2());
|
||||
Serial.print("] tVOC[");
|
||||
//Returns calculated TVOC reading
|
||||
|
||||
Serial.print(tvoc = ccs811.getTVOC());
|
||||
Serial.print("] baseline[");
|
||||
Serial.print(ccs811Baseline = ccs811.getBaseline());
|
||||
|
||||
publish(co2,"/CO2");
|
||||
publish(tvoc,"/TVOC");
|
||||
publish(ccs811Baseline,"/base");
|
||||
|
||||
Serial.print("] millis[");
|
||||
//Simply the time since program start
|
||||
Serial.print(millis());
|
||||
Serial.print("]");
|
||||
Serial.println();
|
||||
printSensorError();
|
||||
|
||||
#ifdef WAK_PIN
|
||||
digitalWrite(WAK_PIN,HIGH); //Relax some time
|
||||
#endif
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void in_hdc1080::printSerialNumber() {
|
||||
Serial.print("Device Serial Number=");
|
||||
HDC1080_SerialNumber sernum = hdc1080.readSerialNumber();
|
||||
char format[12];
|
||||
sprintf(format, "%02X-%04X-%04X", sernum.serialFirst, sernum.serialMid, sernum.serialLast);
|
||||
Serial.println(format);
|
||||
}
|
||||
|
||||
//printDriverError decodes the CCS811Core::status type and prints the
|
||||
//type of error to the serial terminal.
|
||||
//
|
||||
//Save the return value of any function of type CCS811Core::status, then pass
|
||||
//to this function to see what the output was.
|
||||
void in_ccs811::printDriverError( CCS811Core::status errorCode )
|
||||
{
|
||||
switch ( errorCode )
|
||||
{
|
||||
case CCS811Core::SENSOR_SUCCESS:
|
||||
Serial.print("SUCCESS");
|
||||
break;
|
||||
case CCS811Core::SENSOR_ID_ERROR:
|
||||
Serial.print("ID_ERROR");
|
||||
break;
|
||||
case CCS811Core::SENSOR_I2C_ERROR:
|
||||
Serial.print("I2C_ERROR");
|
||||
break;
|
||||
case CCS811Core::SENSOR_INTERNAL_ERROR:
|
||||
Serial.print("INTERNAL_ERROR");
|
||||
break;
|
||||
case CCS811Core::SENSOR_GENERIC_ERROR:
|
||||
Serial.print("GENERIC_ERROR");
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unspecified error.");
|
||||
}
|
||||
}
|
||||
|
||||
//printSensorError gets, clears, then prints the errors
|
||||
//saved within the error register.
|
||||
void in_ccs811::printSensorError()
|
||||
{
|
||||
uint8_t error = ccs811.getErrorRegister();
|
||||
|
||||
if ( error == 0xFF ) //comm error
|
||||
{
|
||||
Serial.println("Failed to get ERROR_ID register.");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Serial.print("");
|
||||
if (error & 1 << 5) Serial.print("Error: HeaterSupply");
|
||||
if (error & 1 << 4) Serial.print("Error: HeaterFault");
|
||||
if (error & 1 << 3) Serial.print("Error: MaxResistance");
|
||||
if (error & 1 << 2) Serial.print("Error: MeasModeInvalid");
|
||||
if (error & 1 << 1) Serial.print("Error: ReadRegInvalid");
|
||||
if (error & 1 << 0) Serial.print("Error: MsgInvalid");
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,50 @@
|
||||
|
||||
#pragma once
|
||||
#ifndef CSSHDC_DISABLE
|
||||
#include <inputs.h>
|
||||
#include <abstractin.h>
|
||||
#include <Wire.h>
|
||||
#include "ClosedCube_HDC1080.h"
|
||||
#include "SparkFunCCS811.h" //Click here to get the library: http://librarymanager/All#SparkFun_CCS811
|
||||
|
||||
//#define CCS811_ADDR 0x5B //Default I2C Address
|
||||
#define CCS811_ADDR 0x5A //Alternate I2C Address
|
||||
|
||||
#if defined (ARDUINO_ARCH_ESP8266)
|
||||
#define twi_scl D1
|
||||
#define WAK_PIN D3
|
||||
|
||||
#define SCL_LOW() (GPES = (1 << twi_scl))
|
||||
#define SCL_HIGH() (GPEC = (1 << twi_scl))
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_AVR)
|
||||
#define WAK_PIN 3 // for LightHub UEXT SCS Pin
|
||||
#endif
|
||||
|
||||
|
||||
class Input;
|
||||
class in_ccs811 : public abstractIn {
|
||||
public:
|
||||
//CCS811 ccs811(CCS811_ADDR);
|
||||
//uint16_t ccs811Baseline;
|
||||
in_ccs811(Input * _in):abstractIn(_in){};
|
||||
int Setup(int addr) override;
|
||||
int Poll() override;
|
||||
|
||||
protected:
|
||||
void printDriverError( CCS811Core::status errorCode );
|
||||
void printSensorError();
|
||||
};
|
||||
|
||||
class in_hdc1080 : public abstractIn {
|
||||
public:
|
||||
//ClosedCube_HDC1080 hdc1080;
|
||||
in_hdc1080(Input * _in):abstractIn(_in){};
|
||||
int Setup(int addr) override;
|
||||
int Poll() override;
|
||||
|
||||
protected:
|
||||
void printSerialNumber();
|
||||
};
|
||||
#endif
|
||||
+16
-3
@@ -4,6 +4,7 @@
|
||||
#endif
|
||||
|
||||
#define TXEnablePin 13
|
||||
#define ESP_EEPROM_SIZE 2048
|
||||
|
||||
#ifndef AVR_DMXOUT_PIN
|
||||
#define AVR_DMXOUT_PIN 3
|
||||
@@ -18,7 +19,7 @@
|
||||
#define FM_OVERHEAT_CELSIUS 40.
|
||||
|
||||
#define MIN_VOLUME 10
|
||||
#define INIT_VOLUME 30
|
||||
#define INIT_VOLUME 50
|
||||
|
||||
#define OFFSET_MAC 0
|
||||
#define OFFSET_IP OFFSET_MAC+6
|
||||
@@ -32,6 +33,11 @@
|
||||
#ifndef INTERVAL_CHECK_INPUT
|
||||
#define INTERVAL_CHECK_INPUT 50
|
||||
#endif
|
||||
|
||||
#ifndef INTERVAL_CHECK_SENSOR
|
||||
#define INTERVAL_CHECK_SENSOR 5000
|
||||
#endif
|
||||
|
||||
#define INTERVAL_CHECK_MODBUS 2000
|
||||
#define INTERVAL_POLLING 100
|
||||
#define THERMOSTAT_CHECK_PERIOD 5000
|
||||
@@ -66,7 +72,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef HOMETOPIC
|
||||
#define HOMETOPIC "/myhome"
|
||||
#define HOMETOPIC "myhome"
|
||||
#endif
|
||||
/*
|
||||
#ifndef OUTTOPIC
|
||||
@@ -98,7 +104,7 @@
|
||||
#endif
|
||||
|
||||
#define MQTT_SUBJECT_LENGTH 20
|
||||
#define MQTT_TOPIC_LENGTH 20
|
||||
#define MQTT_TOPIC_LENGTH 64
|
||||
|
||||
#ifndef DMX_DISABLE
|
||||
#define _dmxin
|
||||
@@ -138,6 +144,13 @@
|
||||
#define dmxin DmxDue1
|
||||
#endif
|
||||
|
||||
#if defined(NRF5)
|
||||
//#define modbusSerial Serial1
|
||||
#undef _dmxin
|
||||
#undef _dmxout
|
||||
#undef _modbus
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#undef _dmxin
|
||||
#undef _modbus
|
||||
|
||||
+15
-15
@@ -26,7 +26,7 @@ e-mail anklimov@gmail.com
|
||||
#include "options.h"
|
||||
|
||||
|
||||
OneWire *net = NULL;
|
||||
OneWire *oneWire = NULL;
|
||||
|
||||
DeviceAddress *term = NULL;
|
||||
|
||||
@@ -46,12 +46,12 @@ int owUpdate() {
|
||||
|
||||
|
||||
Serial.println(F("Searching"));
|
||||
if (net) net->reset_search();
|
||||
if (oneWire) oneWire->reset_search();
|
||||
for (short i = 0; i < t_count; i++) wstat[i] &= ~SW_FIND; //absent
|
||||
|
||||
while (net && net->wireSearch(term[t_count]) > 0 && (t_count < t_max) && finish > millis()) {
|
||||
while (oneWire && oneWire->wireSearch(term[t_count]) > 0 && (t_count < t_max) && finish > millis()) {
|
||||
short ifind = -1;
|
||||
if (net->crc8(term[t_count], 7) == term[t_count][7]) {
|
||||
if (oneWire->crc8(term[t_count], 7) == term[t_count][7]) {
|
||||
for (short i = 0; i < t_count; i++)
|
||||
if (!memcmp(term[i], term[t_count], 8)) {
|
||||
ifind = i;
|
||||
@@ -68,7 +68,7 @@ int owUpdate() {
|
||||
debugSerial.println();
|
||||
if (term[t_count][0] == 0x28) {
|
||||
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
||||
net->setStrongPullup();
|
||||
oneWire->setStrongPullup();
|
||||
// sensors.requestTemperaturesByAddress(term[t_count]);
|
||||
}
|
||||
t_count++;
|
||||
@@ -84,20 +84,20 @@ int owUpdate() {
|
||||
int owSetup(owChangedType owCh) {
|
||||
#ifndef OWIRE_DISABLE
|
||||
//// todo - move memory allocation to here
|
||||
if (net) return true; // Already initialized
|
||||
if (oneWire) return true; // Already initialized
|
||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||
debugSerial<<F("DS2482_100_I2C_TO_1W_BRIDGE init");
|
||||
net = new OneWire;
|
||||
debugSerial<<F("DS2482_100_I2C_TO_1W_BRIDGE init")<<endl;
|
||||
oneWire = new OneWire;
|
||||
#else
|
||||
debugSerial.print(F("One wire setup on PIN:"));
|
||||
debugSerial.println(QUOTE(USE_1W_PIN));
|
||||
net = new OneWire (USE_1W_PIN);
|
||||
oneWire = new OneWire (USE_1W_PIN);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// Pass our oneWire reference to Dallas Temperature.
|
||||
sensors = new DallasTemperature(net);
|
||||
sensors = new DallasTemperature(oneWire);
|
||||
|
||||
term = new DeviceAddress[t_max];
|
||||
//regs = new int [t_max];
|
||||
@@ -106,17 +106,17 @@ int owSetup(owChangedType owCh) {
|
||||
|
||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||
Wire.begin();
|
||||
if (net->checkPresence()) {
|
||||
if (oneWire->checkPresence()) {
|
||||
debugSerial.println(F("DS2482-100 present"));
|
||||
net->deviceReset();
|
||||
oneWire->deviceReset();
|
||||
#ifdef APU_OFF
|
||||
debugSerial.println(F("APU off"));
|
||||
#else
|
||||
net->setActivePullup();
|
||||
oneWire->setActivePullup();
|
||||
#endif
|
||||
|
||||
debugSerial.println(F("\tChecking for 1-Wire devices..."));
|
||||
if (net->wireReset())
|
||||
if (oneWire->wireReset())
|
||||
debugSerial.println(F("\tReset done"));
|
||||
|
||||
sensors->begin();
|
||||
@@ -191,7 +191,7 @@ void owAdd(DeviceAddress addr) {
|
||||
debugSerial.println();
|
||||
if (term[t_count][0] == 0x28) {
|
||||
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
||||
net->setStrongPullup();
|
||||
oneWire->setStrongPullup();
|
||||
// sensors.requestTemperaturesByAddress(term[t_count]);
|
||||
}
|
||||
t_count++;
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ typedef void (*owChangedType) (int , DeviceAddress, float) ;
|
||||
#include <Wire.h>
|
||||
#endif
|
||||
|
||||
extern OneWire *net;
|
||||
extern OneWire *oneWire;
|
||||
|
||||
extern DallasTemperature *sensors;
|
||||
extern DeviceAddress *term ;
|
||||
|
||||
+97
-5
@@ -21,8 +21,9 @@ e-mail anklimov@gmail.com
|
||||
#include "utils.h"
|
||||
#include "options.h"
|
||||
#include "stdarg.h"
|
||||
#include <wire.h>
|
||||
|
||||
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32F1)
|
||||
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32)
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
@@ -77,15 +78,22 @@ void SetAddr(char *out, uint8_t *addr) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// chan is pointer to pointer to string
|
||||
// Function return first retrived integer and move pointer to position next after ','
|
||||
int getInt(char **chan) {
|
||||
if (chan && *chan && **chan)
|
||||
{
|
||||
//Skip non-numeric values
|
||||
while (**chan && !(**chan == '-' || (**chan >= '0' && **chan<='9'))) *chan += 1;
|
||||
int ch = atoi(*chan);
|
||||
*chan = strchr(*chan, ',');
|
||||
|
||||
//Move pointer to next element (after ,)
|
||||
*chan = strchr(*chan, ',');
|
||||
if (*chan) *chan += 1;
|
||||
//Serial.print(F("Par:")); Serial.println(ch);
|
||||
return ch;
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +111,7 @@ unsigned long freeRam ()
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_STM32F1)
|
||||
#if defined(ARDUINO_ARCH_STM32)
|
||||
extern char _end;
|
||||
extern "C" char *sbrk(int i);
|
||||
|
||||
@@ -412,5 +420,89 @@ return buf;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void printUlongValueToStr(char *valstr, unsigned long value) {
|
||||
char buf[11];
|
||||
int i=0;
|
||||
for(;value>0;i++){
|
||||
unsigned long mod = value - ((unsigned long)(value/10))*10;
|
||||
buf[i]=mod+48;
|
||||
value = (unsigned long)(value/10);
|
||||
}
|
||||
|
||||
for(int n=0;n<=i;n++){
|
||||
valstr[n]=buf[i-n-1];
|
||||
}
|
||||
valstr[i]='\0';
|
||||
}
|
||||
|
||||
|
||||
void scan_i2c_bus() {
|
||||
byte error, address;
|
||||
int nDevices;
|
||||
|
||||
debugSerial<<(F("Scanning...\n"));
|
||||
|
||||
nDevices = 0;
|
||||
for(address = 1; address < 127; address++ )
|
||||
{
|
||||
// The i2c_scanner uses the return value of
|
||||
// the Write.endTransmisstion to see if
|
||||
// a device did acknowledge to the address.
|
||||
Wire.beginTransmission(address);
|
||||
error = Wire.endTransmission();
|
||||
|
||||
if (error == 0)
|
||||
{
|
||||
debugSerial<<(F("\nI2C device found at address "));
|
||||
// if (address<16)
|
||||
// debugSerial<<("0");
|
||||
debugSerial<<(address);
|
||||
|
||||
nDevices++;
|
||||
}
|
||||
else if (error==4)
|
||||
{
|
||||
debugSerial<<(F("\nUnknow error at address "));
|
||||
// if (address<16)
|
||||
// debugSerial<<("0");
|
||||
debugSerial<<(address);
|
||||
}
|
||||
}
|
||||
if (nDevices == 0)
|
||||
debugSerial<<(F("No I2C devices found\n"));
|
||||
else
|
||||
debugSerial<<(F("done\n"));
|
||||
}
|
||||
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
void softRebootFunc() {
|
||||
RSTC->RSTC_CR = 0xA5000005;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(NRF5) || defined (ARDUINO_ARCH_STM32)
|
||||
void softRebootFunc() {
|
||||
debugSerial<<"Not implemented"<<endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
void softRebootFunc(){
|
||||
debugSerial<<F("ESP.restart();");
|
||||
ESP.restart();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_AVR)
|
||||
void softRebootFunc(){
|
||||
void (*RebootFunc)(void) = 0;
|
||||
RebootFunc();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#pragma message(VAR_NAME_VALUE(debugSerial))
|
||||
#pragma message(VAR_NAME_VALUE(SERIAL_BAUD))
|
||||
|
||||
@@ -17,6 +17,8 @@ GIT: https://github.com/anklimov/lighthub
|
||||
e-mail anklimov@gmail.com
|
||||
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#define Q(x) #x
|
||||
#define QUOTE(x) Q(x)
|
||||
#define VALUE_TO_STRING(x) #x
|
||||
@@ -54,3 +56,6 @@ int inet_aton(const char* aIPAddrString, IPAddress& aResult);
|
||||
char *inet_ntoa_r(IPAddress addr, char *buf, int buflen);
|
||||
void printIPAddress(IPAddress ipAddress);
|
||||
char* setTopic(char* buf, int8_t buflen, topicType tt, char* suffix = NULL);
|
||||
void printUlongValueToStr(char *valstr, unsigned long value);
|
||||
void scan_i2c_bus();
|
||||
void softRebootFunc();
|
||||
|
||||
+84
-45
@@ -9,25 +9,23 @@
|
||||
; http://docs.platformio.org/page/projectconf.html
|
||||
[platformio]
|
||||
src_dir = lighthub
|
||||
|
||||
env_default = megaatmega2560-net
|
||||
;monitor_speed = 115200
|
||||
;env_default = megaatmega2560-net
|
||||
; megaatmega2560
|
||||
; megaatmega2560-net
|
||||
; due
|
||||
; esp8266
|
||||
; esp32
|
||||
; megaatmega2560-5500
|
||||
; due-5500
|
||||
; due-5500
|
||||
; controllino
|
||||
; stm32
|
||||
; esp32-evb
|
||||
; nrf52840_dk
|
||||
; nrf52840
|
||||
|
||||
|
||||
;build_dir = /tmp/pioenvs
|
||||
;libdeps_dir = /tmp/piolibdeps
|
||||
[env:nrf52840_dk]
|
||||
[env:nrf52840]
|
||||
platform = nordicnrf52
|
||||
board = nrf52840_dk
|
||||
;upload_protocol = mbed
|
||||
@@ -35,6 +33,7 @@ board = nrf52840_dk
|
||||
framework = arduino
|
||||
build_flags = !bash check_custom_build_flags_nrf52840.sh
|
||||
lib_ignore =
|
||||
ESP_EEPROM
|
||||
DmxSimple
|
||||
DMXSerial
|
||||
DmxDue
|
||||
@@ -47,17 +46,21 @@ lib_ignore =
|
||||
httpClient
|
||||
FastLED
|
||||
ESPDMX
|
||||
ESP-Dmx
|
||||
DueFlashStorage
|
||||
PrintEx
|
||||
DHT sensor library
|
||||
;DHT sensor library
|
||||
DHT sensor library for ESPx
|
||||
Adafruit Unified Sensor
|
||||
;Adafruit Unified Sensor
|
||||
WebServer
|
||||
; Adafruit_Sensor
|
||||
UIPEthernet
|
||||
;Adafruit_Sensor
|
||||
ClosedCube HDC1080
|
||||
SparkFun CCS811 Arduino Library
|
||||
lib_deps =
|
||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
||||
https://github.com/anklimov/DS2482_OneWire
|
||||
Ethernet2
|
||||
https://github.com/anklimov/Ethernet2
|
||||
ESP8266HTTPClient
|
||||
https://github.com/anklimov/aJson
|
||||
https://github.com/anklimov/CmdArduino
|
||||
@@ -65,14 +68,14 @@ lib_deps =
|
||||
https://github.com/knolleary/pubsubclient.git
|
||||
; https://github.com/anklimov/Artnet.git
|
||||
; FastLED
|
||||
; Adafruit Unified Sensor
|
||||
; DHT sensor library for ESPx
|
||||
; DHT sensor library
|
||||
Adafruit Unified Sensor
|
||||
DHT sensor library
|
||||
Streaming
|
||||
https://github.com/anklimov/NRFFlashStorage
|
||||
; https://github.com/livello/PrintEx#is-select-redecl
|
||||
|
||||
|
||||
|
||||
[env:esp32]
|
||||
platform = espressif32
|
||||
framework = arduino
|
||||
@@ -93,32 +96,31 @@ lib_ignore =
|
||||
HTTPClient
|
||||
httpClient
|
||||
EEPROM
|
||||
https://github.com/anklimov/ModbusMaster
|
||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
||||
https://github.com/anklimov/DS2482_OneWire
|
||||
DS2482_OneWire
|
||||
OneWire
|
||||
DallasTemperature
|
||||
ModbusMaster
|
||||
Artnet
|
||||
https://github.com/anklimov/Artnet.git
|
||||
FastLED
|
||||
Adafruit Unified Sensor
|
||||
DHT sensor library for ESPx
|
||||
DHT sensor library
|
||||
Wire
|
||||
;WifiManager
|
||||
;HTTPClient
|
||||
;HttpClient
|
||||
HTTPClient
|
||||
UIPEthernet
|
||||
ESP_EEPROM
|
||||
EEPROM
|
||||
lib_deps =
|
||||
https://github.com/ebenolson/WIFIMANAGER-ESP32.git
|
||||
https://github.com/zhouhan0126/WebServer-esp32.git
|
||||
https://github.com/arduino-libraries/ArduinoHttpClient.git
|
||||
ArduinoHttpClient
|
||||
https://github.com/anklimov/aJson
|
||||
https://github.com/anklimov/CmdArduino
|
||||
https://github.com/knolleary/pubsubclient.git
|
||||
Streaming
|
||||
;ESP_EEPROM
|
||||
https://github.com/anklimov/NRFFlashStorage
|
||||
Adafruit Unified Sensor
|
||||
DHT sensor library for ESPx
|
||||
https://github.com/anklimov/Artnet.git
|
||||
https://github.com/anklimov/ModbusMaster
|
||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
||||
https://github.com/anklimov/DS2482_OneWire
|
||||
https://github.com/anklimov/ESP-Dmx
|
||||
FastLED
|
||||
ClosedCube HDC1080
|
||||
SparkFun CCS811 Arduino Library
|
||||
[env:due]
|
||||
platform = atmelsam
|
||||
framework = arduino
|
||||
@@ -126,20 +128,24 @@ board = due
|
||||
build_flags = !bash check_custom_build_flags_due.sh
|
||||
lib_ignore =
|
||||
DHT sensor library for ESPx
|
||||
ESP_EEPROM
|
||||
DMXSerial
|
||||
DmxSimple
|
||||
httpClient
|
||||
ESPDMX
|
||||
ESP-Dmx
|
||||
WifiManager
|
||||
Ethernet3
|
||||
NRFFlashStorage
|
||||
WebServer
|
||||
UIPEthernet
|
||||
EEPROM
|
||||
lib_deps =
|
||||
https://github.com/sebnil/DueFlashStorage
|
||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
||||
https://github.com/anklimov/DS2482_OneWire
|
||||
https://github.com/anklimov/DmxDue
|
||||
https://github.com/anklimov/ArduinoHttpClient
|
||||
ArduinoHttpClient
|
||||
https://github.com/anklimov/aJson
|
||||
https://github.com/anklimov/CmdArduino
|
||||
https://github.com/anklimov/ModbusMaster
|
||||
@@ -153,7 +159,8 @@ lib_deps =
|
||||
DHT sensor library
|
||||
https://github.com/arcao/Syslog.git
|
||||
Streaming
|
||||
|
||||
ClosedCube HDC1080
|
||||
SparkFun CCS811 Arduino Library
|
||||
|
||||
[env:megaatmega2560]
|
||||
platform = atmelavr
|
||||
@@ -170,6 +177,8 @@ lib_ignore =
|
||||
HTTPClient
|
||||
NRFFlashStorage
|
||||
WebServer
|
||||
UIPEthernet
|
||||
ESP_EEPROM
|
||||
lib_deps =
|
||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
||||
https://github.com/anklimov/DS2482_OneWire
|
||||
@@ -183,11 +192,13 @@ lib_deps =
|
||||
https://github.com/knolleary/pubsubclient.git
|
||||
https://github.com/anklimov/Artnet.git
|
||||
FastLED
|
||||
EEPROM
|
||||
;EEPROM
|
||||
Adafruit Unified Sensor
|
||||
DHT sensor library
|
||||
https://github.com/arcao/Syslog.git
|
||||
Streaming
|
||||
ClosedCube HDC1080
|
||||
SparkFun CCS811 Arduino Library
|
||||
|
||||
[env:esp8266]
|
||||
platform = espressif8266
|
||||
@@ -202,8 +213,14 @@ lib_ignore =
|
||||
SD
|
||||
SdFat
|
||||
httpClient
|
||||
HTTPClient
|
||||
ArduinoHttpClient
|
||||
Ethernet3
|
||||
Ethernet2
|
||||
Ethernet
|
||||
NRFFlashStorage
|
||||
UIPEthernet
|
||||
EEPROM
|
||||
lib_deps =
|
||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
||||
https://github.com/anklimov/DS2482_OneWire
|
||||
@@ -221,6 +238,9 @@ lib_deps =
|
||||
WifiManager
|
||||
https://github.com/arcao/Syslog.git
|
||||
Streaming
|
||||
ESP_EEPROM
|
||||
ClosedCube HDC1080
|
||||
SparkFun CCS811 Arduino Library
|
||||
|
||||
[env:megaatmega2560-net]
|
||||
platform = atmelavr
|
||||
@@ -232,12 +252,15 @@ lib_ignore =
|
||||
DHT sensor library for ESPx
|
||||
DmxDue
|
||||
DueFlashStorage
|
||||
ESPDMX
|
||||
ESP-Dmx
|
||||
WifiManager
|
||||
Ethernet3
|
||||
Ethernet2
|
||||
NRFFlashStorage
|
||||
WebServer
|
||||
UIPEthernet
|
||||
ESP_EEPROM
|
||||
lib_deps =
|
||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
||||
https://github.com/anklimov/DS2482_OneWire
|
||||
@@ -255,6 +278,8 @@ lib_deps =
|
||||
DHT sensor library
|
||||
https://github.com/arcao/Syslog.git
|
||||
Streaming
|
||||
ClosedCube HDC1080
|
||||
SparkFun CCS811 Arduino Library
|
||||
|
||||
[env:due-5500]
|
||||
platform = atmelsam
|
||||
@@ -263,10 +288,9 @@ board = due
|
||||
build_flags = !bash check_custom_build_flags_due-5500.sh
|
||||
lib_ignore =
|
||||
DHT sensor library for ESPx
|
||||
https://github.com/anklimov/Ethernet
|
||||
ESPDMX
|
||||
ESP-Dmx
|
||||
DMXSerial
|
||||
ESPDMX
|
||||
WifiManager
|
||||
DmxSimple
|
||||
httpClient
|
||||
@@ -274,14 +298,16 @@ lib_ignore =
|
||||
Ethernet3
|
||||
NRFFlashStorage
|
||||
WebServer
|
||||
|
||||
UIPEthernet
|
||||
ESP_EEPROM
|
||||
EEPROM
|
||||
lib_deps =
|
||||
|
||||
https://github.com/sebnil/DueFlashStorage
|
||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
||||
https://github.com/anklimov/DS2482_OneWire
|
||||
https://github.com/anklimov/DmxDue
|
||||
https://github.com/anklimov/ArduinoHttpClient
|
||||
ArduinoHttpClient
|
||||
https://github.com/anklimov/aJson
|
||||
https://github.com/anklimov/CmdArduino
|
||||
https://github.com/anklimov/ModbusMaster
|
||||
@@ -296,6 +322,8 @@ lib_deps =
|
||||
https://github.com/arcao/Syslog.git
|
||||
Streaming
|
||||
https://github.com/livello/PrintEx#is-select-redecl
|
||||
ClosedCube HDC1080
|
||||
SparkFun CCS811 Arduino Library
|
||||
|
||||
|
||||
[env:controllino]
|
||||
@@ -307,12 +335,15 @@ lib_ignore =
|
||||
DHT sensor library for ESPx
|
||||
DmxDue
|
||||
DueFlashStorage
|
||||
ESPDMX
|
||||
ESP-Dmx
|
||||
WifiManager
|
||||
Ethernet3
|
||||
Ethernet2
|
||||
NRFFlashStorage
|
||||
WebServer
|
||||
UIPEthernet
|
||||
ESP_EEPROM
|
||||
lib_deps =
|
||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
||||
https://github.com/anklimov/DS2482_OneWire
|
||||
@@ -326,11 +357,13 @@ lib_deps =
|
||||
https://github.com/knolleary/pubsubclient.git
|
||||
https://github.com/anklimov/Artnet.git
|
||||
FastLED
|
||||
EEPROM
|
||||
;EEPROM
|
||||
Adafruit Unified Sensor
|
||||
DHT sensor library
|
||||
Streaming
|
||||
https://github.com/livello/PrintEx#is-select-redecl
|
||||
ClosedCube HDC1080
|
||||
SparkFun CCS811 Arduino Library
|
||||
|
||||
[env:stm32]
|
||||
platform = ststm32
|
||||
@@ -343,11 +376,11 @@ lib_ignore =
|
||||
DHT sensor library for ESPx
|
||||
DmxDue
|
||||
DueFlashStorage
|
||||
ESPDMX
|
||||
ESP-Dmx
|
||||
WifiManager
|
||||
FastLED
|
||||
Ethernet
|
||||
https://github.com/anklimov/Ethernet
|
||||
DMXSerial
|
||||
DmxSimple
|
||||
httpClient
|
||||
@@ -356,16 +389,22 @@ lib_ignore =
|
||||
Ethernet2
|
||||
Artnet
|
||||
Ethernet3
|
||||
NRFFlashStorage
|
||||
WebServer
|
||||
|
||||
|
||||
ESP_EEPROM
|
||||
DHT sensor library
|
||||
DallasTemperature
|
||||
Adafruit Unified Sensor
|
||||
DS2482_OneWire
|
||||
ModbusMaster
|
||||
Syslog
|
||||
EEPROM
|
||||
ClosedCube HDC1080
|
||||
SparkFun CCS811 Arduino Library
|
||||
lib_deps =
|
||||
; DallasTemperature
|
||||
https://github.com/anklimov/aJson
|
||||
https://github.com/anklimov/CmdArduino
|
||||
ArduinoHttpClient
|
||||
https://github.com/knolleary/pubsubclient.git
|
||||
Adafruit Unified Sensor
|
||||
DHT sensor library
|
||||
Streaming
|
||||
UIPEthernet
|
||||
https://github.com/anklimov/NRFFlashStorage
|
||||
|
||||
Reference in New Issue
Block a user