From 1133883b252f65479545f49116453bfff489e04f Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 19 Feb 2024 16:07:13 +0300 Subject: [PATCH] NOIP compilation option & some inits --- build-flags/build_flags_stm32-noip | 44 ++++++++++ lighthub/abstractch.cpp | 7 ++ lighthub/abstractin.cpp | 5 +- lighthub/flashstream.h | 2 +- lighthub/inputs.cpp | 12 ++- lighthub/item.cpp | 26 ++++-- lighthub/itemCmd.cpp | 2 +- lighthub/main.cpp | 134 ++++++++++++++++++++--------- lighthub/main.h | 40 +++++---- lighthub/modules/out_pwm.cpp | 7 +- lighthub/modules/out_relay.cpp | 2 +- lighthub/seekablestream.h | 2 +- lighthub/streamlog.cpp | 1 + lighthub/templateStr.h | 2 +- lighthub/utils.cpp | 13 +-- platformio.ini | 70 +++++++++++++++ 16 files changed, 287 insertions(+), 82 deletions(-) create mode 100644 build-flags/build_flags_stm32-noip diff --git a/build-flags/build_flags_stm32-noip b/build-flags/build_flags_stm32-noip new file mode 100644 index 0000000..94b5161 --- /dev/null +++ b/build-flags/build_flags_stm32-noip @@ -0,0 +1,44 @@ +-DNOIP +-DDMX_DISABLE +-DMODBUS_DISABLE +-DMBUS_DISABLE +-DOWIRE_DISABLE +-DDHT_DISABLE +-DCOUNTER_DISABLE +-DNO_HOMIE +-DCSSHDC_DISABLE +-DSPILED_DISABLE +-DAC_DISABLE +-DPID_DISABLE +-DMULTIVENT_DISABLE +-DMOTOR_DISABLE + + +-DENABLE_HWSERIAL1 +-DdebugSerialPort=Serial1 + +#-DFLASH_BASE_ADDRESS +#-DFLASH_DATA_SECTOR +#-DFLASH_PAGE_NUMBER + +-D PIO_FRAMEWORK_ARDUINO_ENABLE_MASS_STORAGE +-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC_AND_MSC + +#-DdebugSerialPort=SerialUSB +#-DSerialPortType=USBSerial +#-DSERIAL_BAUD=0 + +#-DPIO_FRAMEWORK_ARDUINO_ENABLE_CDC +#-DUSBCON +#-DUSBD_VID=0x0483 +#-DUSBD_PID=0x5740 +#-DUSB_MANUFACTURER="Unknown" +#-DUSB_PRODUCT="\"BLUEPILL_F103C8\"" +#-DHAL_PCD_MODULE_ENABLED +#-D USBD_USE_CDC + +-D HAL_CAN_MODULE_ENABLED +#HAL_ETH_MODULE_DISABLED +#HAL_SD_MODULE_DISABLED +#HAL_DAC_MODULE_DISABLED +#-DMERCURY_ENABLE \ No newline at end of file diff --git a/lighthub/abstractch.cpp b/lighthub/abstractch.cpp index 26b9f0e..ae7dfa0 100644 --- a/lighthub/abstractch.cpp +++ b/lighthub/abstractch.cpp @@ -1,13 +1,18 @@ #include "abstractch.h" +#if not defined (NOIP) #include +#endif #include "utils.h" #include #include "main.h" extern lan_status lanStatus; + +#if not defined (NOIP) extern PubSubClient mqttClient; extern int8_t ethernetIdleCount; +#endif int abstractCh::publishTopic(const char* topic, long value, const char* subtopic) { @@ -25,6 +30,7 @@ int abstractCh::publishTopic(const char* topic, float value, const char* subtopi int abstractCh::publishTopic(const char* topic, const char * value, const char* subtopic) { + #if not defined (NOIP) char addrstr[MQTT_TOPIC_LENGTH]; if (!isNotRetainingStatus()) return 0; if (topic) @@ -38,5 +44,6 @@ int abstractCh::publishTopic(const char* topic, const char * value, const char* return 1; } } + #endif return 0; }; diff --git a/lighthub/abstractin.cpp b/lighthub/abstractin.cpp index a6a9b21..b39aab4 100644 --- a/lighthub/abstractin.cpp +++ b/lighthub/abstractin.cpp @@ -1,14 +1,17 @@ #include "abstractin.h" #include "abstractch.h" +#if not defined (NOIP) #include +extern PubSubClient mqttClient; +#endif #include "utils.h" #include #include "inputs.h" #include "main.h" extern lan_status lanStatus; -extern PubSubClient mqttClient; + int abstractIn::publish(long value, const char* subtopic) { diff --git a/lighthub/flashstream.h b/lighthub/flashstream.h index aa49ea1..b073916 100644 --- a/lighthub/flashstream.h +++ b/lighthub/flashstream.h @@ -56,7 +56,7 @@ unsigned int startPos; char openmode ; public: - flashStream():seekableStream(MAX_STREAM_SIZE){openmode = '\0';}; + flashStream():seekableStream(MAX_STREAM_SIZE),pos(0),startPos(0),openmode('\0'){}; void setSize(unsigned int _size); int open(short fileNum, char mode='\0') ; virtual int open(String _filename, char mode='\0') override; diff --git a/lighthub/inputs.cpp b/lighthub/inputs.cpp index 6400ff2..362c4ad 100644 --- a/lighthub/inputs.cpp +++ b/lighthub/inputs.cpp @@ -21,7 +21,9 @@ e-mail anklimov@gmail.com #include "inputs.h" #include "item.h" #include "utils.h" +#if not defined (NOIP) #include +#endif #include "main.h" #include "itemCmd.h" @@ -37,8 +39,9 @@ e-mail anklimov@gmail.com #include "Adafruit_MCP23X17.h" Adafruit_MCP23X17 mcp; #endif - +#if not defined (NOIP) extern PubSubClient mqttClient; +#endif extern aJsonObject *root; extern int8_t ethernetIdleCount; extern int8_t configLocked; @@ -966,6 +969,7 @@ void Input::onContactChanged(int newValue) { } else #endif { +#if not defined (NOIP) char addrstr[MQTT_TOPIC_LENGTH]; strncpy(addrstr,emit->valuestring,sizeof(addrstr)); if (mqttClient.connected() && !ethernetIdleCount) @@ -980,6 +984,7 @@ if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestri else if (strlen(rcmd->valuestring))mqttClient.publish(addrstr, rcmd->valuestring, true); } } +#endif //NOIP } } // emit if (item && item->type == aJson_String) { @@ -1011,7 +1016,7 @@ void Input::onAnalogChanged(itemCmd newValue) { aJsonObject *item = aJson.getObjectItem(inputObj, "item"); aJsonObject *emit = aJson.getObjectItem(inputObj, "emit"); - +#if not defined (NOIP) if (emit && emit->type == aJson_String) { //#ifdef WITH_DOMOTICZ @@ -1029,7 +1034,7 @@ void Input::onAnalogChanged(itemCmd newValue) { if (mqttClient.connected() && !ethernetIdleCount) mqttClient.publish(addrstr, strVal, true); } - +#endif //NOIP if (item && item->type == aJson_String) { Item it(item->valuestring); if (it.isValid()) it.Ctrl(newValue); @@ -1073,6 +1078,7 @@ readCache::readCache() { addr=0; type=0; + cached_data = 0; } uint16_t readCache::analogReadCached (uint8_t _pin) diff --git a/lighthub/item.cpp b/lighthub/item.cpp index 5a9e5aa..d67805d 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -40,8 +40,9 @@ e-mail anklimov@gmail.com #ifndef MODBUS_DISABLE #include #endif - +#if not defined (NOIP) #include +#endif #include "modules/out_spiled.h" #include "modules/out_ac.h" #include "modules/out_motor.h" @@ -70,7 +71,9 @@ short modbusBusy = 0; //bool isPendedModbusWrites = false; extern aJsonObject *pollingItem; +#if not defined (NOIP) extern PubSubClient mqttClient; +#endif extern int8_t ethernetIdleCount; extern int8_t configLocked; extern lan_status lanStatus; @@ -1470,10 +1473,16 @@ if ((!driver || driver->isAllowed(cmd)) && (!getFlag(FLAG_FREEZED))) { thermostatStore tStore; tStore.asint=getExt(); - if (!tStore.timestamp16) mqttClient.publish("/alarmoff/snsr", itemArr->name); + if (!tStore.timestamp16) + { + infoSerial<name<name); + #endif + } tStore.tempX100=cmd.getFloat()*100.; //Save measurement tStore.timestamp16=millisNZ(8) & 0xFFFF; //And timestamp - //debugSerial<name<")<")<")< EthernetClient ethClient; +#endif //NOIP #endif #if defined(OTA) @@ -156,7 +158,9 @@ volatile int8_t configLocked = 0; ModbusMaster node; #endif +#if not defined (NOIP) PubSubClient mqttClient(ethClient); +#endif bool wifiInitialized; @@ -401,6 +405,7 @@ int intopic; return 0; } +#if not defined (NOIP) void mqttCallback(char *topic, byte *payload, unsigned int length) { if (!payload || !length) {debugSerial< HAVE_IP_ADDRESS) { mqttClient.loop(); @@ -2703,7 +2740,9 @@ void loop_main() { MDNS.update(); #endif #endif - } + } +#endif //NOIP + #ifdef _owire yield(); @@ -2776,6 +2815,8 @@ inputLoop(CHECK_INPUT); if (initializedListeners) ipmodbusLoop(); #endif } + +#if not defined (NOIP) void ethernetIdle(void){ ethernetIdleCount++; wdt_res(); @@ -2785,7 +2826,7 @@ ethernetIdleCount++; cmdPoll(); ethernetIdleCount--; }; - +#endif void modbusIdle(void) { @@ -2796,10 +2837,11 @@ void modbusIdle(void) { yield(); inputLoop(CHECK_INPUT); + #if not defined (NOIP) if (lanLoop() > HAVE_IP_ADDRESS) { // Begin network runners yield(); - mqttClient.loop(); + mqttClient.loop(); #ifdef _artnet if (artnet && initializedListeners) artnet->read(); #endif @@ -2816,6 +2858,8 @@ void modbusIdle(void) { #endif } //End network runners +#endif + #ifdef _dmxin DMXCheck(); #endif @@ -3027,14 +3071,18 @@ void thermoLoop(void) { if (isTimeOver(tStore.timestamp16,millisNZ(8) & 0xFFFF,PERIOD_THERMOSTAT_FAILED >> 8,0xFFFF)) { errorSerial<name<name); + #endif tStore.timestamp16=0; //Stop termostat thermostat.setExt(tStore.asint); thermoRelay(thermoPin,HEATER_ERROR); } else { // Not expired yet + #if not defined(NOIP) if (curTemp > overHeatTemp) mqttClient.publish("/alarm/ovrht", thermoItem->name); + #endif if (!active) thermoRelay(thermoPin,HEATER_OFF);//OFF else if (curTemp < thermoSetting - THERMO_GIST_CELSIUS) thermoRelay(thermoPin,HEATER_HEAT);//ON diff --git a/lighthub/main.h b/lighthub/main.h index f7af321..1d57976 100644 --- a/lighthub/main.h +++ b/lighthub/main.h @@ -8,13 +8,17 @@ #if defined(__SAM3X8E__) #include -#include + #if not defined (NOIP) + #include + #endif //#include "TimerInterrupt_Generic.h" #endif #if defined(ARDUINO_ARCH_AVR) -#include "HTTPClient.h" -//#include + #if not defined (NOIP) + #include "HTTPClient.h" + #endif + #include #include #endif @@ -35,7 +39,7 @@ //#define Ethernet WiFi #endif -#if defined ARDUINO_ARCH_ESP32 +#if defined (ARDUINO_ARCH_ESP32) #include //this needs to be first, or it all crashes and burns... //#include "SPIFFS.h" //#include @@ -58,7 +62,7 @@ #include #endif -#ifdef ARDUINO_ARCH_STM32 +#if defined (ARDUINO_ARCH_STM32) and not defined (NOIP) #include "HttpClient.h" //#include "UIPEthernet.h" //#include @@ -156,7 +160,8 @@ extern Streamlog errorSerial; #include #endif #define Ethernet WiFi -#else //Wired connection +#else +#if not defined (NOIP) //Wired connection #ifdef Wiz5500 #include #else @@ -166,6 +171,7 @@ extern Streamlog errorSerial; #include #endif #endif +#endif #endif @@ -190,7 +196,9 @@ extern Streamlog errorSerial; #include "Arduino.h" #include "utils.h" #include "textconst.h" -#include + #if not defined (NOIP) + #include + #endif #include #include #include "aJSON.h" @@ -233,11 +241,16 @@ typedef union { bool isNotRetainingStatus(); +#if not defined (NOIP) void mqttCallback(char *topic, byte *payload, unsigned int length); - void printMACAddress(); - lan_status lanLoop(); +int loadConfigFromHttp(); +void onInitialStateInitLAN(); +void onMQTTConnect(); +void ip_ready_config_loaded_connecting_to_broker(); +void setupMacAddress(); +#endif #ifndef OWIRE_DISABLE void Changed(int i, DeviceAddress addr, float currentTemp); @@ -274,7 +287,7 @@ void saveFlash(short n, IPAddress& ip); int ipLoadFromFlash(short n, IPAddress &ip); */ -int loadConfigFromHttp(); + void preTransmission(); @@ -306,8 +319,6 @@ void printConfigSummary(); void setupCmdArduino(); -void setupMacAddress(); - void printFirmwareVersionAndBuildOptions(); bool IsThermostat(const aJsonObject *item); @@ -316,14 +327,9 @@ bool disabledDisconnected(const aJsonObject *thermoExtensionArray, int thermoLat void resetHard(); -void onInitialStateInitLAN(); - -void ip_ready_config_loaded_connecting_to_broker(); void printCurentLanConfig(); -void onMQTTConnect(); - int16_t attachMaturaTimer(); //void printFreeRam(); diff --git a/lighthub/modules/out_pwm.cpp b/lighthub/modules/out_pwm.cpp index 5f7f78c..026568f 100644 --- a/lighthub/modules/out_pwm.cpp +++ b/lighthub/modules/out_pwm.cpp @@ -125,10 +125,13 @@ switch (cmd.getCmd()){ switch (cType) { case CH_PWM: - { short k; + { short k ; if (authorized || !isProtectedPin(iaddr)) + { analogWrite(iaddr, k=cmd.getPercents255(inverse)); - debugSerial<setExt(0); //if (item->getCmd()) item->setFlag(FLAG_COMMAND); //if (item->itemVal) item->setFlag(FLAG_PARAMETERS); setStatus(CST_INITIALIZED); -if (item->isActive()>0) ///???? +if (item && (item->isActive()>0)) ///???? { item->setExt(millisNZ()); } diff --git a/lighthub/seekablestream.h b/lighthub/seekablestream.h index c9f245d..e1fdbe1 100644 --- a/lighthub/seekablestream.h +++ b/lighthub/seekablestream.h @@ -14,7 +14,7 @@ bool textMode; uint16_t contentType; public: -seekableStream(unsigned int size):Stream(),streamSize(size) {}; +seekableStream(unsigned int size):Stream(),streamSize(size),textMode(false),contentType(0) {}; virtual bool checkPermissions(char mode) {return true;}; unsigned int getSize() {return streamSize;} void setSize (unsigned int size) {streamSize = size;}; diff --git a/lighthub/streamlog.cpp b/lighthub/streamlog.cpp index dd71974..5f46ffd 100644 --- a/lighthub/streamlog.cpp +++ b/lighthub/streamlog.cpp @@ -28,6 +28,7 @@ Streamlog::Streamlog (SerialPortType * _serialPort, uint8_t _severity, uint8_t { serialPort=_serialPort; severity=_severity; + ledPattern=_ledPattern; } #endif /* diff --git a/lighthub/templateStr.h b/lighthub/templateStr.h index 4313796..18a264e 100644 --- a/lighthub/templateStr.h +++ b/lighthub/templateStr.h @@ -10,7 +10,7 @@ extern aJsonObject * topics; class templateStream : public Stream { public: - templateStream(char *s, short sfx=0) : str(s), pos(0), val(NULL), valpos(0), bucket(0),suffix(sfx) { } + templateStream(char *s, short sfx=0) : str(s), pos(0), val(NULL), valpos(0), bucket(0),suffix(sfx) {buffer[0]='\0'; } // Stream methods virtual int available() { return str[pos]; } diff --git a/lighthub/utils.cpp b/lighthub/utils.cpp index 60227c9..669874c 100644 --- a/lighthub/utils.cpp +++ b/lighthub/utils.cpp @@ -25,7 +25,11 @@ e-mail anklimov@gmail.com #include "main.h" #include "item.h" +#if not defined (NOIP) #include +extern PubSubClient mqttClient; +extern int8_t ethernetIdleCount; +#endif #include #include "templateStr.h" @@ -38,10 +42,6 @@ e-mail anklimov@gmail.com #endif extern int8_t configLocked; -extern int8_t ethernetIdleCount; -extern PubSubClient mqttClient; - - #if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32) #include @@ -742,12 +742,13 @@ switch (cmdType) //strncpy(addrstr,emit->valuestring,sizeof(addrstr)); + #if not defined (NOIP) if (mqttClient.connected() && !ethernetIdleCount) { if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring); mqttClient.publish(addrstr, emitCommand , true); } - + #endif } // emit if (item && item->type == aJson_String) { @@ -827,7 +828,7 @@ serialParamType str2SerialParam(char * str) { //debugSerial<< i << F(" ") << pgm_read_word_near(&serialModes_P[i].mode)<< endl; - if (sizeof(serialModesNum)==4) + if (sizeof(serialParamType)==4) return pgm_read_dword_near(&serialModes_P[i].mode); else return pgm_read_word_near(&serialModes_P[i].mode); diff --git a/platformio.ini b/platformio.ini index 093ddf1..a1ee855 100644 --- a/platformio.ini +++ b/platformio.ini @@ -911,6 +911,76 @@ lib_deps = monitor_speed = 115200 + +[env:stm32-noip] +platform = ststm32 +board = genericSTM32F103RB +;olimexino +board_build.mcu = stm32f103rbt6 +;STM32Duino +;generic_stm32f103r +;board_build.ldscript=ldscripts\stm32f103rb_bootloader.ld +board_build.f_cpu = 72000000L +framework = arduino +;board_build.core = maple +;board_build.core = maple // STM32Duino (DEFAULT) // STM32L0 +;board_build.core = stm32lo +;monitor_dtr = 1 +upload_protocol = serial +;debug_tool = cmsis-dap +build_flags = !python get_build_flags.py stm32-noip +lib_ignore = + ;DS2482_OneWire //UNCOMMENT for software 1-wire driver + DHT sensor library for ESPx + DmxDue + DueFlashStorage + ESPDMX + ESP-Dmx + WifiManager + FastLED + UIPEthernet + DMXSerial + DmxSimple + httpClient + SD + PrintEx + Ethernet2 + Artnet + Ethernet3 + WebServer + ESP_EEPROM + DHT sensor library + DallasTemperature + Adafruit Unified Sensor + DS2482_OneWire + ModbusMaster + Syslog + NRFFlashStorage + ClosedCube HDC1080 + SparkFun CCS811 Arduino Library + M5Stack + ArduinoOTA +lib_deps = + EEPROM + https://github.com/anklimov/aJson + https://github.com/anklimov/CmdArduino +; ArduinoHttpClient +; https://github.com/anklimov/pubsubclient.git + Streaming +; Ethernet + + Adafruit NeoPixel + Adafruit MCP23017 Arduino Library + Adafruit BusIO + SPI + br3ttb/PID@^1.2.1 +; ArduinoMDNS + https://github.com/khoih-prog/TimerInterrupt_Generic.git + ;https://github.com/anklimov/ModbusMaster + +monitor_speed = 115200 + + ; Run the following command to upload with this environment ; pio run -e Upload_ISP -t upload [env:Upload_ISP]