mirror of
https://github.com/anklimov/lighthub
synced 2025-12-08 04:39:49 +03:00
stm32f1 suppport. changes
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
# usage:
|
# usage:
|
||||||
# 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="-DMY_CONFIG_SERVER=lazyhome.ru"
|
export FLAGS="-DMY_CONFIG_SERVER=lazyhome.ru"
|
||||||
#export FLAGS="$FLAGS -DWATCH_DOG_TICKER_DISABLE"
|
#export FLAGS="$FLAGS -DWATCH_DOG_TICKER_DISABLE"
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ static volatile long encoder_value[6];
|
|||||||
static volatile long encoder_value[6];
|
static volatile long encoder_value[6];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32F1)
|
||||||
static short encoder_irq_map[54];
|
static short encoder_irq_map[54];
|
||||||
static long encoder_value[54];
|
static long encoder_value[54];
|
||||||
static int encoders_count;
|
static int encoders_count;
|
||||||
@@ -242,7 +242,14 @@ void Input::printFloatValueToStr(float temp, char *valstr) {
|
|||||||
|
|
||||||
void Input::contactPoll() {
|
void Input::contactPoll() {
|
||||||
boolean currentInputState;
|
boolean currentInputState;
|
||||||
uint8_t inputPinMode, inputOnLevel;
|
#if defined(ARDUINO_ARCH_STM32F1)
|
||||||
|
WiringPinMode inputPinMode;
|
||||||
|
#endif
|
||||||
|
#if defined(__SAM3X8E__)||defined(__AVR__)||defined(ESP8266)
|
||||||
|
uint32_t inputPinMode;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uint8_t inputOnLevel;
|
||||||
if (inType & IN_ACTIVE_HIGH) {
|
if (inType & IN_ACTIVE_HIGH) {
|
||||||
inputOnLevel = HIGH;
|
inputOnLevel = HIGH;
|
||||||
inputPinMode = INPUT;
|
inputPinMode = INPUT;
|
||||||
@@ -302,62 +309,32 @@ void Input::onContactChanged(int val)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Input::onEncoderChanged(int i) {
|
||||||
|
#if defined(__SAM3X8E__)
|
||||||
|
encoder_value[encoder_irq_map[i]]++;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__AVR__)
|
||||||
|
encoder_value[i]++;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void Input::onEncoderChanged0() {
|
void Input::onEncoderChanged0() {
|
||||||
#if defined(__SAM3X8E__)
|
onEncoderChanged(0);
|
||||||
encoder_value[encoder_irq_map[0]]++;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__AVR__)
|
|
||||||
encoder_value[0]++;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input::onEncoderChanged1() {
|
void Input::onEncoderChanged1() {
|
||||||
#if defined(__SAM3X8E__)
|
onEncoderChanged(1);
|
||||||
encoder_value[encoder_irq_map[1]]++;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__AVR__)
|
|
||||||
encoder_value[1]++;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input::onEncoderChanged2() {
|
void Input::onEncoderChanged2() {
|
||||||
#if defined(__SAM3X8E__)
|
onEncoderChanged(2);
|
||||||
encoder_value[encoder_irq_map[2]]++;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__AVR__)
|
|
||||||
encoder_value[2]++;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input::onEncoderChanged3() {
|
void Input::onEncoderChanged3() {
|
||||||
#if defined(__SAM3X8E__)
|
onEncoderChanged(3);
|
||||||
encoder_value[encoder_irq_map[3]]++;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__AVR__)
|
|
||||||
encoder_value[3]++;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input::onEncoderChanged4() {
|
void Input::onEncoderChanged4() {
|
||||||
#if defined(__SAM3X8E__)
|
onEncoderChanged(4);
|
||||||
encoder_value[encoder_irq_map[4]]++;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__AVR__)
|
|
||||||
encoder_value[4]++;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input::onEncoderChanged5() {
|
void Input::onEncoderChanged5() {
|
||||||
#if defined(__SAM3X8E__)
|
onEncoderChanged(5);
|
||||||
encoder_value[encoder_irq_map[5]]++;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__AVR__)
|
|
||||||
encoder_value[5]++;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ public:
|
|||||||
|
|
||||||
int poll();
|
int poll();
|
||||||
|
|
||||||
|
static void inline onEncoderChanged(int i);
|
||||||
static void onEncoderChanged0();
|
static void onEncoderChanged0();
|
||||||
static void onEncoderChanged1();
|
static void onEncoderChanged1();
|
||||||
static void onEncoderChanged2();
|
static void onEncoderChanged2();
|
||||||
@@ -115,4 +116,5 @@ protected:
|
|||||||
void encoderPoll();
|
void encoderPoll();
|
||||||
|
|
||||||
void attachInterruptPinIrq(int realPin, int irq);
|
void attachInterruptPinIrq(int realPin, int irq);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ int Item::Ctrl(char * payload, boolean send){
|
|||||||
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)
|
#if not defined(ARDUINO_ARCH_ESP32) and not defined(ESP8266) and not defined(ARDUINO_ARCH_STM32F1)
|
||||||
case -3: //RGB color in #RRGGBB notation
|
case -3: //RGB color in #RRGGBB notation
|
||||||
{
|
{
|
||||||
CRGB rgb;
|
CRGB rgb;
|
||||||
|
|||||||
@@ -91,6 +91,20 @@ WiFiClient ethClient;
|
|||||||
WiFiClient ethClient;
|
WiFiClient ethClient;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ARDUINO_ARCH_STM32F1
|
||||||
|
//#include <EthernetClient.h>
|
||||||
|
//#include "UIPEthernet.h"
|
||||||
|
//#include "UIPUdp.h"
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <Ethernet_STM.h>
|
||||||
|
#include "HttpClient.h"
|
||||||
|
#include "Dns.h"
|
||||||
|
//#include "utility/logging.h"
|
||||||
|
#include <EEPROM.h>
|
||||||
|
|
||||||
|
EthernetClient ethClient;
|
||||||
|
#endif
|
||||||
|
|
||||||
lan_status lanStatus = INITIAL_STATE;
|
lan_status lanStatus = INITIAL_STATE;
|
||||||
|
|
||||||
const char outprefix[] PROGMEM = OUTTOPIC;
|
const char outprefix[] PROGMEM = OUTTOPIC;
|
||||||
@@ -131,7 +145,7 @@ int mqttErrorRate;
|
|||||||
|
|
||||||
void watchdogSetup(void) {
|
void watchdogSetup(void) {
|
||||||
//Serial.begin(115200);
|
//Serial.begin(115200);
|
||||||
//Serial.println("Watchdog armed.");
|
//debugSerial.println("Watchdog armed.");
|
||||||
} //Do not remove - strong re-definition WDT Init for DUE
|
} //Do not remove - strong re-definition WDT Init for DUE
|
||||||
|
|
||||||
|
|
||||||
@@ -140,22 +154,22 @@ void watchdogSetup(void) {
|
|||||||
|
|
||||||
void mqttCallback(char *topic, byte *payload, unsigned int length) {
|
void mqttCallback(char *topic, byte *payload, unsigned int length) {
|
||||||
|
|
||||||
Serial.print(F("\n["));
|
debugSerial.print(F("\n["));
|
||||||
Serial.print(topic);
|
debugSerial.print(topic);
|
||||||
Serial.print(F("] "));
|
debugSerial.print(F("] "));
|
||||||
if (!payload) return;
|
if (!payload) return;
|
||||||
payload[length] = 0;
|
payload[length] = 0;
|
||||||
|
|
||||||
int fr = freeRam();
|
int fr = freeRam();
|
||||||
if (fr < 250) {
|
if (fr < 250) {
|
||||||
Serial.println(F("OOM!"));
|
debugSerial.println(F("OOM!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
Serial.print((char) payload[i]);
|
debugSerial.print((char) payload[i]);
|
||||||
}
|
}
|
||||||
Serial.println();
|
debugSerial.println();
|
||||||
|
|
||||||
if(!strcmp(topic,CMDTOPIC)) {
|
if(!strcmp(topic,CMDTOPIC)) {
|
||||||
cmd_parse((char *)payload);
|
cmd_parse((char *)payload);
|
||||||
@@ -168,11 +182,12 @@ void mqttCallback(char *topic, byte *payload, unsigned int length) {
|
|||||||
{
|
{
|
||||||
char buf[MQTT_TOPIC_LENGTH + 1];
|
char buf[MQTT_TOPIC_LENGTH + 1];
|
||||||
strncpy_P(buf, inprefix, sizeof(buf));
|
strncpy_P(buf, inprefix, sizeof(buf));
|
||||||
|
|
||||||
intopic = strncmp(topic, buf, strlen(inprefix));
|
intopic = strncmp(topic, buf, strlen(inprefix));
|
||||||
}
|
}
|
||||||
// in Retaining status - trying to restore previous state from retained output topic. Retained input topics are not relevant.
|
// in Retaining status - trying to restore previous state from retained output topic. Retained input topics are not relevant.
|
||||||
if (retaining && !intopic) {
|
if (retaining && !intopic) {
|
||||||
Serial.println(F("Skipping.."));
|
debugSerial.println(F("Skipping.."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char subtopic[MQTT_SUBJECT_LENGTH] = "";
|
char subtopic[MQTT_SUBJECT_LENGTH] = "";
|
||||||
@@ -191,19 +206,19 @@ void mqttCallback(char *topic, byte *payload, unsigned int length) {
|
|||||||
|
|
||||||
void printIPAddress(IPAddress ipAddress) {
|
void printIPAddress(IPAddress ipAddress) {
|
||||||
for (byte thisByte = 0; thisByte < 4; thisByte++) {
|
for (byte thisByte = 0; thisByte < 4; thisByte++) {
|
||||||
Serial.print(ipAddress[thisByte], DEC);
|
debugSerial.print(ipAddress[thisByte], DEC);
|
||||||
if (thisByte < 3)
|
if (thisByte < 3)
|
||||||
Serial.print(F("."));
|
debugSerial.print(F("."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void printMACAddress() {
|
void printMACAddress() {
|
||||||
Serial.print(F("Configured MAC:"));
|
debugSerial.print(F("Configured MAC:"));
|
||||||
for (byte thisByte = 0; thisByte < 6; thisByte++) {
|
for (byte thisByte = 0; thisByte < 6; thisByte++) {
|
||||||
Serial.print(mac[thisByte], HEX);
|
debugSerial.print(mac[thisByte], HEX);
|
||||||
Serial.print(F(":"));
|
debugSerial.print(F(":"));
|
||||||
}
|
}
|
||||||
Serial.println();
|
debugSerial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
void restoreState() {
|
void restoreState() {
|
||||||
@@ -246,7 +261,7 @@ lan_status lanLoop() {
|
|||||||
mqttClient.unsubscribe(buf);
|
mqttClient.unsubscribe(buf);
|
||||||
|
|
||||||
lanStatus = OPERATION;//3;
|
lanStatus = OPERATION;//3;
|
||||||
Serial.println(F("Accepting commands..."));
|
debugSerial.println(F("Accepting commands..."));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,32 +298,32 @@ lan_status lanLoop() {
|
|||||||
if (lanStatus > 0)
|
if (lanStatus > 0)
|
||||||
switch (Ethernet.maintain()) {
|
switch (Ethernet.maintain()) {
|
||||||
case NO_LINK:
|
case NO_LINK:
|
||||||
Serial.println(F("No link"));
|
debugSerial.println(F("No link"));
|
||||||
if (mqttClient.connected()) mqttClient.disconnect();
|
if (mqttClient.connected()) mqttClient.disconnect();
|
||||||
nextLanCheckTime = millis() + 30000;
|
nextLanCheckTime = millis() + 30000;
|
||||||
lanStatus = AWAITING_ADDRESS;//-10;
|
lanStatus = AWAITING_ADDRESS;//-10;
|
||||||
break;
|
break;
|
||||||
case DHCP_CHECK_RENEW_FAIL:
|
case DHCP_CHECK_RENEW_FAIL:
|
||||||
Serial.println(F("Error: renewed fail"));
|
debugSerial.println(F("Error: renewed fail"));
|
||||||
if (mqttClient.connected()) mqttClient.disconnect();
|
if (mqttClient.connected()) mqttClient.disconnect();
|
||||||
nextLanCheckTime = millis() + 1000;
|
nextLanCheckTime = millis() + 1000;
|
||||||
lanStatus = AWAITING_ADDRESS;//-10;
|
lanStatus = AWAITING_ADDRESS;//-10;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DHCP_CHECK_RENEW_OK:
|
case DHCP_CHECK_RENEW_OK:
|
||||||
Serial.println(F("Renewed success. IP address:"));
|
debugSerial.println(F("Renewed success. IP address:"));
|
||||||
printIPAddress(Ethernet.localIP());
|
printIPAddress(Ethernet.localIP());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DHCP_CHECK_REBIND_FAIL:
|
case DHCP_CHECK_REBIND_FAIL:
|
||||||
Serial.println(F("Error: rebind fail"));
|
debugSerial.println(F("Error: rebind fail"));
|
||||||
if (mqttClient.connected()) mqttClient.disconnect();
|
if (mqttClient.connected()) mqttClient.disconnect();
|
||||||
nextLanCheckTime = millis() + 1000;
|
nextLanCheckTime = millis() + 1000;
|
||||||
lanStatus = AWAITING_ADDRESS;//-10;
|
lanStatus = AWAITING_ADDRESS;//-10;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DHCP_CHECK_REBIND_OK:
|
case DHCP_CHECK_REBIND_OK:
|
||||||
Serial.println(F("Rebind success. IP address:"));
|
debugSerial.println(F("Rebind success. IP address:"));
|
||||||
printIPAddress(Ethernet.localIP());
|
printIPAddress(Ethernet.localIP());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -341,25 +356,25 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
|||||||
if (n >= 4) user = aJson.getArrayItem(mqttArr, 3)->valuestring;
|
if (n >= 4) user = aJson.getArrayItem(mqttArr, 3)->valuestring;
|
||||||
if (!loadFlash(OFFSET_MQTT_PWD, passwordBuf, sizeof(passwordBuf)) && (n >= 5)) {
|
if (!loadFlash(OFFSET_MQTT_PWD, passwordBuf, sizeof(passwordBuf)) && (n >= 5)) {
|
||||||
password = aJson.getArrayItem(mqttArr, 4)->valuestring;
|
password = aJson.getArrayItem(mqttArr, 4)->valuestring;
|
||||||
Serial.println(F("Using MQTT password from config"));
|
debugSerial.println(F("Using MQTT password from config"));
|
||||||
}
|
}
|
||||||
|
|
||||||
mqttClient.setServer(servername, port);
|
mqttClient.setServer(servername, port);
|
||||||
mqttClient.setCallback(mqttCallback);
|
mqttClient.setCallback(mqttCallback);
|
||||||
|
|
||||||
Serial.print(F("Attempting MQTT connection to "));
|
debugSerial.print(F("Attempting MQTT connection to "));
|
||||||
Serial.print(servername);
|
debugSerial.print(servername);
|
||||||
Serial.print(F(":"));
|
debugSerial.print(F(":"));
|
||||||
Serial.print(port);
|
debugSerial.print(port);
|
||||||
Serial.print(F(" user:"));
|
debugSerial.print(F(" user:"));
|
||||||
Serial.print(user);
|
debugSerial.print(user);
|
||||||
Serial.print(F(" ..."));
|
debugSerial.print(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(client_id, user, password)) {
|
if (mqttClient.connect(client_id, user, password)) {
|
||||||
mqttErrorRate = 0;
|
mqttErrorRate = 0;
|
||||||
Serial.print(F("connected as "));
|
debugSerial.print(F("connected as "));
|
||||||
Serial.println(client_id);
|
debugSerial.println(client_id);
|
||||||
wdt_en();
|
wdt_en();
|
||||||
configOk = true;
|
configOk = true;
|
||||||
// ... Temporary subscribe to status topic
|
// ... Temporary subscribe to status topic
|
||||||
@@ -378,16 +393,16 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
|||||||
// if (_once) {DMXput(); _once=0;}
|
// if (_once) {DMXput(); _once=0;}
|
||||||
lanStatus = RETAINING_COLLECTING;//4;
|
lanStatus = RETAINING_COLLECTING;//4;
|
||||||
nextLanCheckTime = millis() + 5000;
|
nextLanCheckTime = millis() + 5000;
|
||||||
Serial.println(F("Awaiting for retained topics"));
|
debugSerial.println(F("Awaiting for retained topics"));
|
||||||
} else {
|
} else {
|
||||||
Serial.print(F("failed, rc="));
|
debugSerial.print(F("failed, rc="));
|
||||||
Serial.print(mqttClient.state());
|
debugSerial.print(mqttClient.state());
|
||||||
Serial.println(F(" try again in 5 seconds"));
|
debugSerial.println(F(" try again in 5 seconds"));
|
||||||
nextLanCheckTime = millis() + 5000;
|
nextLanCheckTime = millis() + 5000;
|
||||||
#ifdef RESTART_LAN_ON_MQTT_ERRORS
|
#ifdef RESTART_LAN_ON_MQTT_ERRORS
|
||||||
mqttErrorRate++;
|
mqttErrorRate++;
|
||||||
if(mqttErrorRate>50){
|
if(mqttErrorRate>50){
|
||||||
Serial.print(F("Too many MQTT connection errors. Restart LAN"));
|
debugSerial.print(F("Too many MQTT connection errors. Restart LAN"));
|
||||||
mqttErrorRate=0;
|
mqttErrorRate=0;
|
||||||
#ifdef RESET_PIN
|
#ifdef RESET_PIN
|
||||||
resetHard();
|
resetHard();
|
||||||
@@ -406,10 +421,10 @@ void onInitialStateInitLAN() {
|
|||||||
#if defined(ESP8266) and defined(WIFI_MANAGER_DISABLE)
|
#if defined(ESP8266) and defined(WIFI_MANAGER_DISABLE)
|
||||||
if(!wifiInitialized) {
|
if(!wifiInitialized) {
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
Serial.print(F("WIFI AP/Password:"));
|
debugSerial.print(F("WIFI AP/Password:"));
|
||||||
Serial.print(QUOTE(ESP_WIFI_AP));
|
debugSerial.print(QUOTE(ESP_WIFI_AP));
|
||||||
Serial.print(F("/"));
|
debugSerial.print(F("/"));
|
||||||
Serial.println(QUOTE(ESP_WIFI_PWD));
|
debugSerial.println(QUOTE(ESP_WIFI_PWD));
|
||||||
wifi_set_macaddr(STATION_IF,mac);
|
wifi_set_macaddr(STATION_IF,mac);
|
||||||
WiFi.begin(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD));
|
WiFi.begin(QUOTE(ESP_WIFI_AP), QUOTE(ESP_WIFI_PWD));
|
||||||
wifiInitialized = true;
|
wifiInitialized = true;
|
||||||
@@ -420,17 +435,17 @@ void onInitialStateInitLAN() {
|
|||||||
if(!wifiInitialized) {
|
if(!wifiInitialized) {
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.disconnect();
|
WiFi.disconnect();
|
||||||
Serial.print(F("WIFI AP/Password:"));
|
debugSerial.print(F("WIFI AP/Password:"));
|
||||||
Serial.print(QUOTE(ESP_WIFI_AP));
|
debugSerial.print(QUOTE(ESP_WIFI_AP));
|
||||||
Serial.print(F("/"));
|
debugSerial.print(F("/"));
|
||||||
Serial.println(QUOTE(ESP_WIFI_PWD));
|
debugSerial.println(QUOTE(ESP_WIFI_PWD));
|
||||||
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;
|
||||||
while (WiFi.status() != WL_CONNECTED && wifi_connection_wait > 0) {
|
while (WiFi.status() != WL_CONNECTED && wifi_connection_wait > 0) {
|
||||||
delay(500);
|
delay(500);
|
||||||
wifi_connection_wait -= 500;
|
wifi_connection_wait -= 500;
|
||||||
Serial.print(".");
|
debugSerial.print(".");
|
||||||
}
|
}
|
||||||
wifiInitialized = true;
|
wifiInitialized = true;
|
||||||
}
|
}
|
||||||
@@ -438,31 +453,31 @@ void onInitialStateInitLAN() {
|
|||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32) || defined(ESP8266)
|
#if defined(ARDUINO_ARCH_ESP32) || defined(ESP8266)
|
||||||
if (WiFi.status() == WL_CONNECTED) {
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
Serial.print(F("WiFi connected. IP address: "));
|
debugSerial.print(F("WiFi connected. IP address: "));
|
||||||
Serial.println(WiFi.localIP());
|
debugSerial.println(WiFi.localIP());
|
||||||
lanStatus = HAVE_IP_ADDRESS;//1;
|
lanStatus = HAVE_IP_ADDRESS;//1;
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
Serial.println(F("Problem with WiFi connected"));
|
debugSerial.println(F("Problem with WiFi connected"));
|
||||||
nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL/5;
|
nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL/5;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__AVR__) || defined(__SAM3X8E__)
|
#if defined(__AVR__) || defined(__SAM3X8E__)||defined(ARDUINO_ARCH_STM32F1)
|
||||||
IPAddress ip, dns, gw, mask;
|
IPAddress ip, dns, gw, mask;
|
||||||
int res = 1;
|
int res = 1;
|
||||||
Serial.println(F("Starting lan"));
|
debugSerial.println(F("Starting lan"));
|
||||||
if (ipLoadFromFlash(OFFSET_IP, ip)) {
|
if (ipLoadFromFlash(OFFSET_IP, ip)) {
|
||||||
Serial.print("Loaded from flash IP:");
|
debugSerial.print("Loaded from flash IP:");
|
||||||
printIPAddress(ip);
|
printIPAddress(ip);
|
||||||
if (ipLoadFromFlash(OFFSET_DNS, dns)) {
|
if (ipLoadFromFlash(OFFSET_DNS, dns)) {
|
||||||
Serial.print(" DNS:");
|
debugSerial.print(" DNS:");
|
||||||
printIPAddress(dns);
|
printIPAddress(dns);
|
||||||
if (ipLoadFromFlash(OFFSET_GW, gw)) {
|
if (ipLoadFromFlash(OFFSET_GW, gw)) {
|
||||||
Serial.print(" GW:");
|
debugSerial.print(" GW:");
|
||||||
printIPAddress(gw);
|
printIPAddress(gw);
|
||||||
if (ipLoadFromFlash(OFFSET_MASK, mask)) {
|
if (ipLoadFromFlash(OFFSET_MASK, mask)) {
|
||||||
Serial.print(" MASK:");
|
debugSerial.print(" MASK:");
|
||||||
printIPAddress(mask);
|
printIPAddress(mask);
|
||||||
Ethernet.begin(mac, ip, dns, gw, mask);
|
Ethernet.begin(mac, ip, dns, gw, mask);
|
||||||
} else Ethernet.begin(mac, ip, dns, gw);
|
} else Ethernet.begin(mac, ip, dns, gw);
|
||||||
@@ -470,44 +485,62 @@ void onInitialStateInitLAN() {
|
|||||||
} else Ethernet.begin(mac, ip);
|
} else Ethernet.begin(mac, ip);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Serial.println("No IP data found in flash");
|
debugSerial.println("No IP data found in flash");
|
||||||
wdt_dis();
|
wdt_dis();
|
||||||
|
#if defined(__AVR__) || defined(__SAM3X8E__)
|
||||||
res = Ethernet.begin(mac, 12000);
|
res = Ethernet.begin(mac, 12000);
|
||||||
|
#endif
|
||||||
|
#if defined(ARDUINO_ARCH_STM32F1)
|
||||||
|
res = Ethernet.begin(mac);
|
||||||
|
#endif
|
||||||
wdt_en();
|
wdt_en();
|
||||||
wdt_res();
|
wdt_res();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
Serial.println(F("Failed to configure Ethernet using DHCP. You can set ip manually!"));
|
debugSerial.println(F("Failed to configure Ethernet using DHCP. You can set ip manually!"));
|
||||||
Serial.print(F("'ip [ip[,dns[,gw[,subnet]]]]' - set static IP\n"));
|
debugSerial.print(F("'ip [ip[,dns[,gw[,subnet]]]]' - set static IP\n"));
|
||||||
lanStatus = AWAITING_ADDRESS;//-10;
|
lanStatus = AWAITING_ADDRESS;//-10;
|
||||||
nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL;
|
nextLanCheckTime = millis() + DHCP_RETRY_INTERVAL;
|
||||||
#ifdef RESET_PIN
|
#ifdef RESET_PIN
|
||||||
resetHard();
|
resetHard();
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
Serial.print(F("Got IP address:"));
|
debugSerial.print(F("Got IP address:"));
|
||||||
printIPAddress(Ethernet.localIP());
|
printIPAddress(Ethernet.localIP());
|
||||||
lanStatus = HAVE_IP_ADDRESS;//1;
|
lanStatus = HAVE_IP_ADDRESS;//1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ARDUINO_ARCH_STM32F1
|
||||||
|
void softRebootFunc() {
|
||||||
|
nvic_sys_reset();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__AVR__) || defined(__SAM3X8E__)
|
||||||
void (*softRebootFunc)(void) = 0;
|
void (*softRebootFunc)(void) = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||||
|
void softRebootFunc(){
|
||||||
|
debugSerial.print(F("ESP.restart();"));
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void resetHard() {
|
void resetHard() {
|
||||||
#ifdef RESET_PIN
|
#ifdef RESET_PIN
|
||||||
Serial.print(F("Reset Arduino with digital pin "));
|
debugSerial.print(F("Reset Arduino with digital pin "));
|
||||||
Serial.println(QUOTE(RESET_PIN));
|
debugSerial.println(QUOTE(RESET_PIN));
|
||||||
delay(500);
|
delay(500);
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
digitalWrite(RESET_PIN,LOW);
|
digitalWrite(RESET_PIN,LOW);
|
||||||
delay(500);
|
delay(500);
|
||||||
digitalWrite(RESET_PIN,HIGH);
|
digitalWrite(RESET_PIN,HIGH);
|
||||||
delay(500);
|
delay(500);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _owire
|
#ifdef _owire
|
||||||
@@ -527,12 +560,12 @@ void Changed(int i, DeviceAddress addr, int val) {
|
|||||||
owEmit = aJson.getObjectItem(owObj, "emit")->valuestring;
|
owEmit = aJson.getObjectItem(owObj, "emit")->valuestring;
|
||||||
if (owEmit) {
|
if (owEmit) {
|
||||||
strncpy(addrbuf, owEmit, sizeof(addrbuf));
|
strncpy(addrbuf, owEmit, sizeof(addrbuf));
|
||||||
Serial.print(owEmit);
|
debugSerial.print(owEmit);
|
||||||
Serial.print(F("="));
|
debugSerial.print(F("="));
|
||||||
Serial.println(val);
|
debugSerial.println(val);
|
||||||
}
|
}
|
||||||
owItem = aJson.getObjectItem(owObj, "item")->valuestring;
|
owItem = aJson.getObjectItem(owObj, "item")->valuestring;
|
||||||
} else Serial.println(F("1w-item not found in config"));
|
} else debugSerial.println(F("1w-item not found in config"));
|
||||||
|
|
||||||
if ((val == -127) || (val == 85) || (val == 0)) { //ToDo: 1-w short circuit mapped to "0" celsium
|
if ((val == -127) || (val == 85) || (val == 0)) { //ToDo: 1-w short circuit mapped to "0" celsium
|
||||||
return;
|
return;
|
||||||
@@ -554,7 +587,8 @@ void cmdFunctionHelp(int arg_cnt, char **args)
|
|||||||
//(char* tokens)
|
//(char* tokens)
|
||||||
{
|
{
|
||||||
printFirmwareVersionAndBuildOptions();
|
printFirmwareVersionAndBuildOptions();
|
||||||
Serial.println(F("Use the commands: 'help' - this text\n"
|
debugSerial.print(F(" free RAM: "));debugSerial.print(freeRam());
|
||||||
|
debugSerial.println(F(" Use the commands: 'help' - this text\n"
|
||||||
"'mac de:ad:be:ef:fe:00' set and store MAC-address in EEPROM\n"
|
"'mac de:ad:be:ef:fe:00' set and store MAC-address in EEPROM\n"
|
||||||
"'ip [ip[,dns[,gw[,subnet]]]]' - set static IP\n"
|
"'ip [ip[,dns[,gw[,subnet]]]]' - set static IP\n"
|
||||||
"'save' - save config in NVRAM\n"
|
"'save' - save config in NVRAM\n"
|
||||||
@@ -569,12 +603,12 @@ void cmdFunctionHelp(int arg_cnt, char **args)
|
|||||||
void cmdFunctionKill(int arg_cnt, char **args) {
|
void cmdFunctionKill(int arg_cnt, char **args) {
|
||||||
for (short i = 1; i < 20; i++) {
|
for (short i = 1; i < 20; i++) {
|
||||||
delay(1000);
|
delay(1000);
|
||||||
Serial.println(i);
|
debugSerial.println(i);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdFunctionReboot(int arg_cnt, char **args) {
|
void cmdFunctionReboot(int arg_cnt, char **args) {
|
||||||
Serial.println(F("Soft rebooting..."));
|
debugSerial.println(F("Soft rebooting..."));
|
||||||
softRebootFunc();
|
softRebootFunc();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -586,8 +620,8 @@ void applyConfig() {
|
|||||||
dmxArr = aJson.getObjectItem(root, "dmxin");
|
dmxArr = aJson.getObjectItem(root, "dmxin");
|
||||||
if (dmxArr && (itemsCount = aJson.getArraySize(dmxArr))) {
|
if (dmxArr && (itemsCount = aJson.getArraySize(dmxArr))) {
|
||||||
DMXinSetup(itemsCount * 4);
|
DMXinSetup(itemsCount * 4);
|
||||||
Serial.print(F("DMX in started. Channels:"));
|
debugSerial.print(F("DMX in started. Channels:"));
|
||||||
Serial.println(itemsCount * 4);
|
debugSerial.println(itemsCount * 4);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef _dmxout
|
#ifdef _dmxout
|
||||||
@@ -596,8 +630,8 @@ void applyConfig() {
|
|||||||
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);
|
||||||
//,aJson.getArrayItem(dmxoutArr, 0)->valueint);
|
//,aJson.getArrayItem(dmxoutArr, 0)->valueint);
|
||||||
Serial.print(F("DMX out started. Channels: "));
|
debugSerial.print(F("DMX out started. Channels: "));
|
||||||
Serial.println(maxChannels);
|
debugSerial.println(maxChannels);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef _modbus
|
#ifdef _modbus
|
||||||
@@ -609,12 +643,12 @@ void applyConfig() {
|
|||||||
if (owArr && !owReady) {
|
if (owArr && !owReady) {
|
||||||
aJsonObject *item = owArr->child;
|
aJsonObject *item = owArr->child;
|
||||||
owReady = owSetup(&Changed);
|
owReady = owSetup(&Changed);
|
||||||
if (owReady) Serial.println(F("One wire Ready"));
|
if (owReady) debugSerial.println(F("One wire Ready"));
|
||||||
t_count = 0;
|
t_count = 0;
|
||||||
while (item && owReady) {
|
while (item && owReady) {
|
||||||
if ((item->type == aJson_Object)) {
|
if ((item->type == aJson_Object)) {
|
||||||
DeviceAddress addr;
|
DeviceAddress addr;
|
||||||
//Serial.print(F("Add:")),Serial.println(item->name);
|
//debugSerial.print(F("Add:")),debugSerial.println(item->name);
|
||||||
SetAddr(item->name, addr);
|
SetAddr(item->name, addr);
|
||||||
owAdd(addr);
|
owAdd(addr);
|
||||||
}
|
}
|
||||||
@@ -642,10 +676,10 @@ while (items && item)
|
|||||||
int k;
|
int k;
|
||||||
pinMode(pin, OUTPUT);
|
pinMode(pin, OUTPUT);
|
||||||
digitalWrite(pin, k = ((cmd == CMD_ON) ? HIGH : LOW));
|
digitalWrite(pin, k = ((cmd == CMD_ON) ? HIGH : LOW));
|
||||||
Serial.print(F("Pin:"));
|
debugSerial.print(F("Pin:"));
|
||||||
Serial.print(pin);
|
debugSerial.print(pin);
|
||||||
Serial.print(F("="));
|
debugSerial.print(F("="));
|
||||||
Serial.println(k);
|
debugSerial.println(k);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} //switch
|
} //switch
|
||||||
@@ -660,16 +694,16 @@ while (items && item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void printConfigSummary() {
|
void printConfigSummary() {
|
||||||
Serial.println(F("Configured:"));
|
debugSerial.println(F("Configured:"));
|
||||||
Serial.print(F("items "));
|
debugSerial.print(F("items "));
|
||||||
printBool(items);
|
printBool(items);
|
||||||
Serial.print(F("inputs "));
|
debugSerial.print(F("inputs "));
|
||||||
printBool(inputs);
|
printBool(inputs);
|
||||||
Serial.print(F("modbus "));
|
debugSerial.print(F("modbus "));
|
||||||
printBool(modbusArr);
|
printBool(modbusArr);
|
||||||
Serial.print(F("mqtt "));
|
debugSerial.print(F("mqtt "));
|
||||||
printBool(mqttArr);
|
printBool(mqttArr);
|
||||||
Serial.print(F("1-wire "));
|
debugSerial.print(F("1-wire "));
|
||||||
printBool(owArr);
|
printBool(owArr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -682,24 +716,24 @@ int loadConfigFromEEPROM(int arg_cnt, char **args)
|
|||||||
//(char* tokens)
|
//(char* tokens)
|
||||||
{
|
{
|
||||||
char ch;
|
char ch;
|
||||||
Serial.println(F("loading Config"));
|
debugSerial.println(F("loading Config"));
|
||||||
|
|
||||||
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);
|
aJson.deleteItem(root);
|
||||||
root = aJson.parse(&as);
|
root = aJson.parse(&as);
|
||||||
Serial.println();
|
debugSerial.println();
|
||||||
if (!root) {
|
if (!root) {
|
||||||
Serial.println(F("load failed"));
|
debugSerial.println(F("load failed"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Serial.println(F("Loaded"));
|
debugSerial.println(F("Loaded"));
|
||||||
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 {
|
||||||
Serial.println(F("No stored config"));
|
debugSerial.println(F("No stored config"));
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -715,33 +749,33 @@ int mqttConfigRequest(int arg_cnt, char **args)
|
|||||||
//(char* tokens)
|
//(char* tokens)
|
||||||
{
|
{
|
||||||
char buf[25] = "/";
|
char buf[25] = "/";
|
||||||
Serial.println(F("request MQTT Config"));
|
debugSerial.println(F("request MQTT Config"));
|
||||||
SetBytes((uint8_t *) mac, 6, buf + 1);
|
SetBytes((uint8_t *) mac, 6, buf + 1);
|
||||||
buf[13] = 0;
|
buf[13] = 0;
|
||||||
strncat(buf, "/resp/#", 25);
|
strncat(buf, "/resp/#", 25);
|
||||||
Serial.println(buf);
|
debugSerial.println(buf);
|
||||||
mqttClient.subscribe(buf);
|
mqttClient.subscribe(buf);
|
||||||
buf[13] = 0;
|
buf[13] = 0;
|
||||||
strncat(buf, "/req/conf", 25);
|
strncat(buf, "/req/conf", 25);
|
||||||
Serial.println(buf);
|
debugSerial.println(buf);
|
||||||
mqttClient.publish(buf, "1");
|
mqttClient.publish(buf, "1");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int mqttConfigResp(char *as) {
|
int mqttConfigResp(char *as) {
|
||||||
Serial.println(F("got MQTT Config"));
|
debugSerial.println(F("got MQTT Config"));
|
||||||
|
|
||||||
//aJsonEEPROMStream as=aJsonEEPROMStream(EEPROM_offset);
|
//aJsonEEPROMStream as=aJsonEEPROMStream(EEPROM_offset);
|
||||||
|
|
||||||
//aJson.deleteItem(root);
|
//aJson.deleteItem(root);
|
||||||
root = aJson.parse(as);
|
root = aJson.parse(as);
|
||||||
Serial.println();
|
debugSerial.println();
|
||||||
if (!root) {
|
if (!root) {
|
||||||
Serial.println(F("load failed"));
|
debugSerial.println(F("load failed"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Serial.println(F("Loaded"));
|
debugSerial.println(F("Loaded"));
|
||||||
applyConfig();
|
applyConfig();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -750,10 +784,10 @@ void cmdFunctionSave(int arg_cnt, char **args)
|
|||||||
//(char* tokens)
|
//(char* tokens)
|
||||||
{
|
{
|
||||||
aJsonEEPROMStream jsonEEPROMStream = aJsonEEPROMStream(EEPROM_offset);
|
aJsonEEPROMStream jsonEEPROMStream = aJsonEEPROMStream(EEPROM_offset);
|
||||||
Serial.println(F("Saving config to EEPROM.."));
|
debugSerial.println(F("Saving config to EEPROM.."));
|
||||||
aJson.print(root, &jsonEEPROMStream);
|
aJson.print(root, &jsonEEPROMStream);
|
||||||
jsonEEPROMStream.putEOF();
|
jsonEEPROMStream.putEOF();
|
||||||
Serial.println(F("Saved to EEPROM"));
|
debugSerial.println(F("Saved to EEPROM"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdFunctionIp(int arg_cnt, char **args)
|
void cmdFunctionIp(int arg_cnt, char **args)
|
||||||
@@ -785,24 +819,24 @@ void cmdFunctionIp(int arg_cnt, char **args)
|
|||||||
saveFlash(OFFSET_MASK, current_mask);
|
saveFlash(OFFSET_MASK, current_mask);
|
||||||
saveFlash(OFFSET_GW, current_gw);
|
saveFlash(OFFSET_GW, current_gw);
|
||||||
saveFlash(OFFSET_DNS, current_dns);
|
saveFlash(OFFSET_DNS, current_dns);
|
||||||
Serial.print(F("Saved current config(ip,dns,gw,subnet):"));
|
debugSerial.print(F("Saved current config(ip,dns,gw,subnet):"));
|
||||||
printIPAddress(current_ip);
|
printIPAddress(current_ip);
|
||||||
Serial.print(F(" ,"));
|
debugSerial.print(F(" ,"));
|
||||||
printIPAddress(current_dns);
|
printIPAddress(current_dns);
|
||||||
Serial.print(F(" ,"));
|
debugSerial.print(F(" ,"));
|
||||||
printIPAddress(current_gw);
|
printIPAddress(current_gw);
|
||||||
Serial.print(F(" ,"));
|
debugSerial.print(F(" ,"));
|
||||||
printIPAddress(current_mask);
|
printIPAddress(current_mask);
|
||||||
Serial.println(F(";"));
|
debugSerial.println(F(";"));
|
||||||
|
|
||||||
}
|
}
|
||||||
Serial.println(F("Saved"));
|
debugSerial.println(F("Saved"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdFunctionClearEEPROM(int arg_cnt, char **args){
|
void cmdFunctionClearEEPROM(int arg_cnt, char **args){
|
||||||
for (int i = 0; i < 512; i++)
|
for (int i = 0; i < 512; i++)
|
||||||
EEPROM.write(i, 0);
|
EEPROM.write(i, 0);
|
||||||
Serial.println(F("EEPROM cleared"));
|
debugSerial.println(F("EEPROM cleared"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -812,13 +846,13 @@ void cmdFunctionPwd(int arg_cnt, char **args)
|
|||||||
if (arg_cnt)
|
if (arg_cnt)
|
||||||
saveFlash(OFFSET_MQTT_PWD,args[1]);
|
saveFlash(OFFSET_MQTT_PWD,args[1]);
|
||||||
else saveFlash(OFFSET_MQTT_PWD,empty);
|
else saveFlash(OFFSET_MQTT_PWD,empty);
|
||||||
Serial.println(F("Password updated"));
|
debugSerial.println(F("Password updated"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdFunctionSetMac(int arg_cnt, char **args) {
|
void cmdFunctionSetMac(int arg_cnt, char **args) {
|
||||||
|
|
||||||
//Serial.print("Got:");
|
//debugSerial.print("Got:");
|
||||||
//Serial.println(args[1]);
|
//debugSerial.println(args[1]);
|
||||||
if (sscanf(args[1], "%x:%x:%x:%x:%x:%x%с",
|
if (sscanf(args[1], "%x:%x:%x:%x:%x:%x%с",
|
||||||
&mac[0],
|
&mac[0],
|
||||||
&mac[1],
|
&mac[1],
|
||||||
@@ -826,13 +860,13 @@ void cmdFunctionSetMac(int arg_cnt, char **args) {
|
|||||||
&mac[3],
|
&mac[3],
|
||||||
&mac[4],
|
&mac[4],
|
||||||
&mac[5]) < 6) {
|
&mac[5]) < 6) {
|
||||||
Serial.print(F("could not parse: "));
|
debugSerial.print(F("could not parse: "));
|
||||||
Serial.println(args[1]);
|
debugSerial.println(args[1]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
printMACAddress();
|
printMACAddress();
|
||||||
for (short i = 0; i < 6; i++) { EEPROM.write(i, mac[i]); }
|
for (short i = 0; i < 6; i++) { EEPROM.write(i, mac[i]); }
|
||||||
Serial.println(F("Updated"));
|
debugSerial.println(F("Updated"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdFunctionGet(int arg_cnt, char **args) {
|
void cmdFunctionGet(int arg_cnt, char **args) {
|
||||||
@@ -841,7 +875,7 @@ void cmdFunctionGet(int arg_cnt, char **args) {
|
|||||||
//restoreState();
|
//restoreState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void printBool(bool arg) { (arg) ? Serial.println(F("on")) : Serial.println(F("off")); }
|
void printBool(bool arg) { (arg) ? debugSerial.println(F("on")) : debugSerial.println(F("off")); }
|
||||||
|
|
||||||
|
|
||||||
void saveFlash(short n, char *str) {
|
void saveFlash(short n, char *str) {
|
||||||
@@ -885,9 +919,9 @@ lan_status getConfig(int arg_cnt, char **args)
|
|||||||
|
|
||||||
snprintf(URI, sizeof(URI), "/%02x-%02x-%02x-%02x-%02x-%02x.config.json", mac[0], mac[1], mac[2], mac[3], mac[4],
|
snprintf(URI, sizeof(URI), "/%02x-%02x-%02x-%02x-%02x-%02x.config.json", mac[0], mac[1], mac[2], mac[3], mac[4],
|
||||||
mac[5]);
|
mac[5]);
|
||||||
Serial.print(F("Config URI: http://"));
|
debugSerial.print(F("Config URI: http://"));
|
||||||
Serial.print(configServer);
|
debugSerial.print(configServer);
|
||||||
Serial.println(URI);
|
debugSerial.println(URI);
|
||||||
|
|
||||||
#if defined(__AVR__)
|
#if defined(__AVR__)
|
||||||
FILE *configStream;
|
FILE *configStream;
|
||||||
@@ -903,52 +937,52 @@ lan_status getConfig(int arg_cnt, char **args)
|
|||||||
if (configStream != NULL) {
|
if (configStream != NULL) {
|
||||||
if (responseStatusCode == 200) {
|
if (responseStatusCode == 200) {
|
||||||
|
|
||||||
Serial.println(F("got Config"));
|
debugSerial.println(F("got Config"));
|
||||||
char c;
|
char c;
|
||||||
aJsonFileStream as = aJsonFileStream(configStream);
|
aJsonFileStream as = aJsonFileStream(configStream);
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
aJson.deleteItem(root);
|
aJson.deleteItem(root);
|
||||||
root = aJson.parse(&as);
|
root = aJson.parse(&as);
|
||||||
interrupts();
|
interrupts();
|
||||||
// Serial.println(F("Parsed."));
|
// debugSerial.println(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) {
|
||||||
Serial.println(F("Config parsing failed"));
|
debugSerial.println(F("Config parsing failed"));
|
||||||
nextLanCheckTime = millis() + 15000;
|
nextLanCheckTime = millis() + 15000;
|
||||||
return READ_RE_CONFIG;//-11;
|
return READ_RE_CONFIG;//-11;
|
||||||
} else {
|
} else {
|
||||||
// char *outstr = aJson.print(root);
|
// char *outstr = aJson.print(root);
|
||||||
// Serial.println(outstr);
|
// debugSerial.println(outstr);
|
||||||
// free(outstr);
|
// free(outstr);
|
||||||
Serial.println(F("Applying."));
|
debugSerial.println(F("Applying."));
|
||||||
applyConfig();
|
applyConfig();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Serial.print(F("ERROR: Server returned "));
|
debugSerial.print(F("ERROR: Server returned "));
|
||||||
Serial.println(responseStatusCode);
|
debugSerial.println(responseStatusCode);
|
||||||
nextLanCheckTime = millis() + 5000;
|
nextLanCheckTime = millis() + 5000;
|
||||||
return READ_RE_CONFIG;//-11;
|
return READ_RE_CONFIG;//-11;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Serial.println(F("failed to connect"));
|
debugSerial.println(F("failed to connect"));
|
||||||
Serial.println(F(" try again in 5 seconds"));
|
debugSerial.println(F(" try again in 5 seconds"));
|
||||||
nextLanCheckTime = millis() + 5000;
|
nextLanCheckTime = millis() + 5000;
|
||||||
return READ_RE_CONFIG;//-11;
|
return READ_RE_CONFIG;//-11;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32F1)
|
||||||
String response;
|
String response;
|
||||||
EthernetClient configEthClient;
|
EthernetClient configEthClient;
|
||||||
HttpClient htclient = HttpClient(configEthClient, configServer, 80);
|
HttpClient htclient = HttpClient(configEthClient, configServer, 80);
|
||||||
//htclient.stop(); //_socket =MAX
|
//htclient.stop(); //_socket =MAX
|
||||||
htclient.setHttpResponseTimeout(4000);
|
htclient.setHttpResponseTimeout(4000);
|
||||||
wdt_res();
|
wdt_res();
|
||||||
//Serial.println("making GET request");get
|
//debugSerial.println("making GET request");get
|
||||||
htclient.beginRequest();
|
htclient.beginRequest();
|
||||||
htclient.get(URI);
|
htclient.get(URI);
|
||||||
htclient.endRequest();
|
htclient.endRequest();
|
||||||
@@ -959,31 +993,31 @@ lan_status getConfig(int arg_cnt, char **args)
|
|||||||
response = htclient.responseBody();
|
response = htclient.responseBody();
|
||||||
htclient.stop();
|
htclient.stop();
|
||||||
wdt_res();
|
wdt_res();
|
||||||
Serial.print(F("HTTP Status code: "));
|
debugSerial.print(F("HTTP Status code: "));
|
||||||
Serial.println(responseStatusCode);
|
debugSerial.println(responseStatusCode);
|
||||||
//Serial.print("GET Response: ");
|
//debugSerial.print("GET Response: ");
|
||||||
|
|
||||||
if (responseStatusCode == 200) {
|
if (responseStatusCode == 200) {
|
||||||
aJson.deleteItem(root);
|
aJson.deleteItem(root);
|
||||||
root = aJson.parse((char *) response.c_str());
|
root = aJson.parse((char *) response.c_str());
|
||||||
|
|
||||||
if (!root) {
|
if (!root) {
|
||||||
Serial.println(F("Config parsing failed"));
|
debugSerial.println(F("Config parsing failed"));
|
||||||
// nextLanCheckTime=millis()+15000;
|
// nextLanCheckTime=millis()+15000;
|
||||||
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
char * outstr=aJson.print(root);
|
char * outstr=aJson.print(root);
|
||||||
Serial.println(outstr);
|
debugSerial.println(outstr);
|
||||||
free (outstr);
|
free (outstr);
|
||||||
*/
|
*/
|
||||||
Serial.println(response);
|
debugSerial.println(response);
|
||||||
applyConfig();
|
applyConfig();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Serial.println(F("Config retrieving failed"));
|
debugSerial.println(F("Config retrieving failed"));
|
||||||
//nextLanCheckTime=millis()+15000;
|
//nextLanCheckTime=millis()+15000;
|
||||||
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
||||||
}
|
}
|
||||||
@@ -997,23 +1031,23 @@ lan_status getConfig(int arg_cnt, char **args)
|
|||||||
int httpResponseCode = httpClient.GET();
|
int httpResponseCode = httpClient.GET();
|
||||||
if (httpResponseCode > 0) {
|
if (httpResponseCode > 0) {
|
||||||
// HTTP header has been send and Server response header has been handled
|
// HTTP header has been send and Server response header has been handled
|
||||||
Serial.printf("[HTTP] GET... code: %d\n", httpResponseCode);
|
debugSerial.printf("[HTTP] GET... code: %d\n", httpResponseCode);
|
||||||
// file found at server
|
// file found at server
|
||||||
if (httpResponseCode == HTTP_CODE_OK) {
|
if (httpResponseCode == HTTP_CODE_OK) {
|
||||||
String response = httpClient.getString();
|
String response = httpClient.getString();
|
||||||
Serial.println(response);
|
debugSerial.println(response);
|
||||||
aJson.deleteItem(root);
|
aJson.deleteItem(root);
|
||||||
root = aJson.parse((char *) response.c_str());
|
root = aJson.parse((char *) response.c_str());
|
||||||
if (!root) {
|
if (!root) {
|
||||||
Serial.println(F("Config parsing failed"));
|
debugSerial.println(F("Config parsing failed"));
|
||||||
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
||||||
} else {
|
} else {
|
||||||
Serial.println(F("Config OK, Applying"));
|
debugSerial.println(F("Config OK, Applying"));
|
||||||
applyConfig();
|
applyConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Serial.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());
|
||||||
httpClient.end();
|
httpClient.end();
|
||||||
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
||||||
}
|
}
|
||||||
@@ -1092,84 +1126,76 @@ void setup_main() {
|
|||||||
//TODO: checkForRemoteSketchUpdate();
|
//TODO: checkForRemoteSketchUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MMMMMM
|
|
||||||
errro!!!
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void printFirmwareVersionAndBuildOptions() {
|
void printFirmwareVersionAndBuildOptions() {
|
||||||
Serial.print(F("\nLazyhome.ru LightHub controller "));
|
debugSerial.print(F("\nLazyhome.ru LightHub controller "));
|
||||||
Serial.println(F(QUOTE(PIO_SRC_REV)));
|
debugSerial.println(F(QUOTE(PIO_SRC_REV)));
|
||||||
#ifdef CONTROLLINO
|
#ifdef CONTROLLINO
|
||||||
Serial.println(F("(+)CONTROLLINO"));
|
debugSerial.println(F("(+)CONTROLLINO"));
|
||||||
#endif
|
#endif
|
||||||
#ifdef WATCH_DOG_TICKER_DISABLE
|
#ifdef WATCH_DOG_TICKER_DISABLE
|
||||||
Serial.println(F("(-)WATCHDOG"));
|
debugSerial.println(F("(-)WATCHDOG"));
|
||||||
#else
|
#else
|
||||||
Serial.println(F("(+)WATCHDOG"));
|
debugSerial.println(F("(+)WATCHDOG"));
|
||||||
#endif
|
#endif
|
||||||
Serial.print(F("Config server:"));
|
debugSerial.print(F("Config server:"));
|
||||||
Serial.println(F(CONFIG_SERVER));
|
debugSerial.println(F(CONFIG_SERVER));
|
||||||
Serial.print(F("Firmware MAC Address "));
|
debugSerial.print(F("Firmware MAC Address "));
|
||||||
Serial.println(F(QUOTE(CUSTOM_FIRMWARE_MAC))); //Q Macros didn't working with 6 args
|
debugSerial.println(F(QUOTE(CUSTOM_FIRMWARE_MAC))); //Q Macros didn't working with 6 args
|
||||||
#ifdef DISABLE_FREERAM_PRINT
|
#ifdef DISABLE_FREERAM_PRINT
|
||||||
Serial.println(F("(-)FreeRam printing"));
|
debugSerial.println(F("(-)FreeRam printing"));
|
||||||
#else
|
#else
|
||||||
Serial.println(F("(+)FreeRam printing"));
|
debugSerial.println(F("(+)FreeRam printing"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_1W_PIN
|
#ifdef USE_1W_PIN
|
||||||
Serial.print(F("(-)DS2482-100 USE_1W_PIN="));
|
debugSerial.print(F("(-)DS2482-100 USE_1W_PIN="));
|
||||||
Serial.println(QUOTE(USE_1W_PIN));
|
debugSerial.println(QUOTE(USE_1W_PIN));
|
||||||
#else
|
#else
|
||||||
Serial.println(F("(+)DS2482-100"));
|
debugSerial.println(F("(+)DS2482-100"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Wiz5500
|
#ifdef Wiz5500
|
||||||
Serial.println(F("(+)WizNet5500"));
|
debugSerial.println(F("(+)WizNet5500"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DMX_DISABLE
|
#ifdef DMX_DISABLE
|
||||||
Serial.println(F("(-)DMX"));
|
debugSerial.println(F("(-)DMX"));
|
||||||
#else
|
#else
|
||||||
Serial.println(F("(+)DMX"));
|
debugSerial.println(F("(+)DMX"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MODBUS_DISABLE
|
#ifdef MODBUS_DISABLE
|
||||||
Serial.println(F("(-)MODBUS"));
|
debugSerial.println(F("(-)MODBUS"));
|
||||||
#else
|
#else
|
||||||
Serial.println(F("(+)MODBUS"));
|
debugSerial.println(F("(+)MODBUS"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef OWIRE_DISABLE
|
#ifdef OWIRE_DISABLE
|
||||||
Serial.println(F("(-)OWIRE"));
|
debugSerial.println(F("(-)OWIRE"));
|
||||||
#else
|
#else
|
||||||
Serial.println(F("(+)OWIRE"));
|
debugSerial.println(F("(+)OWIRE"));
|
||||||
#endif
|
#endif
|
||||||
#ifndef DHT_DISABLE
|
#ifndef DHT_DISABLE
|
||||||
Serial.println(F("(+)DHT"));
|
debugSerial.println(F("(+)DHT"));
|
||||||
#else
|
#else
|
||||||
Serial.println(F("(-)DHT"));
|
debugSerial.println(F("(-)DHT"));
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef Wiz5500
|
|
||||||
Serial.println(F("(+)Wiz5500"));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SD_CARD_INSERTED
|
#ifdef SD_CARD_INSERTED
|
||||||
Serial.println(F("(+)SDCARD"));
|
debugSerial.println(F("(+)SDCARD"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RESET_PIN
|
#ifdef RESET_PIN
|
||||||
Serial.print(F("(+)HARDRESET on pin="));
|
debugSerial.print(F("(+)HARDRESET on pin="));
|
||||||
Serial.println(F(QUOTE(RESET_PIN)));
|
debugSerial.println(F(QUOTE(RESET_PIN)));
|
||||||
#else
|
#else
|
||||||
Serial.println("(-)HARDRESET, using soft");
|
debugSerial.println("(-)HARDRESET, using soft");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RESTART_LAN_ON_MQTT_ERRORS
|
#ifdef RESTART_LAN_ON_MQTT_ERRORS
|
||||||
Serial.println(F("(+)RESTART_LAN_ON_MQTT_ERRORS"));
|
debugSerial.println(F("(+)RESTART_LAN_ON_MQTT_ERRORS"));
|
||||||
#else
|
#else
|
||||||
Serial.println("(-)RESTART_LAN_ON_MQTT_ERRORS");
|
debugSerial.println("(-)RESTART_LAN_ON_MQTT_ERRORS");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1191,7 +1217,7 @@ void setupMacAddress() {
|
|||||||
if (mac[i] != 0 && mac[i] != 0xff) isMacValid = true;
|
if (mac[i] != 0 && mac[i] != 0xff) isMacValid = true;
|
||||||
}
|
}
|
||||||
if (!isMacValid) {
|
if (!isMacValid) {
|
||||||
Serial.println(F("Invalid MAC: set firmware's MAC"));
|
debugSerial.println(F("Invalid MAC: set firmware's MAC"));
|
||||||
memcpy(mac, firmwareMacAddress, 6);
|
memcpy(mac, firmwareMacAddress, 6);
|
||||||
}
|
}
|
||||||
printMACAddress();
|
printMACAddress();
|
||||||
@@ -1199,7 +1225,7 @@ void setupMacAddress() {
|
|||||||
|
|
||||||
void setupCmdArduino() {
|
void setupCmdArduino() {
|
||||||
cmdInit(uint32_t(SERIAL_BAUD));
|
cmdInit(uint32_t(SERIAL_BAUD));
|
||||||
Serial.println(F(">>>"));
|
debugSerial.println(F(">>>"));
|
||||||
cmdAdd("help", cmdFunctionHelp);
|
cmdAdd("help", cmdFunctionHelp);
|
||||||
cmdAdd("save", cmdFunctionSave);
|
cmdAdd("save", cmdFunctionSave);
|
||||||
cmdAdd("load", cmdFunctionLoad);
|
cmdAdd("load", cmdFunctionLoad);
|
||||||
@@ -1231,7 +1257,7 @@ void loop_main() {
|
|||||||
// unsigned long lastpacket = DMXSerial.noDataSince();
|
// unsigned long lastpacket = DMXSerial.noDataSince();
|
||||||
DMXCheck();
|
DMXCheck();
|
||||||
#endif
|
#endif
|
||||||
// if (lastpacket && (lastpacket%10==0)) Serial.println(lastpacket);
|
// if (lastpacket && (lastpacket%10==0)) debugSerial.println(lastpacket);
|
||||||
|
|
||||||
if (items) {
|
if (items) {
|
||||||
#ifndef MODBUS_DISABLE
|
#ifndef MODBUS_DISABLE
|
||||||
@@ -1257,7 +1283,7 @@ void owIdle(void) {
|
|||||||
|
|
||||||
wdt_res();
|
wdt_res();
|
||||||
return; //TODO: unreached code
|
return; //TODO: unreached code
|
||||||
Serial.print(F("o"));
|
debugSerial.print(F("o"));
|
||||||
if (lanLoop() == 1) mqttClient.loop();
|
if (lanLoop() == 1) mqttClient.loop();
|
||||||
//if (owReady) owLoop();
|
//if (owReady) owLoop();
|
||||||
|
|
||||||
@@ -1272,7 +1298,7 @@ void owIdle(void) {
|
|||||||
void ethernetIdle(void){
|
void ethernetIdle(void){
|
||||||
wdt_res();
|
wdt_res();
|
||||||
inputLoop();
|
inputLoop();
|
||||||
// Serial.print(".");
|
// debugSerial.print(".");
|
||||||
};
|
};
|
||||||
|
|
||||||
void modbusIdle(void) {
|
void modbusIdle(void) {
|
||||||
@@ -1357,8 +1383,8 @@ void thermoLoop(void) {
|
|||||||
int curTemp = aJson.getArrayItem(thermoExtensionArray, IET_TEMP)->valueint;
|
int curTemp = aJson.getArrayItem(thermoExtensionArray, IET_TEMP)->valueint;
|
||||||
|
|
||||||
if (!aJson.getArrayItem(thermoExtensionArray, IET_ATTEMPTS)->valueint) {
|
if (!aJson.getArrayItem(thermoExtensionArray, IET_ATTEMPTS)->valueint) {
|
||||||
Serial.print(thermoItem->name);
|
debugSerial.print(thermoItem->name);
|
||||||
Serial.println(F(" Expired"));
|
debugSerial.println(F(" Expired"));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (!(--aJson.getArrayItem(thermoExtensionArray, IET_ATTEMPTS)->valueint))
|
if (!(--aJson.getArrayItem(thermoExtensionArray, IET_ATTEMPTS)->valueint))
|
||||||
@@ -1368,27 +1394,27 @@ void thermoLoop(void) {
|
|||||||
if (curTemp > THERMO_OVERHEAT_CELSIUS) mqttClient.publish("/alarm/ovrht", thermoItem->name);
|
if (curTemp > THERMO_OVERHEAT_CELSIUS) mqttClient.publish("/alarm/ovrht", thermoItem->name);
|
||||||
|
|
||||||
|
|
||||||
Serial.print(thermoItem->name);
|
debugSerial.print(thermoItem->name);
|
||||||
Serial.print(F(" Set:"));
|
debugSerial.print(F(" Set:"));
|
||||||
Serial.print(thermoSetting);
|
debugSerial.print(thermoSetting);
|
||||||
Serial.print(F(" Cur:"));
|
debugSerial.print(F(" Cur:"));
|
||||||
Serial.print(curTemp);
|
debugSerial.print(curTemp);
|
||||||
Serial.print(F(" cmd:"));
|
debugSerial.print(F(" cmd:"));
|
||||||
Serial.print(thermoStateCommand);
|
debugSerial.print(thermoStateCommand);
|
||||||
pinMode(thermoPin, OUTPUT);
|
pinMode(thermoPin, OUTPUT);
|
||||||
if (thermoDisabledOrDisconnected(thermoExtensionArray, thermoStateCommand)) {
|
if (thermoDisabledOrDisconnected(thermoExtensionArray, thermoStateCommand)) {
|
||||||
digitalWrite(thermoPin, LOW);
|
digitalWrite(thermoPin, LOW);
|
||||||
Serial.println(F(" OFF"));
|
debugSerial.println(F(" OFF"));
|
||||||
} else {
|
} else {
|
||||||
if (curTemp < thermoSetting - THERMO_GIST_CELSIUS) {
|
if (curTemp < thermoSetting - THERMO_GIST_CELSIUS) {
|
||||||
digitalWrite(thermoPin, HIGH);
|
digitalWrite(thermoPin, HIGH);
|
||||||
Serial.println(F(" ON"));
|
debugSerial.println(F(" ON"));
|
||||||
} //too cold
|
} //too cold
|
||||||
else if (curTemp >= thermoSetting) {
|
else if (curTemp >= thermoSetting) {
|
||||||
digitalWrite(thermoPin, LOW);
|
digitalWrite(thermoPin, LOW);
|
||||||
Serial.println(F(" OFF"));
|
debugSerial.println(F(" OFF"));
|
||||||
} //Reached settings
|
} //Reached settings
|
||||||
else Serial.println(F(" -target zone-")); // Nothing to do
|
else debugSerial.println(F(" -target zone-")); // Nothing to do
|
||||||
}
|
}
|
||||||
thermostatCheckPrinted = true;
|
thermostatCheckPrinted = true;
|
||||||
}
|
}
|
||||||
@@ -1398,9 +1424,9 @@ void thermoLoop(void) {
|
|||||||
nextThermostatCheck = millis() + THERMOSTAT_CHECK_PERIOD;
|
nextThermostatCheck = millis() + THERMOSTAT_CHECK_PERIOD;
|
||||||
|
|
||||||
#ifndef DISABLE_FREERAM_PRINT
|
#ifndef DISABLE_FREERAM_PRINT
|
||||||
(thermostatCheckPrinted) ? Serial.print(F("\nfree:")) : Serial.print(F(" "));
|
(thermostatCheckPrinted) ? debugSerial.print(F("\nfree:")) : debugSerial.print(F(" "));
|
||||||
Serial.print(freeRam());
|
debugSerial.print(freeRam());
|
||||||
Serial.print(" ");
|
debugSerial.print(" ");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1431,4 +1457,3 @@ short thermoSetCurTemp(char *name, short t) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,12 @@
|
|||||||
#define wdt_dis()
|
#define wdt_dis()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_STM32F1)
|
||||||
|
#define wdt_res()
|
||||||
|
#define wdt_en()
|
||||||
|
#define wdt_dis()
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef DHCP_RETRY_INTERVAL
|
#ifndef DHCP_RETRY_INTERVAL
|
||||||
#define DHCP_RETRY_INTERVAL 60000
|
#define DHCP_RETRY_INTERVAL 60000
|
||||||
#endif
|
#endif
|
||||||
@@ -50,7 +56,9 @@
|
|||||||
#include "stdarg.h"
|
#include "stdarg.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "inputs.h"
|
#include "inputs.h"
|
||||||
|
#ifndef ARDUINO_ARCH_STM32F1
|
||||||
#include "FastLED.h"
|
#include "FastLED.h"
|
||||||
|
#endif
|
||||||
#include "Dns.h"
|
#include "Dns.h"
|
||||||
//#include "hsv2rgb.h"
|
//#include "hsv2rgb.h"
|
||||||
|
|
||||||
|
|||||||
@@ -135,4 +135,16 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DHT_POLL_DELAY_DEFAULT 15000
|
#define DHT_POLL_DELAY_DEFAULT 15000
|
||||||
|
|
||||||
|
#ifdef ARDUINO_ARCH_STM32F1
|
||||||
|
#define strncpy_P strncpy
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef debugSerial
|
||||||
|
#define debugSerial Serial1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef Wiz5500
|
||||||
|
#define W5100_ETHERNET_SHIELD
|
||||||
|
#endif
|
||||||
@@ -41,6 +41,7 @@ unsigned long owTimer = 0;
|
|||||||
owChangedType owChanged;
|
owChangedType owChanged;
|
||||||
|
|
||||||
int owUpdate() {
|
int owUpdate() {
|
||||||
|
#ifndef OWIRE_DISABLE
|
||||||
unsigned long finish = millis() + OW_UPDATE_INTERVAL;
|
unsigned long finish = millis() + OW_UPDATE_INTERVAL;
|
||||||
short sr;
|
short sr;
|
||||||
|
|
||||||
@@ -80,11 +81,12 @@ int owUpdate() {
|
|||||||
|
|
||||||
Serial.print(F("1-wire count: "));
|
Serial.print(F("1-wire count: "));
|
||||||
Serial.println(t_count);
|
Serial.println(t_count);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int owSetup(owChangedType owCh) {
|
int owSetup(owChangedType owCh) {
|
||||||
|
#ifndef OWIRE_DISABLE
|
||||||
//// todo - move memory allocation to here
|
//// todo - move memory allocation to here
|
||||||
if (net) return true; // Already initialized
|
if (net) return true; // Already initialized
|
||||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||||
@@ -138,6 +140,7 @@ net = new OneWire (USE_1W_PIN);
|
|||||||
|
|
||||||
delay(500);
|
delay(500);
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -182,6 +185,7 @@ int owFind(DeviceAddress addr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void owAdd(DeviceAddress addr) {
|
void owAdd(DeviceAddress addr) {
|
||||||
|
#ifndef OWIRE_DISABLE
|
||||||
if (t_count>=t_max) return;
|
if (t_count>=t_max) return;
|
||||||
wstat[t_count] = SW_FIND; //Newly detected
|
wstat[t_count] = SW_FIND; //Newly detected
|
||||||
memcpy(term[t_count], addr, 8);
|
memcpy(term[t_count], addr, 8);
|
||||||
@@ -198,4 +202,5 @@ void owAdd(DeviceAddress addr) {
|
|||||||
// sensors.requestTemperaturesByAddress(term[t_count]);
|
// sensors.requestTemperaturesByAddress(term[t_count]);
|
||||||
}
|
}
|
||||||
t_count++;
|
t_count++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,10 @@ e-mail anklimov@gmail.com
|
|||||||
#define t_max 20 //Maximum number of 1w devices
|
#define t_max 20 //Maximum number of 1w devices
|
||||||
#define TEMPERATURE_PRECISION 9
|
#define TEMPERATURE_PRECISION 9
|
||||||
|
|
||||||
|
#ifndef ARDUINO_ARCH_STM32F1
|
||||||
#include <DS2482_OneWire.h>
|
#include <DS2482_OneWire.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <DallasTemperature.h>
|
#include <DallasTemperature.h>
|
||||||
#include "aJSON.h"
|
#include "aJSON.h"
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ e-mail anklimov@gmail.com
|
|||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32F1)
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ void SetBytes(uint8_t *addr, uint8_t count, char *out) {
|
|||||||
|
|
||||||
|
|
||||||
byte HEX2DEC(char i) {
|
byte HEX2DEC(char i) {
|
||||||
byte v;
|
byte v=0;
|
||||||
if ('a' <= i && i <= 'f') { v = i - 97 + 10; }
|
if ('a' <= i && i <= 'f') { v = i - 97 + 10; }
|
||||||
else if ('A' <= i && i <= 'F') { v = i - 65 + 10; }
|
else if ('A' <= i && i <= 'F') { v = i - 65 + 10; }
|
||||||
else if ('0' <= i && i <= '9') { v = i - 48; }
|
else if ('0' <= i && i <= '9') { v = i - 48; }
|
||||||
@@ -94,6 +94,20 @@ unsigned long freeRam ()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_STM32F1)
|
||||||
|
extern char _end;
|
||||||
|
extern "C" char *sbrk(int i);
|
||||||
|
|
||||||
|
unsigned long freeRam() {
|
||||||
|
char *heapend = sbrk(0);
|
||||||
|
register char *stack_ptr asm( "sp" );
|
||||||
|
struct mallinfo mi = mallinfo();
|
||||||
|
|
||||||
|
return stack_ptr - heapend + mi.fordblks;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
extern char _end;
|
extern char _end;
|
||||||
extern "C" char *sbrk(int i);
|
extern "C" char *sbrk(int i);
|
||||||
@@ -119,4 +133,6 @@ void parseBytes(const char *str, char separator, byte *bytes, int maxBytes, int
|
|||||||
}
|
}
|
||||||
str++; // Point to next character after separator
|
str++; // Point to next character after separator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#pragma message(VAR_NAME_VALUE(debugSerial))
|
||||||
|
#pragma message(VAR_NAME_VALUE(SERIAL_BAUD))
|
||||||
@@ -19,6 +19,9 @@ e-mail anklimov@gmail.com
|
|||||||
*/
|
*/
|
||||||
#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(x) VALUE_TO_STRING(x)
|
||||||
|
#define VAR_NAME_VALUE(var) #var "=" VALUE(var)
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
[platformio]
|
[platformio]
|
||||||
src_dir = lighthub
|
src_dir = lighthub
|
||||||
env_default =
|
env_default =
|
||||||
megaatmega2560
|
; megaatmega2560
|
||||||
; megaatmega2560-net
|
; megaatmega2560-net
|
||||||
; due
|
; due
|
||||||
; esp8266
|
; esp8266
|
||||||
@@ -18,7 +18,7 @@ env_default =
|
|||||||
; megaatmega2560-5500
|
; megaatmega2560-5500
|
||||||
; due-5500
|
; due-5500
|
||||||
; controllino
|
; controllino
|
||||||
; stm32f407
|
stm32
|
||||||
|
|
||||||
build_dir = /tmp/pioenvs
|
build_dir = /tmp/pioenvs
|
||||||
libdeps_dir = /tmp/piolibdeps
|
libdeps_dir = /tmp/piolibdeps
|
||||||
@@ -44,28 +44,22 @@ lib_deps =
|
|||||||
DHT sensor library for ESPx
|
DHT sensor library for ESPx
|
||||||
DHT sensor library
|
DHT sensor library
|
||||||
|
|
||||||
[env:stm32f407]
|
[env:stm32]
|
||||||
platform = ststm32
|
platform = ststm32
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board = genericSTM32F407VET6
|
board = nucleo_f103rb
|
||||||
|
upload_protocol = st-link
|
||||||
;lib_ldf_mode = chain+
|
;lib_ldf_mode = chain+
|
||||||
build_flags = !sh build_flags_stm32f407.sh
|
build_flags = !sh build_flags_stm32.sh
|
||||||
lib_deps =
|
lib_deps =
|
||||||
https://github.com/sebnil/DueFlashStorage
|
DallasTemperature
|
||||||
https://github.com/anklimov/Arduino-Temperature-Control-Library.git
|
|
||||||
https://github.com/anklimov/DS2482_OneWire
|
|
||||||
https://github.com/anklimov/DmxDue
|
|
||||||
https://github.com/anklimov/ArduinoHttpClient
|
|
||||||
https://github.com/anklimov/aJson
|
https://github.com/anklimov/aJson
|
||||||
https://github.com/anklimov/CmdArduino
|
https://github.com/anklimov/CmdArduino
|
||||||
|
ArduinoHttpClient
|
||||||
https://github.com/anklimov/ModbusMaster
|
https://github.com/anklimov/ModbusMaster
|
||||||
https://github.com/anklimov/Ethernet
|
; https://github.com/Serasidis/Ethernet_STM.git
|
||||||
https://github.com/anklimov/Ethernet2
|
; https://github.com/livello/Ethernet_STM.git
|
||||||
https://github.com/knolleary/pubsubclient.git
|
https://github.com/knolleary/pubsubclient.git
|
||||||
https://github.com/anklimov/Artnet.git
|
|
||||||
; FastLED
|
|
||||||
SD
|
|
||||||
SdFat
|
|
||||||
Adafruit Unified Sensor
|
Adafruit Unified Sensor
|
||||||
DHT sensor library
|
DHT sensor library
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user