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:
2019-04-09 21:39:42 +03:00
committed by GitHub
37 changed files with 17506 additions and 7591 deletions

2
.gitignore vendored
View File

@@ -3,6 +3,7 @@
.clang_complete .clang_complete
.gcc-flags.json .gcc-flags.json
CMakeListsPrivate.txt CMakeListsPrivate.txt
custom-build-flags/*
build_flags_due.sh build_flags_due.sh
build_flags_esp32.sh build_flags_esp32.sh
build_flags_esp8266.sh build_flags_esp8266.sh
@@ -10,3 +11,4 @@ build_flags_stm32.sh
build_flags_due-5500.sh build_flags_due-5500.sh
build_flags_mega2560.sh build_flags_mega2560.sh
build_flags_controllino.sh build_flags_controllino.sh
build_flags_nrf52840.sh

View File

@@ -1,9 +1,9 @@
#! /bin/bash #! /bin/bash
export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) 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 -DMODBUS_DISABLE"
export FLAGS="$FLAGS -DOWIRE_DISABLE" #export FLAGS="$FLAGS -DOWIRE_DISABLE"
export FLAGS="$FLAGS -DDHT_DISABLE" #export FLAGS="$FLAGS -DDHT_DISABLE"
export FLAGS="$FLAGS -DCOUNTER_DISABLE" export FLAGS="$FLAGS -DCOUNTER_DISABLE"
#export FLAGS="$FLAGS -std=gnu++11" #export FLAGS="$FLAGS -std=gnu++11"
CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_esp32.sh CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_esp32.sh

View File

@@ -1,6 +1,6 @@
#! /bin/bash #! /bin/bash
export FLAGS="$FLAGS -DMODBUS_DISABLE" 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) 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 CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_esp8266.sh
if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then

View File

@@ -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 -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 -DMODBUS_DISABLE"
export FLAGS="$FLAGS -DOWIRE_DISABLE" #export FLAGS="$FLAGS -DOWIRE_DISABLE"
export FLAGS="$FLAGS -std=gnu++11" export FLAGS="$FLAGS -std=gnu++11"
export FLAGS="$FLAGS -DWIFI_MANAGER_DISABLE" export FLAGS="$FLAGS -DWIFI_MANAGER_DISABLE"
export FLAGS="$FLAGS -DCOUNTER_DISABLE" export FLAGS="$FLAGS -DCOUNTER_DISABLE"
export FLAGS="$FLAGS -DCSSHDC_DISABLE"
CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_nrf52840.sh CUSTOM_BUILD_FLAGS_FILE=custom-build-flags/build_flags_nrf52840.sh
if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then

View File

@@ -6,6 +6,8 @@ export FLAGS="$FLAGS -DMODBUS_DISABLE"
export FLAGS="$FLAGS -DOWIRE_DISABLE" export FLAGS="$FLAGS -DOWIRE_DISABLE"
export FLAGS="$FLAGS -DDHT_DISABLE" export FLAGS="$FLAGS -DDHT_DISABLE"
export FLAGS="$FLAGS -DCOUNTER_DISABLE" export FLAGS="$FLAGS -DCOUNTER_DISABLE"
export FLAGS="$FLAGS -DNO_HOMIE"
export FLAGS="$FLAGS -DCSSHDC_DISABLE"
if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then if [ -f $CUSTOM_BUILD_FLAGS_FILE ]; then
source $CUSTOM_BUILD_FLAGS_FILE source $CUSTOM_BUILD_FLAGS_FILE
fi fi

Binary file not shown.

Binary file not shown.

BIN
compiled/DUE/firmware.bin Executable file

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

BIN
compiled/due-5500/firmware.bin Executable file

Binary file not shown.

BIN
compiled/esp32/firmware.bin Normal file

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

BIN
compiled/stm32/firmware.bin Executable file

Binary file not shown.

View File

@@ -3,14 +3,14 @@
# first make your own copy of template # first make your own copy of template
# cp build_flags_template.sh build_flags_ENVNAME.sh # cp build_flags_template.sh build_flags_ENVNAME.sh
# then edit, change or comment something # then edit, change or comment something
export FLAGS="$FLAGS -DMY_CONFIG_SERVER=lazyhome.ru" # export FLAGS="$FLAGS -DMY_CONFIG_SERVER=lazyhome.ru"
# export FLAGS="$FLAGS -DWATCH_DOG_TICKER_DISABLE" # export FLAGS="$FLAGS -DWATCH_DOG_TICKER_DISABLE"
# export FLAGS="$FLAGS -DUSE_1W_PIN=12" # export FLAGS="$FLAGS -DUSE_1W_PIN=12"
# export FLAGS="$FLAGS -DSD_CARD_INSERTED" # export FLAGS="$FLAGS -DSD_CARD_INSERTED"
export FLAGS="$FLAGS -DSERIAL_BAUD=115200" # export FLAGS="$FLAGS -DSERIAL_BAUD=115200"
# export FLAGS="$FLAGS -DWiz5500" # export FLAGS="$FLAGS -DWiz5500"
# export FLAGS="$FLAGS -DDISABLE_FREERAM_PRINT" # export FLAGS="$FLAGS -DDISABLE_FREERAM_PRINT"
export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:ff" # export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:ff"
# export FLAGS="$FLAGS -DDMX_DISABLE" # export FLAGS="$FLAGS -DDMX_DISABLE"
# export FLAGS="$FLAGS -DMODBUS_DISABLE" # export FLAGS="$FLAGS -DMODBUS_DISABLE"
# export FLAGS="$FLAGS -DOWIRE_DISABLE" # export FLAGS="$FLAGS -DOWIRE_DISABLE"
@@ -26,7 +26,8 @@
# export FLAGS="$FLAGS -DW5500_CS_PIN=53" # export FLAGS="$FLAGS -DW5500_CS_PIN=53"
# export FLAGS="$FLAGS -DSYSLOG_ENABLE" # export FLAGS="$FLAGS -DSYSLOG_ENABLE"
# export FLAGS="$FLAGS -DDEVICE_NAME=MYDEVICE" # export FLAGS="$FLAGS -DDEVICE_NAME=MYDEVICE"
#export FLAGS="$FLAGS -DDHT_COUNTER_DISABLE" # export FLAGS="$FLAGS -DDHT_DISABLE"
# export FLAGS="$FLAGS -DCOUNTER_DISABLE"
# export FLAGS="$FLAGS -DWITH_PRINTEX_LIB" # export FLAGS="$FLAGS -DWITH_PRINTEX_LIB"
export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short) # export FLAGS="$FLAGS -DPIO_SRC_REV="$(git log --pretty=format:%h_%ad -1 --date=short)
echo $FLAGS echo $FLAGS

43
lighthub/abstractin.cpp Normal file
View File

@@ -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;
};

17
lighthub/abstractin.h Normal file
View File

@@ -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;
};

View File

@@ -1,3 +1,4 @@
#pragma once
const char state_P[] PROGMEM = "$state"; const char state_P[] PROGMEM = "$state";
const char disconnected_P[] PROGMEM = "disconnected"; const char disconnected_P[] PROGMEM = "disconnected";
@@ -10,6 +11,12 @@ 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 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 color_P[] PROGMEM = "color";
const char datatype_P[] PROGMEM = "$datatype"; const char datatype_P[] PROGMEM = "$datatype";

View File

@@ -26,17 +26,21 @@ e-mail anklimov@gmail.com
#ifndef DHT_DISABLE #ifndef DHT_DISABLE
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
#include <DHTesp.h> #include <DHTesp.h>
#else #else
#include "DHT.h" #include "DHT.h"
#endif #endif
#endif #endif
extern PubSubClient mqttClient; 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 unsigned long nextPollMillisValue[5];
static volatile int nextPollMillisPin[5] = {0,0,0,0,0}; static volatile int nextPollMillisPin[5] = {0,0,0,0,0};
#endif
#ifndef COUNTER_DISABLE
#if defined(ARDUINO_ARCH_AVR) #if defined(ARDUINO_ARCH_AVR)
static volatile long counter_value[6]; static volatile long counter_value[6];
#endif #endif
@@ -49,7 +53,7 @@ static volatile long counter_value[6];
static volatile long counter_value[6]; static volatile long counter_value[6];
#endif #endif
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32F1) #if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32)
static short counter_irq_map[54]; static short counter_irq_map[54];
static long counter_value[54]; static long counter_value[54];
static int counters_count; static int counters_count;
@@ -91,7 +95,7 @@ void Input::Parse()
store = NULL; store = NULL;
inType = 0; inType = 0;
pin = 0; pin = 0;
if (inputObj && (inputObj->type == aJson_Object)) { if (inputObj && (inputObj->type == aJson_Object) && root) {
aJsonObject *itemBuffer; aJsonObject *itemBuffer;
itemBuffer = aJson.getObjectItem(inputObj, "T"); itemBuffer = aJson.getObjectItem(inputObj, "T");
if (itemBuffer) inType = static_cast<uint8_t>(itemBuffer->valueint); if (itemBuffer) inType = static_cast<uint8_t>(itemBuffer->valueint);
@@ -106,25 +110,81 @@ void Input::Parse()
} }
} }
int Input::poll() { void Input::setup()
if (!isValid()) return -1; {
if (0) ; if (!isValid() || (!root)) return;
#ifndef DHT_DISABLE #ifndef CSSHDC_DISABLE
else if (inType & IN_DHT22) in_ccs811 ccs811(this);
dht22Poll(); in_hdc1080 hdc1080(this);
else if (inType & IN_COUNTER)
counterPoll(); if (inType == IN_CCS811)
else if (inType & IN_UPTIME) ccs811.Setup(pin);
uptimePoll(); else if (inType == IN_HDC1080)
hdc1080.Setup(pin);
// TODO rest types setup
#endif #endif
else if (inType & IN_ANALOG)
analogPoll();
else
contactPoll();
return 0;
// contactPoll(); }
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
#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 #ifndef COUNTER_DISABLE
@@ -160,9 +220,11 @@ void Input::counterPoll() {
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit"); aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
if (emit) { if (emit) {
char valstr[10]; char valstr[10];
char addrstr[100] = ""; char addrstr[MQTT_TOPIC_LENGTH];
strcat(addrstr, emit->valuestring); strncpy(addrstr,emit->valuestring,sizeof(addrstr));
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
sprintf(valstr, "%d", counterValue); sprintf(valstr, "%d", counterValue);
if (mqttClient.connected() && !ethernetIdleCount)
mqttClient.publish(addrstr, valstr); mqttClient.publish(addrstr, valstr);
setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT); setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT);
debugSerial<<F(" NextPollMillis=")<<nextPollTime(); 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() { void Input::uptimePoll() {
if (nextPollTime() > millis()) if (nextPollTime() > millis())
@@ -288,6 +288,7 @@ void Input::uptimePoll() {
char valstr[11]; char valstr[11];
// printUlongValueToStr(valstr,millis()); // printUlongValueToStr(valstr,millis());
printUlongValueToStr(valstr, millis()); printUlongValueToStr(valstr, millis());
if (mqttClient.connected() && !ethernetIdleCount)
mqttClient.publish(emit->valuestring, valstr); mqttClient.publish(emit->valuestring, valstr);
} }
setNextPollTime(millis() + UPTIME_POLL_DELAY_DEFAULT); setNextPollTime(millis() + UPTIME_POLL_DELAY_DEFAULT);
@@ -324,16 +325,94 @@ void Input::onCounterChanged5() {
#endif #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() { void Input::contactPoll() {
boolean currentInputState; boolean currentInputState;
#if defined(ARDUINO_ARCH_STM32F1) /*
#if defined(ARDUINO_ARCH_STM32)
WiringPinMode inputPinMode; WiringPinMode inputPinMode;
#endif #endif
#if defined(__SAM3X8E__)||defined(ARDUINO_ARCH_AVR)||defined(ARDUINO_ARCH_ESP8266)||defined(ARDUINO_ARCH_ESP32) #if defined(__SAM3X8E__)||defined(ARDUINO_ARCH_AVR)||defined(ARDUINO_ARCH_ESP8266)||defined(ARDUINO_ARCH_ESP32)
#endif #endif
*/
uint32_t inputPinMode; uint32_t inputPinMode;
uint8_t inputOnLevel; uint8_t inputOnLevel;
if (inType & IN_ACTIVE_HIGH) { if (inType & IN_ACTIVE_HIGH) {
@@ -372,12 +451,14 @@ void Input::analogPoll() {
short Noize = ANALOG_NOIZE; short Noize = ANALOG_NOIZE;
short simple = 0; short simple = 0;
#if defined(ARDUINO_ARCH_STM32F1) /*
#if defined(ARDUINO_ARCH_STM32)
WiringPinMode inputPinMode; WiringPinMode inputPinMode;
#endif #endif
#if defined(__SAM3X8E__)||defined(ARDUINO_ARCH_AVR)||defined(ARDUINO_ARCH_ESP8266)||defined(ARDUINO_ARCH_ESP32) #if defined(__SAM3X8E__)||defined(ARDUINO_ARCH_AVR)||defined(ARDUINO_ARCH_ESP8266)||defined(ARDUINO_ARCH_ESP32)
#endif #endif */
uint32_t inputPinMode; uint32_t inputPinMode;
if (inType & IN_ACTIVE_HIGH) { if (inType & IN_ACTIVE_HIGH) {
inputPinMode = INPUT; inputPinMode = INPUT;
@@ -437,22 +518,33 @@ void Input::onContactChanged(int newValue) {
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit"); aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
if (emit) { if (emit) {
#ifdef WITH_DOMOTICZ #ifdef WITH_DOMOTICZ
if (getIdxField()) { if (getIdxField())
(newValue)? publishDataToDomoticz(0, emit, "{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"On\"}", getIdxField()) { (newValue) ? publishDataToDomoticz(0, emit, "{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"On\"}",
: publishDataToDomoticz(0,emit,"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",getIdxField()); : publishDataToDomoticz(0,emit,"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",getIdxField()); getIdxField())
: publishDataToDomoticz(0, emit,
"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",
getIdxField());
} else } else
#endif #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 (newValue) { //send set command
if (!scmd) mqttClient.publish(emit->valuestring, "ON", true); if (!scmd) mqttClient.publish(addrstr, "ON", true);
else if (strlen(scmd->valuestring)) else if (strlen(scmd->valuestring))
mqttClient.publish(emit->valuestring, scmd->valuestring, true); mqttClient.publish(addrstr, scmd->valuestring, true);
} else { //send reset command } else { //send reset command
if (!rcmd) mqttClient.publish(emit->valuestring, "OFF", true); if (!rcmd) mqttClient.publish(addrstr, "OFF", true);
else if (strlen(rcmd->valuestring))mqttClient.publish(emit->valuestring, rcmd->valuestring, true); else if (strlen(rcmd->valuestring))mqttClient.publish(addrstr, rcmd->valuestring, true);
} }
} }
}
} // emit
if (item) { if (item) {
//debugSerial <<F("Controlled item:")<< item->valuestring <<endl;
Item it(item->valuestring); Item it(item->valuestring);
if (it.isValid()) { if (it.isValid()) {
if (newValue) { //send set command if (newValue) { //send set command
@@ -468,7 +560,6 @@ void Input::onContactChanged(int newValue) {
} }
} }
void Input::onAnalogChanged(int newValue) { void Input::onAnalogChanged(int newValue) {
debugSerial << F("IN:") << (pin) << F("=") << newValue << endl; debugSerial << F("IN:") << (pin) << F("=") << newValue << endl;
aJsonObject *item = aJson.getObjectItem(inputObj, "item"); 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()); // : publishDataToDomoticz(0,emit,"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",getIdxField());
// } else // } else
//#endif //#endif
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]; char strVal[16];
itoa(newValue,strVal,10); itoa(newValue,strVal,10);
mqttClient.publish(emit->valuestring, strVal, true); if (mqttClient.connected() && !ethernetIdleCount)
mqttClient.publish(addrstr, strVal, true);
} }
if (item) { 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, ...) bool Input::publishDataToDomoticz(int pollTimeIncrement, aJsonObject *emit, const char *format, ...)
{ {
#ifdef WITH_DOMOTICZ #ifdef WITH_DOMOTICZ
@@ -521,6 +602,7 @@ bool Input::publishDataToDomoticz(int pollTimeIncrement, aJsonObject *emit, cons
vsnprintf(valstr, sizeof(valstr) - 1, format, args); vsnprintf(valstr, sizeof(valstr) - 1, format, args);
va_end(args); va_end(args);
debugSerial << valstr; debugSerial << valstr;
if (mqttClient.connected() && !ethernetIdleCount)
mqttClient.publish(emit->valuestring, valstr); mqttClient.publish(emit->valuestring, valstr);
if (pollTimeIncrement) if (pollTimeIncrement)
setNextPollTime(millis() + pollTimeIncrement); setNextPollTime(millis() + pollTimeIncrement);

View File

@@ -17,8 +17,9 @@ GIT: https://github.com/anklimov/lighthub
e-mail anklimov@gmail.com e-mail anklimov@gmail.com
*/ */
#pragma once
#include <aJSON.h> #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_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 #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_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_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_DHT22 4
#define IN_CCS811 5
#define IN_HDC1080 6
#define IN_COUNTER 8 #define IN_COUNTER 8
#define IN_UPTIME 16 #define IN_UPTIME 16
#define SAME_STATE_ATTEMPTS 3 #define SAME_STATE_ATTEMPTS 3
#define ANALOG_STATE_ATTEMPTS 6 #define ANALOG_STATE_ATTEMPTS 6
#define ANALOG_NOIZE 1 #define ANALOG_NOIZE 1
#define CHECK_INPUT 1
#define CHECK_SENSOR 2
// in syntaxis // 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" } // "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 { typedef union {
long int aslong; long int aslong;
uint32_t timestamp;
struct { struct {
int8_t logicState; int8_t logicState;
int8_t bounce; int8_t bounce;
@@ -95,7 +105,8 @@ public:
void onContactChanged(int newValue); void onContactChanged(int newValue);
void onAnalogChanged(int newValue); void onAnalogChanged(int newValue);
int poll(); int poll(short cause);
void setup();
static void inline onCounterChanged(int i); static void inline onCounterChanged(int i);
static void onCounterChanged0(); static void onCounterChanged0();
@@ -126,7 +137,6 @@ protected:
void uptimePoll(); void uptimePoll();
void printUlongValueToStr(char *valstr, unsigned long value);
bool publishDataToDomoticz(int , aJsonObject *, const char *format, ...); bool publishDataToDomoticz(int , aJsonObject *, const char *format, ...);
char* getIdxField(); char* getIdxField();

View File

@@ -17,6 +17,7 @@ GIT: https://github.com/anklimov/lighthub
e-mail anklimov@gmail.com e-mail anklimov@gmail.com
*/ */
#include "options.h" #include "options.h"
#include "item.h" #include "item.h"
#include "aJSON.h" #include "aJSON.h"
@@ -32,7 +33,28 @@ e-mail anklimov@gmail.com
#endif #endif
#include <PubSubClient.h> #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; short modbusBusy = 0;
extern aJsonObject *pollingItem; extern aJsonObject *pollingItem;
@@ -41,6 +63,7 @@ extern aJsonObject *pollingItem;
//int modbusSet(int addr, uint16_t _reg, int _mask, uint16_t value); //int modbusSet(int addr, uint16_t _reg, int _mask, uint16_t value);
extern PubSubClient mqttClient; extern PubSubClient mqttClient;
extern int8_t ethernetIdleCount;
//extern char outprefix[]; //extern char outprefix[];
//const char outprefix[] PROGMEM = OUTTOPIC; //const char outprefix[] PROGMEM = OUTTOPIC;
@@ -51,19 +74,39 @@ int txt2cmd(char *payload) {
int cmd = -1; int cmd = -1;
// Check for command // Check for command
if (strcmp(payload, "ON") == 0) cmd = CMD_ON; if (strcmp_P(payload, ON_P) == 0) cmd = CMD_ON;
else if (strcmp(payload, "OFF") == 0) cmd = CMD_OFF; else if (strcmp_P(payload, OFF_P) == 0) cmd = CMD_OFF;
else if (strcmp(payload, "REST") == 0) cmd = CMD_RESTORE; else if (strcmp_P(payload, REST_P) == 0) cmd = CMD_RESTORE;
else if (strcmp(payload, "TOGGLE") == 0) cmd = CMD_TOGGLE; else if (strcmp_P(payload, TOGGLE_P) == 0) cmd = CMD_TOGGLE;
else if (strcmp(payload, "HALT") == 0) cmd = CMD_HALT; else if (strcmp_P(payload, HALT_P) == 0) cmd = CMD_HALT;
else if (strcmp(payload, "XON") == 0) cmd = CMD_XON; else if (strcmp_P(payload, XON_P) == 0) cmd = CMD_XON;
else if (strcmp(payload, "XOFF") == 0) cmd = CMD_XOFF; else if (strcmp_P(payload, XOFF_P) == 0) cmd = CMD_XOFF;
else if (strcmp(payload, "INCREASE") == 0) cmd = CMD_UP; else if (strcmp_P(payload, TRUE_P) == 0) cmd = CMD_ON;
else if (strcmp(payload, "DECREASE") == 0) cmd = CMD_DN; else if (strcmp_P(payload, FALSE_P) == 0) cmd = CMD_OFF;
else if (*payload == '-' || (*payload >= '0' && *payload <= '9')) cmd = 0; else if (strcmp_P(payload, INCREASE_P) == 0) cmd = CMD_UP;
else if (*payload == '{') cmd = -2; else if (strcmp_P(payload, DECREASE_P) == 0) cmd = CMD_DN;
else if (*payload == '#') cmd = -3; 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; return cmd;
} }
@@ -200,24 +243,46 @@ boolean Item::getEnableCMD(int delta) {
int Item::Ctrl(char * payload, boolean send, char * subItem){ int Item::Ctrl(char * payload, boolean send, char * subItem){
if (!payload) return 0; 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); int cmd = txt2cmd(payload);
debugSerial<<F("Txt2Cmd:")<<cmd<<endl;
switch (cmd) { switch (cmd) {
case 0: { case CMD_NUM:
case CMD_HSV:
{
short i = 0; short i = 0;
int Par[3]; int Par[3];
while (payload && i < 3) while (payload && i < 3)
Par[i++] = getInt((char **) &payload); Par[i++] = getInt((char **) &payload);
return Ctrl(0, i, Par, send, subItem); return Ctrl(0, i, Par, send, subItemN);
} }
break; break;
case -1: //Not known command case -1: //Not known command
case -2: //JSON input (not implemented yet case -2: //JSON input (not implemented yet
break; 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 case -3: //RGB color in #RRGGBB notation
{ {
CRGB rgb; 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[0] = map(hsv.h, 0, 255, 0, 365);
Par[1] = map(hsv.s, 0, 255, 0, 100); Par[1] = map(hsv.s, 0, 255, 0, 100);
Par[2] = map(hsv.v, 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; break;
} }
@@ -236,20 +301,21 @@ int Item::Ctrl(char * payload, boolean send, char * subItem){
// if (item.getEnableCMD(500) || lanStatus == 4) // if (item.getEnableCMD(500) || lanStatus == 4)
return Ctrl(cmd, 0, NULL, 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")); // else debugSerial<<F("on Skipped"));
break; break;
default: //some known command default: //some known command
return Ctrl(cmd, 0, NULL, send, subItem); return Ctrl(cmd, 0, NULL, send, subItemN);
} //ctrl } //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; if (!itemArr) return -1;
int Par[MAXCTRLPAR] = {0, 0, 0}; int Par[MAXCTRLPAR] = {0, 0, 0};
if (Parameters) 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) { switch (itemType) {
#ifdef _dmxout #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)); DmxWrite(iaddr, map(Par[0], 0, 100, 0, 255));
break; break;
case CH_RGBW: //Colour RGBW case CH_RGBW: //Colour RGBW
// Saturation 0 - Only white
// 0..50 - white + RGB
//50..100 RGB
{ {
int k; int k;
DmxWrite(iaddr + 3, k = map((100 - Par[1]) * Par[2], 0, 10000, 0, 255)); if (Par[1]<50) { // Using white
debugSerial<<F("W:")<<k<<endl; 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 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, rgb.r);
DmxWrite(iaddr + 1, rgb.g); DmxWrite(iaddr + 1, rgb.g);
DmxWrite(iaddr + 2, rgb.b); DmxWrite(iaddr + 2, rgb.b);
@@ -569,7 +653,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, char * subItem
while (i) { while (i) {
Item it(i->valuestring); Item it(i->valuestring);
// it.copyPar(itemVal); // it.copyPar(itemVal);
it.Ctrl(cmd, n, Par, send); //// was true it.Ctrl(cmd, n, Par, send,subItemN); //// was true
i = i->next; i = i->next;
} //while } //while
} //if } //if
@@ -577,17 +661,29 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, char * subItem
break; break;
case CH_RELAY: { case CH_RELAY: {
int k; int k;
short inverse = 0;
if (iaddr < 0) {
iaddr = -iaddr;
inverse = 1;
}
pinMode(iaddr, OUTPUT); pinMode(iaddr, OUTPUT);
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)); digitalWrite(iaddr, k = ((cmd == CMD_ON || cmd == CMD_XON) ? HIGH : LOW));
debugSerial<<F("Pin:")<<iaddr<<F("=")<<k<<endl; debugSerial<<F("Pin:")<<iaddr<<F("=")<<k<<endl;
break; break;
case CH_THERMO:
///thermoSet(name,cmd,Par1); all cativities done - update temp & cmd
break;
} }
case CH_THERMO:
///thermoSet(name,cmd,Par1); all activities done - update temp & cmd
break;
case CH_PWM: { case CH_PWM: {
int k; int k;
short inverse = 0; short inverse = 0;
if (iaddr < 0) { if (iaddr < 0) {
iaddr = -iaddr; iaddr = -iaddr;
inverse = 1; inverse = 1;
@@ -959,12 +1055,14 @@ int Item::checkFM() {
else aJson.addNumberToObject(out, "pwr", 0); else aJson.addNumberToObject(out, "pwr", 0);
if (ftemp > FM_OVERHEAT_CELSIUS && set) { if (ftemp > FM_OVERHEAT_CELSIUS && set) {
if (mqttClient.connected() && !ethernetIdleCount)
mqttClient.publish("/alarm/ovrht", itemArr->name); mqttClient.publish("/alarm/ovrht", itemArr->name);
Ctrl(CMD_OFF); //Shut down Ctrl(CMD_OFF); //Shut down
} }
} else } else
debugSerial << F("Modbus polling error=") << _HEX(result); debugSerial << F("Modbus polling error=") << _HEX(result);
outch = aJson.print(out); outch = aJson.print(out);
if (mqttClient.connected() && !ethernetIdleCount)
mqttClient.publish(addrstr, outch); mqttClient.publish(addrstr, outch);
free(outch); free(outch);
aJson.deleteItem(out); aJson.deleteItem(out);
@@ -1204,6 +1302,7 @@ int Item::SendStatus(short cmd, short n, int *Par, boolean deffered) {
return -1; return -1;
} }
debugSerial<<F("Pub: ")<<addrstr<<F("->")<<valstr<<endl; debugSerial<<F("Pub: ")<<addrstr<<F("->")<<valstr<<endl;
if (mqttClient.connected() && !ethernetIdleCount)
mqttClient.publish(addrstr, valstr,true); mqttClient.publish(addrstr, valstr,true);
return 0; return 0;
} }

View File

@@ -19,6 +19,17 @@ e-mail anklimov@gmail.com
*/ */
#include "options.h" #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_DIMMER 0 //DMX 1 ch
#define CH_RGBW 1 //DMX 4 ch #define CH_RGBW 1 //DMX 4 ch
#define CH_RGB 2 //DMX 3 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_AC_HAIER 10 //AC Haier
#define CH_WHITE 127// #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_ON 1
#define CMD_OFF 2 #define CMD_OFF 2
#define CMD_RESTORE 3 //on only if was turned off by CMD_HALT #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_HALT 5 //just Off
#define CMD_XON 6 //just on #define CMD_XON 6 //just on
#define CMD_XOFF 7 //off only if was previously turned on by CMD_XON #define CMD_XOFF 7 //off only if was previously turned on by CMD_XON
#define CMD_UP 8 //just on #define CMD_UP 8 //increase
#define CMD_DN 9 //off only if was previously turned on by CMD_XON #define CMD_DN 9 //decrease
#define CMD_SET 0xe #define CMD_SET 0xe
#define CMD_MASK 0xf #define CMD_MASK 0xf
@@ -68,6 +85,7 @@ e-mail anklimov@gmail.com
#include "aJSON.h" #include "aJSON.h"
extern aJsonObject *items; extern aJsonObject *items;
extern short thermoSetCurTemp(char *name, float t);
int txt2cmd (char * payload); int txt2cmd (char * payload);
@@ -105,7 +123,7 @@ class Item
Item(char * name); Item(char * name);
Item(aJsonObject * obj); Item(aJsonObject * obj);
boolean isValid (); 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); virtual int Ctrl(char * payload, boolean send=true, char * subItem=NULL);
int getArg(short n=0); int getArg(short n=0);
@@ -117,9 +135,9 @@ class Item
//void setVal(uint8_t n, int par); //void setVal(uint8_t n, int par);
void setVal(long int par); void setVal(long int par);
//void copyPar (aJsonObject *itemV); //void copyPar (aJsonObject *itemV);
inline int On (){Ctrl(CMD_ON);}; inline int On (){return Ctrl(CMD_ON);};
inline int Off(){Ctrl(CMD_OFF);}; inline int Off(){return Ctrl(CMD_OFF);};
inline int Toggle(){Ctrl(CMD_TOGGLE);}; inline int Toggle(){return Ctrl(CMD_TOGGLE);};
int Poll(); int Poll();
int SendStatus(short cmd, short n=0, int * Par=NULL, boolean deferred = false); int SendStatus(short cmd, short n=0, int * Par=NULL, boolean deferred = false);

View File

@@ -79,26 +79,26 @@ EthernetClient ethClient;
#ifdef ARDUINO_ARCH_ESP8266 #ifdef ARDUINO_ARCH_ESP8266
WiFiClient ethClient; WiFiClient ethClient;
#if not defined(WIFI_MANAGER_DISABLE)
WiFiManager wifiManager;
#endif
#endif #endif
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
WiFiClient ethClient; WiFiClient ethClient;
NRFFlashStorage EEPROM; NRFFlashStorage EEPROM;
#if not defined(WIFI_MANAGER_DISABLE)
WiFiManager wifiManager;
#endif #endif
#ifdef ARDUINO_ARCH_STM32F1 #endif
#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>
#ifdef ARDUINO_ARCH_STM32
EthernetClient ethClient; EthernetClient ethClient;
NRFFlashStorage EEPROM;
#endif #endif
#ifdef NRF5 #ifdef NRF5
@@ -117,6 +117,7 @@ lan_status lanStatus = INITIAL_STATE;
const char configserver[] PROGMEM = CONFIG_SERVER; const char configserver[] PROGMEM = CONFIG_SERVER;
const char verval_P[] PROGMEM = QUOTE(PIO_SRC_REV);
unsigned int UniqueID[5] = {0,0,0,0,0}; unsigned int UniqueID[5] = {0,0,0,0,0};
@@ -140,15 +141,17 @@ aJsonObject *dmxArr = NULL;
aJsonObject *udpSyslogArr = NULL; aJsonObject *udpSyslogArr = NULL;
#endif #endif
unsigned long nextPollingCheck = 0; uint32_t nextPollingCheck = 0;
unsigned long nextInputCheck = 0; uint32_t nextInputCheck = 0;
unsigned long nextLanCheckTime = 0; uint32_t nextLanCheckTime = 0;
unsigned long nextThermostatCheck = 0; uint32_t nextThermostatCheck = 0;
uint32_t nextSensorCheck =0;
aJsonObject *pollingItem = NULL; aJsonObject *pollingItem = NULL;
bool owReady = false; bool owReady = false;
bool configOk = false; bool configOk = false;
int8_t ethernetIdleCount =0;
#ifdef _modbus #ifdef _modbus
ModbusMaster node; ModbusMaster node;
@@ -166,6 +169,28 @@ int mqttErrorRate;
void watchdogSetup(void) {} //Do not remove - strong re-definition WDT Init for DUE void watchdogSetup(void) {} //Do not remove - strong re-definition WDT Init for DUE
#endif #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) { void mqttCallback(char *topic, byte *payload, unsigned int length) {
debugSerial<<F("\n[")<<topic<<F("] "); debugSerial<<F("\n[")<<topic<<F("] ");
if (!payload) return; if (!payload) return;
@@ -246,7 +271,7 @@ else
void printMACAddress() { void printMACAddress() {
debugSerial<<F("Configured MAC:"); debugSerial<<F("MAC:");
for (byte i = 0; i < 6; i++) for (byte i = 0; i < 6; i++)
#ifdef WITH_PRINTEX_LIB #ifdef WITH_PRINTEX_LIB
(i < 5) ?debugSerial<<hex <<(mac[i])<<F(":"):debugSerial<<hex<<(mac[i])<<endl; (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__) #if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__)
wdt_dis(); wdt_dis();
if (lanStatus > 0) if (lanStatus > 0)
@@ -385,6 +418,7 @@ void onMQTTConnect(){
setTopic(topic,sizeof(topic),T_DEV); setTopic(topic,sizeof(topic),T_DEV);
strncat_P(topic, name_P, sizeof(topic)); strncat_P(topic, name_P, sizeof(topic));
strncpy_P(buf, nameval_P, sizeof(buf)); strncpy_P(buf, nameval_P, sizeof(buf));
strncat_P(buf,(verval_P),sizeof(buf));
mqttClient.publish(topic,buf,true); mqttClient.publish(topic,buf,true);
//strncpy_P(topic, outprefix, sizeof(topic)); //strncpy_P(topic, outprefix, sizeof(topic));
@@ -407,8 +441,8 @@ void onMQTTConnect(){
aJsonObject * item = items->child; aJsonObject * item = items->child;
while (items && item) while (items && item)
if (item->type == aJson_Array && aJson.getArraySize(item)>0) { if (item->type == aJson_Array && aJson.getArraySize(item)>0) {
strncat(buf,item->name,sizeof(buf)); /// strncat(buf,item->name,sizeof(buf));
strncat(buf,",",sizeof(buf)); /// strncat(buf,",",sizeof(buf));
switch ( aJson.getArrayItem(item, I_TYPE)->valueint) { switch ( aJson.getArrayItem(item, I_TYPE)->valueint) {
case CH_THERMO: case CH_THERMO:
@@ -460,7 +494,7 @@ void onMQTTConnect(){
//strncpy_P(topic, outprefix, sizeof(topic)); //strncpy_P(topic, outprefix, sizeof(topic));
setTopic(topic,sizeof(topic),T_DEV); setTopic(topic,sizeof(topic),T_DEV);
strncat_P(topic, nodes_P, sizeof(topic)); strncat_P(topic, nodes_P, sizeof(topic));
mqttClient.publish(topic,buf,true); /// mqttClient.publish(topic,buf,true);
} }
#endif #endif
} }
@@ -474,8 +508,11 @@ void ip_ready_config_loaded_connecting_to_broker() {
char *password = passwordBuf; char *password = passwordBuf;
int syslogPort = 514; int syslogPort = 514;
char syslogDeviceHostname[16]; 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 #ifdef SYSLOG_ENABLE
//debugSerial<<"debugSerial:"; //debugSerial<<"debugSerial:";
delay(100); 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(" ..."); 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)) { if (mqttClient.connect(deviceName, user, password,willTopic,MQTTQOS1,true,willMessage)) {
mqttErrorRate = 0; mqttErrorRate = 0;
debugSerial<<F("connected as ")<<deviceName <<endl; debugSerial<<F("connected as ")<<deviceName <<endl;
wdt_en(); // wdt_en();
configOk = true; configOk = true;
// ... Temporary subscribe to status topic // ... Temporary subscribe to status topic
char buf[MQTT_TOPIC_LENGTH]; char buf[MQTT_TOPIC_LENGTH];
@@ -577,21 +614,44 @@ void ip_ready_config_loaded_connecting_to_broker() {
} }
void onInitialStateInitLAN() { void onInitialStateInitLAN() {
#if defined(ARDUINO_ARCH_ESP8266) and defined(WIFI_MANAGER_DISABLE) #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
if(!wifiInitialized) { #if defined(WIFI_MANAGER_DISABLE)
WiFi.mode(WIFI_STA); if(WiFi.status() != WL_CONNECTED) {
debugSerial<<F("WIFI AP/Password:")<<QUOTE(ESP_WIFI_AP)<<F("/")<<QUOTE(ESP_WIFI_PWD); WiFi.mode(WIFI_STA); // ESP 32 - WiFi.disconnect(); instead
wifi_set_macaddr(STATION_IF,mac); 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)); 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; 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 #endif
#ifdef ARDUINO_ARCH_ESP32 /*
#if defined(ARDUINO_ARCH_ESP32) and defined(WIFI_MANAGER_DISABLE)
if(!wifiInitialized) { if(!wifiInitialized) {
// WiFi.mode(WIFI_STA); // WiFi.mode(WIFI_STA);
WiFi.disconnect(); 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)); WiFi.begin(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD));
int wifi_connection_wait = 10000; int wifi_connection_wait = 10000;
@@ -603,19 +663,20 @@ void onInitialStateInitLAN() {
wifiInitialized = true; wifiInitialized = true;
} }
#endif #endif
*/
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
if (WiFi.status() == WL_CONNECTED) { 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; lanStatus = HAVE_IP_ADDRESS;//1;
} else } else
{ {
debugSerial<<F("Problem with WiFi!"); debugSerial<<F("Problem with WiFi!");
nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL/5; nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL;
} }
#endif #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 #ifdef W5500_CS_PIN
Ethernet.w5500_cspin = W5500_CS_PIN; Ethernet.w5500_cspin = W5500_CS_PIN;
debugSerial<<F("Use W5500 pin: "); debugSerial<<F("Use W5500 pin: ");
@@ -649,7 +710,7 @@ void onInitialStateInitLAN() {
#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__) #if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__)
res = Ethernet.begin(mac, 12000); res = Ethernet.begin(mac, 12000);
#endif #endif
#if defined(ARDUINO_ARCH_STM32F1) #if defined(ARDUINO_ARCH_STM32)
res = Ethernet.begin(mac); res = Ethernet.begin(mac);
#endif #endif
wdt_en(); wdt_en();
@@ -675,25 +736,6 @@ void onInitialStateInitLAN() {
#endif #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() { void resetHard() {
#ifdef RESET_PIN #ifdef RESET_PIN
@@ -719,7 +761,7 @@ void Changed(int i, DeviceAddress addr, float currentTemp) {
SetBytes(addr, 8, addrstr); SetBytes(addr, 8, addrstr);
addrstr[17] = 0; addrstr[17] = 0;
if (!root) return;
printFloatValueToStr(currentTemp,valstr); printFloatValueToStr(currentTemp,valstr);
debugSerial<<endl<<F("T:")<<valstr<<F("<"); debugSerial<<endl<<F("T:")<<valstr<<F("<");
aJsonObject *owObj = aJson.getObjectItem(owArr, addrstr); aJsonObject *owObj = aJson.getObjectItem(owArr, addrstr);
@@ -738,6 +780,7 @@ void Changed(int i, DeviceAddress addr, float currentTemp) {
char valstr[50]; char valstr[50];
sprintf(valstr, "{\"idx\":%s,\"svalue\":\"%.1f\"}", idx->valuestring, currentTemp); sprintf(valstr, "{\"idx\":%s,\"svalue\":\"%.1f\"}", idx->valuestring, currentTemp);
debugSerial << valstr; debugSerial << valstr;
if (mqttClient.connected() && !ethernetIdleCount)
mqttClient.publish(owEmitString, valstr); mqttClient.publish(owEmitString, valstr);
return; return;
} }
@@ -746,6 +789,7 @@ void Changed(int i, DeviceAddress addr, float currentTemp) {
//strcpy_P(addrstr, outprefix); //strcpy_P(addrstr, outprefix);
setTopic(addrstr,sizeof(addrstr),T_OUT); setTopic(addrstr,sizeof(addrstr),T_OUT);
strncat(addrstr, owEmitString, sizeof(addrstr)); strncat(addrstr, owEmitString, sizeof(addrstr));
if (mqttClient.connected() && !ethernetIdleCount)
mqttClient.publish(addrstr, valstr); mqttClient.publish(addrstr, valstr);
} }
// And translate temp to internal items // And translate temp to internal items
@@ -796,12 +840,11 @@ void cmdFunctionKill(int arg_cnt, char **args) {
void cmdFunctionReboot(int arg_cnt, char **args) { void cmdFunctionReboot(int arg_cnt, char **args) {
debugSerial<<F("Soft rebooting..."); debugSerial<<F("Soft rebooting...");
//// softRebootFunc(); softRebootFunc();
} }
void applyConfig() { void applyConfig() {
if (!root) return; if (!root) return;
#ifdef _dmxin #ifdef _dmxin
int itemsCount; int itemsCount;
dmxArr = aJson.getObjectItem(root, "dmxin"); dmxArr = aJson.getObjectItem(root, "dmxin");
@@ -815,7 +858,7 @@ void applyConfig() {
aJsonObject *dmxoutArr = aJson.getObjectItem(root, "dmx"); aJsonObject *dmxoutArr = aJson.getObjectItem(root, "dmx");
if (dmxoutArr && aJson.getArraySize(dmxoutArr) >=1 ) { if (dmxoutArr && aJson.getArraySize(dmxoutArr) >=1 ) {
DMXoutSetup(maxChannels = aJson.getArrayItem(dmxoutArr, 1)->valueint); DMXoutSetup(maxChannels = aJson.getArrayItem(dmxoutArr, 1)->valueint);
debugSerial<<F("DMX out started. Channels: ")<<maxChannels; debugSerial<<F("DMX out started. Channels: ")<<maxChannels<<endl;
} }
#endif #endif
#ifdef _modbus #ifdef _modbus
@@ -851,7 +894,9 @@ void applyConfig() {
if (item->type == aJson_Array && aJson.getArraySize(item)>1) { if (item->type == aJson_Array && aJson.getArraySize(item)>1) {
Item it(item); Item it(item);
if (it.isValid()) { if (it.isValid()) {
short inverse = 0;
int pin=it.getArg(); int pin=it.getArg();
if (pin<0) {pin=-pin; inverse = 1;}
int cmd = it.getCmd(); int cmd = it.getCmd();
switch (it.itemType) { switch (it.itemType) {
case CH_THERMO: case CH_THERMO:
@@ -860,6 +905,9 @@ void applyConfig() {
{ {
int k; int k;
pinMode(pin, OUTPUT); pinMode(pin, OUTPUT);
if (inverse)
digitalWrite(pin, k = ((cmd == CMD_ON) ? LOW : HIGH));
else
digitalWrite(pin, k = ((cmd == CMD_ON) ? HIGH : LOW)); digitalWrite(pin, k = ((cmd == CMD_ON) ? HIGH : LOW));
debugSerial<<F("Pin:")<<pin<<F("=")<<k<<F(","); debugSerial<<F("Pin:")<<pin<<F("=")<<k<<F(",");
} }
@@ -872,6 +920,8 @@ void applyConfig() {
} }
inputs = aJson.getObjectItem(root, "in"); inputs = aJson.getObjectItem(root, "in");
mqttArr = aJson.getObjectItem(root, "mqtt"); mqttArr = aJson.getObjectItem(root, "mqtt");
inputSetup();
#ifdef SYSLOG_ENABLE #ifdef SYSLOG_ENABLE
udpSyslogArr = aJson.getObjectItem(root, "syslog"); udpSyslogArr = aJson.getObjectItem(root, "syslog");
#endif #endif
@@ -898,6 +948,7 @@ void printConfigSummary() {
printBool(udpSyslogArr); printBool(udpSyslogArr);
#endif #endif
debugSerial << endl; debugSerial << endl;
debugSerial<<F("RAM=")<<freeRam()<<endl;
} }
void cmdFunctionLoad(int arg_cnt, char **args) { void cmdFunctionLoad(int arg_cnt, char **args) {
@@ -905,26 +956,27 @@ void cmdFunctionLoad(int arg_cnt, char **args) {
// restoreState(); // restoreState();
} }
int loadConfigFromEEPROM() int loadConfigFromEEPROM()
{ {
char ch; char ch;
debugSerial<<F("loading Config"); debugSerial<<F("Loading Config from EEPROM")<<endl;
ch = EEPROM.read(EEPROM_offset); ch = EEPROM.read(EEPROM_offset);
if (ch == '{') { if (ch == '{') {
aJsonEEPROMStream as = aJsonEEPROMStream(EEPROM_offset); aJsonEEPROMStream as = aJsonEEPROMStream(EEPROM_offset);
aJson.deleteItem(root); cleanConf();
root = aJson.parse(&as); root = aJson.parse(&as);
if (!root) { if (!root) {
debugSerial<<F("\nload failed"); debugSerial<<F("load failed")<<endl;
return 0; return 0;
} }
debugSerial<<F("\nLoaded\n"); debugSerial<<F("Loaded")<<endl;
applyConfig(); applyConfig();
ethClient.stop(); //Refresh MQTT connect to get retained info ethClient.stop(); //Refresh MQTT connect to get retained info
return 1; return 1;
} else { } else {
debugSerial<<F("\nNo stored config\n"); debugSerial<<F("No stored config")<<endl;
return 0; return 0;
} }
return 0; return 0;
@@ -949,6 +1001,7 @@ int mqttConfigRequest(int arg_cnt, char **args)
strncat(buf, "/req/conf", 25); strncat(buf, "/req/conf", 25);
debugSerial<<buf; debugSerial<<buf;
mqttClient.publish(buf, "1"); mqttClient.publish(buf, "1");
return 1;
} }
@@ -957,7 +1010,7 @@ int mqttConfigResp(char *as) {
root = aJson.parse(as); root = aJson.parse(as);
if (!root) { if (!root) {
debugSerial<<F("\nload failed"); debugSerial<<F("\nload failed\n");
return 0; return 0;
} }
debugSerial<<F("\nLoaded"); debugSerial<<F("\nLoaded");
@@ -1003,6 +1056,7 @@ void cmdFunctionIp(int arg_cnt, char **args)
case 1: //dynamic IP case 1: //dynamic IP
saveFlash(OFFSET_IP,ip0); saveFlash(OFFSET_IP,ip0);
debugSerial<<F("Set dynamic IP\n");
/* /*
IPAddress current_ip = Ethernet.localIP(); IPAddress current_ip = Ethernet.localIP();
IPAddress current_mask = Ethernet.subnetMask(); IPAddress current_mask = Ethernet.subnetMask();
@@ -1107,10 +1161,8 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
#if defined(ARDUINO_ARCH_AVR) #if defined(ARDUINO_ARCH_AVR)
FILE *configStream; FILE *configStream;
//byte hserver[] = { 192,168,88,2 };
wdt_dis(); wdt_dis();
HTTPClient hclient(configServer, 80); HTTPClient hclient(configServer, 80);
HTTPClient hclientPrint(configServer, 80);
// FILE is the return STREAM type of the HTTPClient // FILE is the return STREAM type of the HTTPClient
configStream = hclient.getURI(URI); configStream = hclient.getURI(URI);
responseStatusCode = hclient.getLastReturnCode(); responseStatusCode = hclient.getLastReturnCode();
@@ -1123,10 +1175,9 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
char c; char c;
aJsonFileStream as = aJsonFileStream(configStream); aJsonFileStream as = aJsonFileStream(configStream);
noInterrupts(); noInterrupts();
aJson.deleteItem(root); cleanConf();
root = aJson.parse(&as); root = aJson.parse(&as);
interrupts(); interrupts();
// debugSerial<<F("Parsed."));
hclient.closeStream(configStream); // this is very important -- be sure to close the STREAM hclient.closeStream(configStream); // this is very important -- be sure to close the STREAM
if (!root) { if (!root) {
@@ -1134,12 +1185,9 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
nextLanCheckTime = millis() + 15000; nextLanCheckTime = millis() + 15000;
return READ_RE_CONFIG;//-11; return READ_RE_CONFIG;//-11;
} else { } else {
// char *outstr = aJson.print(root);
// debugSerial<<outstr);
// free(outstr);
debugSerial<<F("Applying.\n"); debugSerial<<F("Applying.\n");
applyConfig(); applyConfig();
debugSerial<<F("Done.\n");
} }
@@ -1157,7 +1205,7 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
return READ_RE_CONFIG;//-11; return READ_RE_CONFIG;//-11;
} }
#endif #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) #if defined(ARDUINO_ARCH_ESP32)
WiFiClient configEthClient; WiFiClient configEthClient;
#else #else
@@ -1170,10 +1218,11 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
wdt_res(); wdt_res();
//debugSerial<<"making GET request");get //debugSerial<<"making GET request");get
htclient.beginRequest(); htclient.beginRequest();
htclient.get(URI); responseStatusCode = htclient.get(URI);
htclient.endRequest(); htclient.endRequest();
if (responseStatusCode == HTTP_SUCCESS)
{
// read the status code and body of the response // read the status code and body of the response
responseStatusCode = htclient.responseStatusCode(); responseStatusCode = htclient.responseStatusCode();
response = htclient.responseBody(); response = htclient.responseBody();
@@ -1184,7 +1233,7 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
//debugSerial<<"GET Response: "); //debugSerial<<"GET Response: ");
if (responseStatusCode == 200) { if (responseStatusCode == 200) {
aJson.deleteItem(root); cleanConf();
root = aJson.parse((char *) response.c_str()); root = aJson.parse((char *) response.c_str());
if (!root) { if (!root) {
@@ -1193,11 +1242,16 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
} else { } else {
debugSerial<<response; debugSerial<<response;
applyConfig(); applyConfig();
debugSerial<<F("Done.\n");
} }
} else { } else {
debugSerial<<F("Config retrieving failed\n"); debugSerial<<F("Config retrieving failed\n");
return READ_RE_CONFIG;//-11; //Load from NVRAM return READ_RE_CONFIG;//-11; //Load from NVRAM
} }
} else {
debugSerial<<F("Connect failed\n");
return READ_RE_CONFIG;//-11; //Load from NVRAM
}
#endif #endif
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
HTTPClient httpClient; HTTPClient httpClient;
@@ -1211,7 +1265,7 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
if (httpResponseCode == HTTP_CODE_OK) { if (httpResponseCode == HTTP_CODE_OK) {
String response = httpClient.getString(); String response = httpClient.getString();
debugSerial<<response; debugSerial<<response;
aJson.deleteItem(root); cleanConf();
root = aJson.parse((char *) response.c_str()); root = aJson.parse((char *) response.c_str());
if (!root) { if (!root) {
debugSerial<<F("Config parsing failed\n"); debugSerial<<F("Config parsing failed\n");
@@ -1219,7 +1273,11 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
} else { } else {
debugSerial<<F("Config OK, Applying\n"); debugSerial<<F("Config OK, Applying\n");
applyConfig(); applyConfig();
debugSerial<<F("Done.\n");
} }
} else {
debugSerial<<F("Config retrieving failed\n");
return READ_RE_CONFIG;//-11; //Load from NVRAM
} }
} else { } else {
debugSerial.printf("[HTTP] GET... failed, error: %s\n", httpClient.errorToString(httpResponseCode).c_str()); debugSerial.printf("[HTTP] GET... failed, error: %s\n", httpClient.errorToString(httpResponseCode).c_str());
@@ -1256,10 +1314,16 @@ void setup_main() {
setupCmdArduino(); setupCmdArduino();
printFirmwareVersionAndBuildOptions(); printFirmwareVersionAndBuildOptions();
// scan_i2c_bus();
#ifdef SD_CARD_INSERTED #ifdef SD_CARD_INSERTED
sd_card_w5100_setup(); sd_card_w5100_setup();
#endif #endif
setupMacAddress(); setupMacAddress();
#if defined(ARDUINO_ARCH_ESP8266)
EEPROM.begin(ESP_EEPROM_SIZE);
#endif
loadConfigFromEEPROM(); loadConfigFromEEPROM();
#ifdef _modbus #ifdef _modbus
@@ -1281,7 +1345,7 @@ void setup_main() {
//owReady = 0; //owReady = 0;
#ifdef _owire #ifdef _owire
if (net) net->idle(&owIdle); if (oneWire) oneWire->idle(&owIdle);
#endif #endif
mqttClient.setCallback(mqttCallback); mqttClient.setCallback(mqttCallback);
@@ -1290,13 +1354,16 @@ void setup_main() {
ArtnetSetup(); ArtnetSetup();
#endif #endif
#if defined(ARDUINO_ARCH_ESP8266) and not defined(WIFI_MANAGER_DISABLE) #if (defined(ARDUINO_ARCH_ESP8266) or defined(ARDUINO_ARCH_ESP32)) and not defined(WIFI_MANAGER_DISABLE)
WiFiManager wifiManager; // WiFiManager wifiManager;
wifiManager.setTimeout(180);
#if defined(ESP_WIFI_AP) and defined(ESP_WIFI_PWD) #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 #else
wifiManager.autoConnect(); wifiInitialized = wifiManager.autoConnect();
#endif #endif
#endif #endif
delay(LAN_INIT_DELAY);//for LAN-shield initializing delay(LAN_INIT_DELAY);//for LAN-shield initializing
@@ -1378,6 +1445,7 @@ debugSerial<<endl;
// WDT_Disable( WDT ) ; // WDT_Disable( WDT ) ;
#if defined(__SAM3X8E__)
Serial.println(F("Reading 128 bits unique identifier") ) ; Serial.println(F("Reading 128 bits unique identifier") ) ;
ReadUniqueID( UniqueID ) ; ReadUniqueID( UniqueID ) ;
@@ -1386,7 +1454,7 @@ debugSerial<<endl;
for (byte b = 0 ; b < 4 ; b++) for (byte b = 0 ; b < 4 ; b++)
Serial.print ((unsigned int) UniqueID [b], HEX) ; Serial.print ((unsigned int) UniqueID [b], HEX) ;
Serial.println () ; Serial.println () ;
#endif
} }
@@ -1396,42 +1464,27 @@ void publishStat(){
long fr = freeRam(); long fr = freeRam();
char topic[64]; char topic[64];
char intbuf[16]; char intbuf[16];
long ut = millis()/1000; uint32_t ut = millis()/1000UL;
if (!mqttClient.connected()) return;
// debugSerial<<F("\nfree RAM: ")<<fr; // debugSerial<<F("\nfree RAM: ")<<fr;
setTopic(topic,sizeof(topic),T_DEV); setTopic(topic,sizeof(topic),T_DEV);
strncat_P(topic, stats_P, sizeof(topic)); strncat_P(topic, stats_P, sizeof(topic));
strncat(topic, "/", sizeof(topic)); strncat(topic, "/", sizeof(topic));
strncat_P(topic, freeheap_P, sizeof(topic)); strncat_P(topic, freeheap_P, sizeof(topic));
printUlongValueToStr(intbuf, fr);
mqttClient.publish(topic,itoa(fr,intbuf,10),true); mqttClient.publish(topic,intbuf,true);
setTopic(topic,sizeof(topic),T_DEV); setTopic(topic,sizeof(topic),T_DEV);
strncat_P(topic, stats_P, sizeof(topic)); strncat_P(topic, stats_P, sizeof(topic));
strncat(topic, "/", sizeof(topic)); strncat(topic, "/", sizeof(topic));
strncat_P(topic, uptime_P, sizeof(topic)); strncat_P(topic, uptime_P, sizeof(topic));
printUlongValueToStr(intbuf, ut);
mqttClient.publish(topic,itoa(ut,intbuf,10),true); mqttClient.publish(topic,intbuf,true);
} }
void setupMacAddress() { void setupMacAddress() {
#if defined(__SAM3X8E__) //Check MAC, stored in NVRAM
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; bool isMacValid = false;
for (short i = 0; i < 6; i++) { for (short i = 0; i < 6; i++) {
mac[i] = EEPROM.read(i); mac[i] = EEPROM.read(i);
@@ -1439,8 +1492,29 @@ for (byte b = 0 ; b < 4 ; b++)
} }
if (!isMacValid) { if (!isMacValid) {
debugSerial<<F("No MAC configured: set firmware's MAC\n"); debugSerial<<F("No MAC configured: set firmware's MAC\n");
memcpy(mac, firmwareMacAddress, 6);
#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(); printMACAddress();
} }
@@ -1521,8 +1595,10 @@ void owIdle(void) {
#endif #endif
} }
void ethernetIdle(void){ void ethernetIdle(void){
ethernetIdleCount++;
wdt_res(); wdt_res();
inputLoop(); inputLoop();
ethernetIdleCount--;
}; };
void modbusIdle(void) { void modbusIdle(void) {
@@ -1547,17 +1623,45 @@ void modbusIdle(void) {
void inputLoop(void) { void inputLoop(void) {
if (!inputs) return; if (!inputs) return;
if (millis() > nextInputCheck) { if (millis() > nextInputCheck) {
aJsonObject *input = inputs->child; aJsonObject *input = inputs->child;
while (input) { while (input) {
if ((input->type == aJson_Object)) { if ((input->type == aJson_Object)) {
Input in(input); Input in(input);
in.poll(); in.poll(CHECK_INPUT);
} }
input = input->next; input = input->next;
} }
nextInputCheck = millis() + INTERVAL_CHECK_INPUT; 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 #ifndef MODBUS_DISABLE
@@ -1595,6 +1699,7 @@ bool thermoDisabledOrDisconnected(aJsonObject *thermoExtensionArray, int thermoS
void thermoLoop(void) { void thermoLoop(void) {
if (millis() < nextThermostatCheck) if (millis() < nextThermostatCheck)
return; return;
if (!items) return;
bool thermostatCheckPrinted = false; bool thermostatCheckPrinted = false;
for (aJsonObject *thermoItem = items->child; thermoItem; thermoItem = thermoItem->next) { for (aJsonObject *thermoItem = items->child; thermoItem; thermoItem = thermoItem->next) {
if (isThermostatWithMinArraySize(thermoItem, 5)) { if (isThermostatWithMinArraySize(thermoItem, 5)) {
@@ -1618,17 +1723,19 @@ void thermoLoop(void) {
debugSerial << endl << thermoItem->name << F(" Set:") << thermoSetting << F(" Cur:") << curTemp debugSerial << endl << thermoItem->name << F(" Set:") << thermoSetting << F(" Cur:") << curTemp
<< F(" cmd:") << thermoStateCommand; << F(" cmd:") << thermoStateCommand;
pinMode(thermoPin, OUTPUT); if (thermoPin<0) pinMode(-thermoPin, OUTPUT); else pinMode(thermoPin, OUTPUT);
if (thermoDisabledOrDisconnected(thermoExtensionArray, thermoStateCommand)) { 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"); debugSerial<<F(" OFF");
} else { } else {
if (curTemp < thermoSetting - THERMO_GIST_CELSIUS) { if (curTemp < thermoSetting - THERMO_GIST_CELSIUS) {
digitalWrite(thermoPin, HIGH); if (thermoPin<0) digitalWrite(-thermoPin, LOW); digitalWrite(thermoPin, HIGH);
debugSerial<<F(" ON"); debugSerial<<F(" ON");
} //too cold } //too cold
else if (curTemp >= thermoSetting) { else if (curTemp >= thermoSetting) {
digitalWrite(thermoPin, LOW); if (thermoPin<0) digitalWrite(-thermoPin, HIGH); digitalWrite(thermoPin, LOW);
debugSerial<<F(" OFF"); debugSerial<<F(" OFF");
} //Reached settings } //Reached settings
else debugSerial<<F(" -target zone-"); // Nothing to do else debugSerial<<F(" -target zone-"); // Nothing to do
@@ -1641,15 +1748,17 @@ void thermoLoop(void) {
nextThermostatCheck = millis() + THERMOSTAT_CHECK_PERIOD; nextThermostatCheck = millis() + THERMOSTAT_CHECK_PERIOD;
publishStat(); publishStat();
#ifndef DISABLE_FREERAM_PRINT #ifndef DISABLE_FREERAM_PRINT
(thermostatCheckPrinted) ? debugSerial<<F("\nfree:")<<freeRam()<<" " : debugSerial<<F(" ")<<freeRam()<<F(" "); (thermostatCheckPrinted) ? debugSerial<<F("\nRAM=")<<freeRam()<<" " : debugSerial<<F(" ")<<freeRam()<<F(" ");
#endif #endif
} }
short thermoSetCurTemp(char *name, float t) { short thermoSetCurTemp(char *name, float t) {
if (!name || !strlen(name)) return 0;
if (items) { if (items) {
aJsonObject *thermoItem = aJson.getObjectItem(items, name); aJsonObject *thermoItem = aJson.getObjectItem(items, name);
if (!thermoItem) return 0;
if (isThermostatWithMinArraySize(thermoItem, 4)) { if (isThermostatWithMinArraySize(thermoItem, 4)) {
aJsonObject *extArray = NULL; aJsonObject *extArray = NULL;
@@ -1670,5 +1779,5 @@ short thermoSetCurTemp(char *name, float t) {
att->valueint = (int) T_ATTEMPTS; att->valueint = (int) T_ATTEMPTS;
} }
} }
} return 1;}
} return 0;}

View File

@@ -16,13 +16,14 @@
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
#include <FS.h> //this needs to be first, or it all crashes and burns... #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 <ESP8266HTTPClient.h>
#include <WiFiManager.h> #include <WiFiManager.h>
#include <DNSServer.h> #include <DNSServer.h>
#include <ESP8266WebServer.h> #include <ESP8266WebServer.h>
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <user_interface.h> #include <user_interface.h>
#define Ethernet WiFi
#endif #endif
#if defined ARDUINO_ARCH_ESP32 #if defined ARDUINO_ARCH_ESP32
@@ -44,14 +45,15 @@
#include <NRFFlashStorage.h> #include <NRFFlashStorage.h>
#endif #endif
#if defined(__SAM3X8E__) #ifdef ARDUINO_ARCH_STM32
#define wdt_res() watchdogReset() #include "HttpClient.h"
#define wdt_en() #include "UIPEthernet.h"
#define wdt_dis() #include <NRFFlashStorage.h>
//#include <EEPROM.h>
#endif #endif
#if defined(ARDUINO_ARCH_STM32F1) #if defined(__SAM3X8E__)
#define wdt_res() #define wdt_res() watchdogReset()
#define wdt_en() #define wdt_en()
#define wdt_dis() #define wdt_dis()
#endif #endif
@@ -78,6 +80,12 @@
#define wdt_dis() #define wdt_dis()
#endif #endif
#if defined(ARDUINO_ARCH_STM32)
#define wdt_res()
#define wdt_en()
#define wdt_dis()
#endif
//#if defined(ESP8266) //#if defined(ESP8266)
//#define wdt_res() //#define wdt_res()
//#define wdt_en() //#define wdt_en()
@@ -224,6 +232,8 @@ void modbusIdle(void);
void inputLoop(void); void inputLoop(void);
void inputSetup(void);
void pollingLoop(void); void pollingLoop(void);
void thermoLoop(void); void thermoLoop(void);

View File

@@ -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

View File

@@ -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

View File

@@ -4,6 +4,7 @@
#endif #endif
#define TXEnablePin 13 #define TXEnablePin 13
#define ESP_EEPROM_SIZE 2048
#ifndef AVR_DMXOUT_PIN #ifndef AVR_DMXOUT_PIN
#define AVR_DMXOUT_PIN 3 #define AVR_DMXOUT_PIN 3
@@ -18,7 +19,7 @@
#define FM_OVERHEAT_CELSIUS 40. #define FM_OVERHEAT_CELSIUS 40.
#define MIN_VOLUME 10 #define MIN_VOLUME 10
#define INIT_VOLUME 30 #define INIT_VOLUME 50
#define OFFSET_MAC 0 #define OFFSET_MAC 0
#define OFFSET_IP OFFSET_MAC+6 #define OFFSET_IP OFFSET_MAC+6
@@ -32,6 +33,11 @@
#ifndef INTERVAL_CHECK_INPUT #ifndef INTERVAL_CHECK_INPUT
#define INTERVAL_CHECK_INPUT 50 #define INTERVAL_CHECK_INPUT 50
#endif #endif
#ifndef INTERVAL_CHECK_SENSOR
#define INTERVAL_CHECK_SENSOR 5000
#endif
#define INTERVAL_CHECK_MODBUS 2000 #define INTERVAL_CHECK_MODBUS 2000
#define INTERVAL_POLLING 100 #define INTERVAL_POLLING 100
#define THERMOSTAT_CHECK_PERIOD 5000 #define THERMOSTAT_CHECK_PERIOD 5000
@@ -66,7 +72,7 @@
#endif #endif
#ifndef HOMETOPIC #ifndef HOMETOPIC
#define HOMETOPIC "/myhome" #define HOMETOPIC "myhome"
#endif #endif
/* /*
#ifndef OUTTOPIC #ifndef OUTTOPIC
@@ -98,7 +104,7 @@
#endif #endif
#define MQTT_SUBJECT_LENGTH 20 #define MQTT_SUBJECT_LENGTH 20
#define MQTT_TOPIC_LENGTH 20 #define MQTT_TOPIC_LENGTH 64
#ifndef DMX_DISABLE #ifndef DMX_DISABLE
#define _dmxin #define _dmxin
@@ -138,6 +144,13 @@
#define dmxin DmxDue1 #define dmxin DmxDue1
#endif #endif
#if defined(NRF5)
//#define modbusSerial Serial1
#undef _dmxin
#undef _dmxout
#undef _modbus
#endif
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
#undef _dmxin #undef _dmxin
#undef _modbus #undef _modbus

View File

@@ -26,7 +26,7 @@ e-mail anklimov@gmail.com
#include "options.h" #include "options.h"
OneWire *net = NULL; OneWire *oneWire = NULL;
DeviceAddress *term = NULL; DeviceAddress *term = NULL;
@@ -46,12 +46,12 @@ int owUpdate() {
Serial.println(F("Searching")); 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 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; 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++) for (short i = 0; i < t_count; i++)
if (!memcmp(term[i], term[t_count], 8)) { if (!memcmp(term[i], term[t_count], 8)) {
ifind = i; ifind = i;
@@ -68,7 +68,7 @@ int owUpdate() {
debugSerial.println(); debugSerial.println();
if (term[t_count][0] == 0x28) { if (term[t_count][0] == 0x28) {
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION); sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
net->setStrongPullup(); oneWire->setStrongPullup();
// sensors.requestTemperaturesByAddress(term[t_count]); // sensors.requestTemperaturesByAddress(term[t_count]);
} }
t_count++; t_count++;
@@ -84,20 +84,20 @@ int owUpdate() {
int owSetup(owChangedType owCh) { int owSetup(owChangedType owCh) {
#ifndef OWIRE_DISABLE #ifndef OWIRE_DISABLE
//// todo - move memory allocation to here //// 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 #ifdef DS2482_100_I2C_TO_1W_BRIDGE
debugSerial<<F("DS2482_100_I2C_TO_1W_BRIDGE init"); debugSerial<<F("DS2482_100_I2C_TO_1W_BRIDGE init")<<endl;
net = new OneWire; oneWire = new OneWire;
#else #else
debugSerial.print(F("One wire setup on PIN:")); debugSerial.print(F("One wire setup on PIN:"));
debugSerial.println(QUOTE(USE_1W_PIN)); debugSerial.println(QUOTE(USE_1W_PIN));
net = new OneWire (USE_1W_PIN); oneWire = new OneWire (USE_1W_PIN);
#endif #endif
// Pass our oneWire reference to Dallas Temperature. // Pass our oneWire reference to Dallas Temperature.
sensors = new DallasTemperature(net); sensors = new DallasTemperature(oneWire);
term = new DeviceAddress[t_max]; term = new DeviceAddress[t_max];
//regs = new int [t_max]; //regs = new int [t_max];
@@ -106,17 +106,17 @@ int owSetup(owChangedType owCh) {
#ifdef DS2482_100_I2C_TO_1W_BRIDGE #ifdef DS2482_100_I2C_TO_1W_BRIDGE
Wire.begin(); Wire.begin();
if (net->checkPresence()) { if (oneWire->checkPresence()) {
debugSerial.println(F("DS2482-100 present")); debugSerial.println(F("DS2482-100 present"));
net->deviceReset(); oneWire->deviceReset();
#ifdef APU_OFF #ifdef APU_OFF
debugSerial.println(F("APU off")); debugSerial.println(F("APU off"));
#else #else
net->setActivePullup(); oneWire->setActivePullup();
#endif #endif
debugSerial.println(F("\tChecking for 1-Wire devices...")); debugSerial.println(F("\tChecking for 1-Wire devices..."));
if (net->wireReset()) if (oneWire->wireReset())
debugSerial.println(F("\tReset done")); debugSerial.println(F("\tReset done"));
sensors->begin(); sensors->begin();
@@ -191,7 +191,7 @@ void owAdd(DeviceAddress addr) {
debugSerial.println(); debugSerial.println();
if (term[t_count][0] == 0x28) { if (term[t_count][0] == 0x28) {
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION); sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
net->setStrongPullup(); oneWire->setStrongPullup();
// sensors.requestTemperaturesByAddress(term[t_count]); // sensors.requestTemperaturesByAddress(term[t_count]);
} }
t_count++; t_count++;

View File

@@ -70,7 +70,7 @@ typedef void (*owChangedType) (int , DeviceAddress, float) ;
#include <Wire.h> #include <Wire.h>
#endif #endif
extern OneWire *net; extern OneWire *oneWire;
extern DallasTemperature *sensors; extern DallasTemperature *sensors;
extern DeviceAddress *term ; extern DeviceAddress *term ;

View File

@@ -21,8 +21,9 @@ e-mail anklimov@gmail.com
#include "utils.h" #include "utils.h"
#include "options.h" #include "options.h"
#include "stdarg.h" #include "stdarg.h"
#include <wire.h>
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32F1) #if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32)
#include <malloc.h> #include <malloc.h>
#endif #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) { 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); int ch = atoi(*chan);
*chan = strchr(*chan, ',');
//Move pointer to next element (after ,)
*chan = strchr(*chan, ',');
if (*chan) *chan += 1; if (*chan) *chan += 1;
//Serial.print(F("Par:")); Serial.println(ch); //Serial.print(F("Par:")); Serial.println(ch);
return ch; return ch;
}
return 0;
} }
@@ -103,7 +111,7 @@ unsigned long freeRam ()
} }
#endif #endif
#if defined(ARDUINO_ARCH_STM32F1) #if defined(ARDUINO_ARCH_STM32)
extern char _end; extern char _end;
extern "C" char *sbrk(int i); 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(debugSerial))
#pragma message(VAR_NAME_VALUE(SERIAL_BAUD)) #pragma message(VAR_NAME_VALUE(SERIAL_BAUD))

View File

@@ -17,6 +17,8 @@ GIT: https://github.com/anklimov/lighthub
e-mail anklimov@gmail.com e-mail anklimov@gmail.com
*/ */
#pragma once
#define Q(x) #x #define Q(x) #x
#define QUOTE(x) Q(x) #define QUOTE(x) Q(x)
#define VALUE_TO_STRING(x) #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); char *inet_ntoa_r(IPAddress addr, char *buf, int buflen);
void printIPAddress(IPAddress ipAddress); void printIPAddress(IPAddress ipAddress);
char* setTopic(char* buf, int8_t buflen, topicType tt, char* suffix = NULL); 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();

View File

@@ -9,9 +9,8 @@
; http://docs.platformio.org/page/projectconf.html ; http://docs.platformio.org/page/projectconf.html
[platformio] [platformio]
src_dir = lighthub src_dir = lighthub
env_default = megaatmega2560-net
;monitor_speed = 115200 ;monitor_speed = 115200
;env_default = megaatmega2560-net
; megaatmega2560 ; megaatmega2560
; megaatmega2560-net ; megaatmega2560-net
; due ; due
@@ -21,13 +20,12 @@ env_default = megaatmega2560-net
; due-5500 ; due-5500
; controllino ; controllino
; stm32 ; stm32
; esp32-evb ; nrf52840
; nrf52840_dk
;build_dir = /tmp/pioenvs ;build_dir = /tmp/pioenvs
;libdeps_dir = /tmp/piolibdeps ;libdeps_dir = /tmp/piolibdeps
[env:nrf52840_dk] [env:nrf52840]
platform = nordicnrf52 platform = nordicnrf52
board = nrf52840_dk board = nrf52840_dk
;upload_protocol = mbed ;upload_protocol = mbed
@@ -35,6 +33,7 @@ board = nrf52840_dk
framework = arduino framework = arduino
build_flags = !bash check_custom_build_flags_nrf52840.sh build_flags = !bash check_custom_build_flags_nrf52840.sh
lib_ignore = lib_ignore =
ESP_EEPROM
DmxSimple DmxSimple
DMXSerial DMXSerial
DmxDue DmxDue
@@ -47,17 +46,21 @@ lib_ignore =
httpClient httpClient
FastLED FastLED
ESPDMX ESPDMX
ESP-Dmx
DueFlashStorage DueFlashStorage
PrintEx PrintEx
DHT sensor library ;DHT sensor library
DHT sensor library for ESPx DHT sensor library for ESPx
Adafruit Unified Sensor ;Adafruit Unified Sensor
WebServer WebServer
UIPEthernet
;Adafruit_Sensor ;Adafruit_Sensor
ClosedCube HDC1080
SparkFun CCS811 Arduino Library
lib_deps = lib_deps =
https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire https://github.com/anklimov/DS2482_OneWire
Ethernet2 https://github.com/anklimov/Ethernet2
ESP8266HTTPClient ESP8266HTTPClient
https://github.com/anklimov/aJson https://github.com/anklimov/aJson
https://github.com/anklimov/CmdArduino https://github.com/anklimov/CmdArduino
@@ -65,14 +68,14 @@ lib_deps =
https://github.com/knolleary/pubsubclient.git https://github.com/knolleary/pubsubclient.git
; https://github.com/anklimov/Artnet.git ; https://github.com/anklimov/Artnet.git
; FastLED ; FastLED
; Adafruit Unified Sensor Adafruit Unified Sensor
; DHT sensor library for ESPx DHT sensor library
; DHT sensor library
Streaming Streaming
https://github.com/anklimov/NRFFlashStorage https://github.com/anklimov/NRFFlashStorage
; https://github.com/livello/PrintEx#is-select-redecl ; https://github.com/livello/PrintEx#is-select-redecl
[env:esp32] [env:esp32]
platform = espressif32 platform = espressif32
framework = arduino framework = arduino
@@ -93,32 +96,31 @@ lib_ignore =
HTTPClient HTTPClient
httpClient httpClient
EEPROM 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 Artnet
https://github.com/anklimov/Artnet.git HTTPClient
FastLED UIPEthernet
Adafruit Unified Sensor ESP_EEPROM
DHT sensor library for ESPx EEPROM
DHT sensor library
Wire
;WifiManager
;HTTPClient
;HttpClient
lib_deps = lib_deps =
https://github.com/ebenolson/WIFIMANAGER-ESP32.git https://github.com/ebenolson/WIFIMANAGER-ESP32.git
https://github.com/zhouhan0126/WebServer-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/aJson
https://github.com/anklimov/CmdArduino https://github.com/anklimov/CmdArduino
https://github.com/knolleary/pubsubclient.git https://github.com/knolleary/pubsubclient.git
Streaming Streaming
;ESP_EEPROM
https://github.com/anklimov/NRFFlashStorage 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] [env:due]
platform = atmelsam platform = atmelsam
framework = arduino framework = arduino
@@ -126,20 +128,24 @@ board = due
build_flags = !bash check_custom_build_flags_due.sh build_flags = !bash check_custom_build_flags_due.sh
lib_ignore = lib_ignore =
DHT sensor library for ESPx DHT sensor library for ESPx
ESP_EEPROM
DMXSerial DMXSerial
DmxSimple DmxSimple
httpClient httpClient
ESPDMX ESPDMX
ESP-Dmx
WifiManager WifiManager
Ethernet3 Ethernet3
NRFFlashStorage NRFFlashStorage
WebServer WebServer
UIPEthernet
EEPROM
lib_deps = lib_deps =
https://github.com/sebnil/DueFlashStorage https://github.com/sebnil/DueFlashStorage
https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire https://github.com/anklimov/DS2482_OneWire
https://github.com/anklimov/DmxDue https://github.com/anklimov/DmxDue
https://github.com/anklimov/ArduinoHttpClient ArduinoHttpClient
https://github.com/anklimov/aJson https://github.com/anklimov/aJson
https://github.com/anklimov/CmdArduino https://github.com/anklimov/CmdArduino
https://github.com/anklimov/ModbusMaster https://github.com/anklimov/ModbusMaster
@@ -153,7 +159,8 @@ lib_deps =
DHT sensor library DHT sensor library
https://github.com/arcao/Syslog.git https://github.com/arcao/Syslog.git
Streaming Streaming
ClosedCube HDC1080
SparkFun CCS811 Arduino Library
[env:megaatmega2560] [env:megaatmega2560]
platform = atmelavr platform = atmelavr
@@ -170,6 +177,8 @@ lib_ignore =
HTTPClient HTTPClient
NRFFlashStorage NRFFlashStorage
WebServer WebServer
UIPEthernet
ESP_EEPROM
lib_deps = lib_deps =
https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire https://github.com/anklimov/DS2482_OneWire
@@ -183,11 +192,13 @@ lib_deps =
https://github.com/knolleary/pubsubclient.git https://github.com/knolleary/pubsubclient.git
https://github.com/anklimov/Artnet.git https://github.com/anklimov/Artnet.git
FastLED FastLED
EEPROM ;EEPROM
Adafruit Unified Sensor Adafruit Unified Sensor
DHT sensor library DHT sensor library
https://github.com/arcao/Syslog.git https://github.com/arcao/Syslog.git
Streaming Streaming
ClosedCube HDC1080
SparkFun CCS811 Arduino Library
[env:esp8266] [env:esp8266]
platform = espressif8266 platform = espressif8266
@@ -202,8 +213,14 @@ lib_ignore =
SD SD
SdFat SdFat
httpClient httpClient
HTTPClient
ArduinoHttpClient
Ethernet3 Ethernet3
Ethernet2
Ethernet
NRFFlashStorage NRFFlashStorage
UIPEthernet
EEPROM
lib_deps = lib_deps =
https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire https://github.com/anklimov/DS2482_OneWire
@@ -221,6 +238,9 @@ lib_deps =
WifiManager WifiManager
https://github.com/arcao/Syslog.git https://github.com/arcao/Syslog.git
Streaming Streaming
ESP_EEPROM
ClosedCube HDC1080
SparkFun CCS811 Arduino Library
[env:megaatmega2560-net] [env:megaatmega2560-net]
platform = atmelavr platform = atmelavr
@@ -232,12 +252,15 @@ lib_ignore =
DHT sensor library for ESPx DHT sensor library for ESPx
DmxDue DmxDue
DueFlashStorage DueFlashStorage
ESPDMX
ESP-Dmx ESP-Dmx
WifiManager WifiManager
Ethernet3 Ethernet3
Ethernet2 Ethernet2
NRFFlashStorage NRFFlashStorage
WebServer WebServer
UIPEthernet
ESP_EEPROM
lib_deps = lib_deps =
https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire https://github.com/anklimov/DS2482_OneWire
@@ -255,6 +278,8 @@ lib_deps =
DHT sensor library DHT sensor library
https://github.com/arcao/Syslog.git https://github.com/arcao/Syslog.git
Streaming Streaming
ClosedCube HDC1080
SparkFun CCS811 Arduino Library
[env:due-5500] [env:due-5500]
platform = atmelsam platform = atmelsam
@@ -263,10 +288,9 @@ board = due
build_flags = !bash check_custom_build_flags_due-5500.sh build_flags = !bash check_custom_build_flags_due-5500.sh
lib_ignore = lib_ignore =
DHT sensor library for ESPx DHT sensor library for ESPx
https://github.com/anklimov/Ethernet ESPDMX
ESP-Dmx ESP-Dmx
DMXSerial DMXSerial
ESPDMX
WifiManager WifiManager
DmxSimple DmxSimple
httpClient httpClient
@@ -274,14 +298,16 @@ lib_ignore =
Ethernet3 Ethernet3
NRFFlashStorage NRFFlashStorage
WebServer WebServer
UIPEthernet
ESP_EEPROM
EEPROM
lib_deps = lib_deps =
https://github.com/sebnil/DueFlashStorage https://github.com/sebnil/DueFlashStorage
https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire https://github.com/anklimov/DS2482_OneWire
https://github.com/anklimov/DmxDue https://github.com/anklimov/DmxDue
https://github.com/anklimov/ArduinoHttpClient ArduinoHttpClient
https://github.com/anklimov/aJson https://github.com/anklimov/aJson
https://github.com/anklimov/CmdArduino https://github.com/anklimov/CmdArduino
https://github.com/anklimov/ModbusMaster https://github.com/anklimov/ModbusMaster
@@ -296,6 +322,8 @@ lib_deps =
https://github.com/arcao/Syslog.git https://github.com/arcao/Syslog.git
Streaming Streaming
https://github.com/livello/PrintEx#is-select-redecl https://github.com/livello/PrintEx#is-select-redecl
ClosedCube HDC1080
SparkFun CCS811 Arduino Library
[env:controllino] [env:controllino]
@@ -307,12 +335,15 @@ lib_ignore =
DHT sensor library for ESPx DHT sensor library for ESPx
DmxDue DmxDue
DueFlashStorage DueFlashStorage
ESPDMX
ESP-Dmx ESP-Dmx
WifiManager WifiManager
Ethernet3 Ethernet3
Ethernet2 Ethernet2
NRFFlashStorage NRFFlashStorage
WebServer WebServer
UIPEthernet
ESP_EEPROM
lib_deps = lib_deps =
https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire https://github.com/anklimov/DS2482_OneWire
@@ -326,11 +357,13 @@ lib_deps =
https://github.com/knolleary/pubsubclient.git https://github.com/knolleary/pubsubclient.git
https://github.com/anklimov/Artnet.git https://github.com/anklimov/Artnet.git
FastLED FastLED
EEPROM ;EEPROM
Adafruit Unified Sensor Adafruit Unified Sensor
DHT sensor library DHT sensor library
Streaming Streaming
https://github.com/livello/PrintEx#is-select-redecl https://github.com/livello/PrintEx#is-select-redecl
ClosedCube HDC1080
SparkFun CCS811 Arduino Library
[env:stm32] [env:stm32]
platform = ststm32 platform = ststm32
@@ -343,11 +376,11 @@ lib_ignore =
DHT sensor library for ESPx DHT sensor library for ESPx
DmxDue DmxDue
DueFlashStorage DueFlashStorage
ESPDMX
ESP-Dmx ESP-Dmx
WifiManager WifiManager
FastLED FastLED
Ethernet Ethernet
https://github.com/anklimov/Ethernet
DMXSerial DMXSerial
DmxSimple DmxSimple
httpClient httpClient
@@ -356,16 +389,22 @@ lib_ignore =
Ethernet2 Ethernet2
Artnet Artnet
Ethernet3 Ethernet3
NRFFlashStorage
WebServer WebServer
ESP_EEPROM
DHT sensor library
DallasTemperature
Adafruit Unified Sensor
DS2482_OneWire
ModbusMaster
Syslog
EEPROM
ClosedCube HDC1080
SparkFun CCS811 Arduino Library
lib_deps = lib_deps =
; DallasTemperature
https://github.com/anklimov/aJson https://github.com/anklimov/aJson
https://github.com/anklimov/CmdArduino https://github.com/anklimov/CmdArduino
ArduinoHttpClient ArduinoHttpClient
https://github.com/knolleary/pubsubclient.git https://github.com/knolleary/pubsubclient.git
Adafruit Unified Sensor
DHT sensor library
Streaming Streaming
UIPEthernet
https://github.com/anklimov/NRFFlashStorage