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