mirror of
https://github.com/anklimov/lighthub
synced 2025-12-08 04:39:49 +03:00
refactoring. stm32 minimal support
This commit is contained in:
@@ -23,16 +23,17 @@ e-mail anklimov@gmail.com
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#ifdef _dmxout
|
#ifdef _dmxout
|
||||||
|
|
||||||
#include "dmx.h"
|
#include "dmx.h"
|
||||||
#include "FastLED.h"
|
#include "FastLED.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef MODBUS_DISABLE
|
||||||
#include <ModbusMaster.h>
|
#include <ModbusMaster.h>
|
||||||
|
#endif
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
short modbusBusy = 0;
|
short modbusBusy = 0;
|
||||||
extern aJsonObject *pollingItem;
|
extern aJsonObject *pollingItem;
|
||||||
|
|
||||||
@@ -1266,7 +1267,10 @@ int Item::SendStatus(short cmd, short n, int *Par, boolean deffered) {
|
|||||||
if (Par)
|
if (Par)
|
||||||
for (short i = 0; i < n; i++) {
|
for (short i = 0; i < n; i++) {
|
||||||
char num[4];
|
char num[4];
|
||||||
|
#ifndef FLASH_64KB
|
||||||
snprintf(num, sizeof(num), "%d", Par[i]);
|
snprintf(num, sizeof(num), "%d", Par[i]);
|
||||||
|
#endif
|
||||||
|
itoa(Par[i],num,10);
|
||||||
strncat(valstr, num, sizeof(valstr));
|
strncat(valstr, num, sizeof(valstr));
|
||||||
if (i != n - 1) {
|
if (i != n - 1) {
|
||||||
strcpy(num, ",");
|
strcpy(num, ",");
|
||||||
|
|||||||
@@ -94,12 +94,13 @@ WiFiClient ethClient;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_STM32F1
|
#ifdef ARDUINO_ARCH_STM32F1
|
||||||
|
#include "HttpClient.h"
|
||||||
//#include <EthernetClient.h>
|
//#include <EthernetClient.h>
|
||||||
//#include "UIPEthernet.h"
|
//#include "UIPEthernet.h"
|
||||||
//#include "UIPUdp.h"
|
//#include "UIPUdp.h"
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <Ethernet_STM.h>
|
#include <Ethernet_STM.h>
|
||||||
#include "HttpClient.h"
|
|
||||||
#include "Dns.h"
|
#include "Dns.h"
|
||||||
//#include "utility/logging.h"
|
//#include "utility/logging.h"
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
@@ -126,10 +127,18 @@ aJsonObject *items = NULL;
|
|||||||
aJsonObject *inputs = NULL;
|
aJsonObject *inputs = NULL;
|
||||||
|
|
||||||
aJsonObject *mqttArr = NULL;
|
aJsonObject *mqttArr = NULL;
|
||||||
|
#ifndef MODBUS_DISABLE
|
||||||
aJsonObject *modbusArr = NULL;
|
aJsonObject *modbusArr = NULL;
|
||||||
|
#endif
|
||||||
|
#ifdef _owire
|
||||||
aJsonObject *owArr = NULL;
|
aJsonObject *owArr = NULL;
|
||||||
|
#endif
|
||||||
|
#ifdef _dmxout
|
||||||
aJsonObject *dmxArr = NULL;
|
aJsonObject *dmxArr = NULL;
|
||||||
|
#endif
|
||||||
|
#ifdef SYSLOG_ENABLE
|
||||||
aJsonObject *udpSyslogArr = NULL;
|
aJsonObject *udpSyslogArr = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
unsigned long nextPollingCheck = 0;
|
unsigned long nextPollingCheck = 0;
|
||||||
unsigned long nextInputCheck = 0;
|
unsigned long nextInputCheck = 0;
|
||||||
@@ -378,7 +387,6 @@ void ip_ready_config_loaded_connecting_to_broker() {
|
|||||||
mqttClient.setCallback(mqttCallback);
|
mqttClient.setCallback(mqttCallback);
|
||||||
|
|
||||||
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(client_id, user, password)) {
|
if (mqttClient.connect(client_id, user, password)) {
|
||||||
mqttErrorRate = 0;
|
mqttErrorRate = 0;
|
||||||
@@ -619,7 +627,6 @@ void cmdFunctionHelp(int arg_cnt, char **args)
|
|||||||
"'clear' - clear EEPROM\n"
|
"'clear' - clear EEPROM\n"
|
||||||
"'reboot' - reboot controller");
|
"'reboot' - reboot controller");
|
||||||
}
|
}
|
||||||
|
|
||||||
void printCurentLanConfig() {
|
void printCurentLanConfig() {
|
||||||
debugSerial << F("Current LAN config(ip,dns,gw,subnet):");
|
debugSerial << F("Current LAN config(ip,dns,gw,subnet):");
|
||||||
printIPAddress(Ethernet.localIP());
|
printIPAddress(Ethernet.localIP());
|
||||||
@@ -712,7 +719,9 @@ void applyConfig() {
|
|||||||
}
|
}
|
||||||
inputs = aJson.getObjectItem(root, "in");
|
inputs = aJson.getObjectItem(root, "in");
|
||||||
mqttArr = aJson.getObjectItem(root, "mqtt");
|
mqttArr = aJson.getObjectItem(root, "mqtt");
|
||||||
|
#ifdef SYSLOG_ENABLE
|
||||||
udpSyslogArr = aJson.getObjectItem(root, "syslog");
|
udpSyslogArr = aJson.getObjectItem(root, "syslog");
|
||||||
|
#endif
|
||||||
printConfigSummary();
|
printConfigSummary();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -721,14 +730,20 @@ void printConfigSummary() {
|
|||||||
printBool(items);
|
printBool(items);
|
||||||
debugSerial<<F("\ninputs ");
|
debugSerial<<F("\ninputs ");
|
||||||
printBool(inputs);
|
printBool(inputs);
|
||||||
|
#ifndef MODBUS_DISABLE
|
||||||
debugSerial<<F("\nmodbus ");
|
debugSerial<<F("\nmodbus ");
|
||||||
printBool(modbusArr);
|
printBool(modbusArr);
|
||||||
|
#endif
|
||||||
debugSerial<<F("\nmqtt ");
|
debugSerial<<F("\nmqtt ");
|
||||||
printBool(mqttArr);
|
printBool(mqttArr);
|
||||||
|
#ifdef _owire
|
||||||
debugSerial<<F("\n1-wire ");
|
debugSerial<<F("\n1-wire ");
|
||||||
printBool(owArr);
|
printBool(owArr);
|
||||||
|
#endif
|
||||||
|
#ifdef SYSLOG_ENABLE
|
||||||
debugSerial<<F("\nudp syslog ");
|
debugSerial<<F("\nudp syslog ");
|
||||||
printBool(udpSyslogArr);
|
printBool(udpSyslogArr);
|
||||||
|
#endif
|
||||||
debugSerial << eol;
|
debugSerial << eol;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -759,6 +774,7 @@ int loadConfigFromEEPROM()
|
|||||||
debugSerial<<F("\nNo stored config\n");
|
debugSerial<<F("\nNo stored config\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmdFunctionReq(int arg_cnt, char **args) {
|
void cmdFunctionReq(int arg_cnt, char **args) {
|
||||||
@@ -873,8 +889,7 @@ void cmdFunctionGet(int arg_cnt, char **args) {
|
|||||||
//restoreState();
|
//restoreState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void printBool(bool arg) { (arg) ? debugSerial<<F("on") : debugSerial<<F("off"); }
|
void printBool(bool arg) { (arg) ? debugSerial<<F("+") : debugSerial<<F("-"); }
|
||||||
|
|
||||||
|
|
||||||
void saveFlash(short n, char *str) {
|
void saveFlash(short n, char *str) {
|
||||||
short i;
|
short i;
|
||||||
@@ -902,7 +917,6 @@ int ipLoadFromFlash(short n, IPAddress &ip) {
|
|||||||
ip[i] = EEPROM.read(n++);
|
ip[i] = EEPROM.read(n++);
|
||||||
return (ip[0] && (ip[0] != 0xff));
|
return (ip[0] && (ip[0] != 0xff));
|
||||||
}
|
}
|
||||||
|
|
||||||
lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||||
{
|
{
|
||||||
int responseStatusCode = 0;
|
int responseStatusCode = 0;
|
||||||
@@ -918,7 +932,13 @@ lan_status loadConfigFromHttp(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]);
|
||||||
#else
|
#else
|
||||||
|
#ifndef FLASH_64KB
|
||||||
snprintf(URI, sizeof(URI), "/%s_config.json",QUOTE(DEVICE_NAME));
|
snprintf(URI, sizeof(URI), "/%s_config.json",QUOTE(DEVICE_NAME));
|
||||||
|
#else
|
||||||
|
strncpy_P(URI, "/", sizeof(URI));
|
||||||
|
strncat(URI, QUOTE(DEVICE_NAME), sizeof(URI));
|
||||||
|
strncat(URI, "_config.json", sizeof(URI));
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
debugSerial<<F("Config URI: http://")<<configServer<<URI<<eol;
|
debugSerial<<F("Config URI: http://")<<configServer<<URI<<eol;
|
||||||
|
|
||||||
@@ -1002,22 +1022,13 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
|||||||
|
|
||||||
if (!root) {
|
if (!root) {
|
||||||
debugSerial<<F("Config parsing failed\n");
|
debugSerial<<F("Config parsing failed\n");
|
||||||
// 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);
|
|
||||||
debugSerial<<outstr);
|
|
||||||
free (outstr);
|
|
||||||
*/
|
|
||||||
debugSerial<<response;
|
debugSerial<<response;
|
||||||
applyConfig();
|
applyConfig();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debugSerial<<F("Config retrieving failed\n");
|
debugSerial<<F("Config retrieving failed\n");
|
||||||
//nextLanCheckTime=millis()+15000;
|
|
||||||
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
return READ_RE_CONFIG;//-11; //Load from NVRAM
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -1225,7 +1236,9 @@ void setupCmdArduino() {
|
|||||||
cmdAdd("save", cmdFunctionSave);
|
cmdAdd("save", cmdFunctionSave);
|
||||||
cmdAdd("load", cmdFunctionLoad);
|
cmdAdd("load", cmdFunctionLoad);
|
||||||
cmdAdd("get", cmdFunctionGet);
|
cmdAdd("get", cmdFunctionGet);
|
||||||
|
#ifndef FLASH_64KB
|
||||||
cmdAdd("mac", cmdFunctionSetMac);
|
cmdAdd("mac", cmdFunctionSetMac);
|
||||||
|
#endif
|
||||||
cmdAdd("kill", cmdFunctionKill);
|
cmdAdd("kill", cmdFunctionKill);
|
||||||
cmdAdd("req", cmdFunctionReq);
|
cmdAdd("req", cmdFunctionReq);
|
||||||
cmdAdd("ip", cmdFunctionIp);
|
cmdAdd("ip", cmdFunctionIp);
|
||||||
@@ -1368,7 +1381,6 @@ void thermoLoop(void) {
|
|||||||
if (millis() < nextThermostatCheck)
|
if (millis() < nextThermostatCheck)
|
||||||
return;
|
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)) {
|
||||||
aJsonObject *thermoExtensionArray = aJson.getArrayItem(thermoItem, I_EXT);
|
aJsonObject *thermoExtensionArray = aJson.getArrayItem(thermoItem, I_EXT);
|
||||||
|
|||||||
@@ -55,13 +55,17 @@
|
|||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ModbusMaster.h>
|
|
||||||
#include "aJSON.h"
|
#include "aJSON.h"
|
||||||
#include <Cmd.h>
|
#include <Cmd.h>
|
||||||
#include "stdarg.h"
|
#include "stdarg.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "inputs.h"
|
#include "inputs.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef MODBUS_DISABLE
|
||||||
|
#include <ModbusMaster.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef ARDUINO_ARCH_STM32F1
|
#ifndef ARDUINO_ARCH_STM32F1
|
||||||
#include "FastLED.h"
|
#include "FastLED.h"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -158,6 +158,8 @@
|
|||||||
|
|
||||||
#ifndef Wiz5500
|
#ifndef Wiz5500
|
||||||
#define W5100_ETHERNET_SHIELD
|
#define W5100_ETHERNET_SHIELD
|
||||||
|
#else
|
||||||
|
#define W5500_ETHERNET_SHIELD
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define eol "\n"
|
#define eol "\n"
|
||||||
|
|||||||
@@ -100,11 +100,13 @@ extern char _end;
|
|||||||
extern "C" char *sbrk(int i);
|
extern "C" char *sbrk(int i);
|
||||||
|
|
||||||
unsigned long freeRam() {
|
unsigned long freeRam() {
|
||||||
|
#ifndef DISABLE_FREERAM_PRINT
|
||||||
char *heapend = sbrk(0);
|
char *heapend = sbrk(0);
|
||||||
register char *stack_ptr asm( "sp" );
|
register char *stack_ptr asm( "sp" );
|
||||||
struct mallinfo mi = mallinfo();
|
struct mallinfo mi = mallinfo();
|
||||||
|
|
||||||
return stack_ptr - heapend + mi.fordblks;
|
return stack_ptr - heapend + mi.fordblks;
|
||||||
|
#endif
|
||||||
|
return 7777;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -156,6 +158,8 @@ void printFloatValueToStr(float value, char *valstr) {
|
|||||||
|
|
||||||
#define ARDBUFFER 16 //Buffer for storing intermediate strings. Performance may vary depending on size.
|
#define ARDBUFFER 16 //Buffer for storing intermediate strings. Performance may vary depending on size.
|
||||||
|
|
||||||
|
#ifndef ARDUINO_ARCH_STM32F1
|
||||||
|
|
||||||
int log(const char *str, ...)//TODO: __FlashStringHelper str support
|
int log(const char *str, ...)//TODO: __FlashStringHelper str support
|
||||||
{
|
{
|
||||||
int i, count=0, j=0, flag=0;
|
int i, count=0, j=0, flag=0;
|
||||||
@@ -207,6 +211,7 @@ int log(const char *str, ...)//TODO: __FlashStringHelper str support
|
|||||||
Serial.println(); //Print trailing newline
|
Serial.println(); //Print trailing newline
|
||||||
return count + 1; //Return number of arguments detected
|
return count + 1; //Return number of arguments detected
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#pragma message(VAR_NAME_VALUE(debugSerial))
|
#pragma message(VAR_NAME_VALUE(debugSerial))
|
||||||
|
|||||||
@@ -9,19 +9,19 @@
|
|||||||
; http://docs.platformio.org/page/projectconf.html
|
; http://docs.platformio.org/page/projectconf.html
|
||||||
[platformio]
|
[platformio]
|
||||||
src_dir = lighthub
|
src_dir = lighthub
|
||||||
env_default =
|
;env_default =
|
||||||
; megaatmega2560
|
; megaatmega2560
|
||||||
; megaatmega2560-net
|
; megaatmega2560-net
|
||||||
; due
|
; due
|
||||||
; esp8266
|
; esp8266
|
||||||
; esp32
|
; esp32
|
||||||
; megaatmega2560-5500
|
; megaatmega2560-5500
|
||||||
due-5500
|
; due-5500
|
||||||
; controllino
|
; controllino
|
||||||
; stm32
|
; stm32
|
||||||
|
|
||||||
build_dir = /tmp/pioenvs
|
;build_dir = /tmp/pioenvs
|
||||||
libdeps_dir = /tmp/piolibdeps
|
;libdeps_dir = /tmp/piolibdeps
|
||||||
|
|
||||||
[env:esp32]
|
[env:esp32]
|
||||||
platform = espressif32
|
platform = espressif32
|
||||||
@@ -247,35 +247,37 @@ lib_deps =
|
|||||||
https://github.com/livello/PrintEx#is-select-redecl
|
https://github.com/livello/PrintEx#is-select-redecl
|
||||||
|
|
||||||
;TODO:STM32 compilation problems
|
;TODO:STM32 compilation problems
|
||||||
;[env:stm32]
|
[env:stm32]
|
||||||
;platform = ststm32
|
platform = ststm32
|
||||||
;framework = arduino
|
framework = arduino
|
||||||
;board = nucleo_f103rb
|
board = nucleo_f103rb
|
||||||
;upload_protocol = stlink
|
upload_protocol = stlink
|
||||||
;debug_tool = stlink
|
debug_tool = stlink
|
||||||
;build_flags = !bash check_custom_build_flags_stm32.sh
|
build_flags = !bash check_custom_build_flags_stm32.sh
|
||||||
;lib_ignore =
|
lib_ignore =
|
||||||
; DHT sensor library for ESPx
|
DHT sensor library for ESPx
|
||||||
; DmxDue
|
DmxDue
|
||||||
; DueFlashStorage
|
DueFlashStorage
|
||||||
; ESP-Dmx
|
ESP-Dmx
|
||||||
; WifiManager
|
WifiManager
|
||||||
; FastLED
|
FastLED
|
||||||
; Ethernet
|
Ethernet
|
||||||
;lib_deps =
|
https://github.com/anklimov/Ethernet
|
||||||
|
DMXSerial
|
||||||
|
DmxSimple
|
||||||
|
httpClient
|
||||||
|
SD
|
||||||
|
PrintEx
|
||||||
|
Ethernet2
|
||||||
|
Artnet
|
||||||
|
|
||||||
|
|
||||||
|
lib_deps =
|
||||||
; DallasTemperature
|
; 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/anklimov/ModbusMaster
|
https://github.com/knolleary/pubsubclient.git
|
||||||
;; https://github.com/Serasidis/Ethernet_STM.git
|
Adafruit Unified Sensor
|
||||||
;; https://github.com/livello/Ethernet_STM.git
|
DHT sensor library
|
||||||
; https://github.com/knolleary/pubsubclient.git
|
Streaming
|
||||||
; Adafruit Unified Sensor
|
|
||||||
; DHT sensor library
|
|
||||||
;; https://github.com/anklimov/DMXSerial
|
|
||||||
;; Syslog
|
|
||||||
;; https://github.com/No3x/Syslog.git
|
|
||||||
; https://github.com/arcao/Syslog.git
|
|
||||||
;; UIPEthernet
|
|
||||||
; Streaming
|
|
||||||
|
|||||||
Reference in New Issue
Block a user