From 70c31dd0eaea7aa108d4942a0763600f59b2e7cb Mon Sep 17 00:00:00 2001 From: livello Date: Fri, 23 Mar 2018 01:29:21 +0300 Subject: [PATCH] custom firmware mac address build_flags_template disabling freeram print removing CR if no previous thermostat printing --- README.md | 21 +++++++++++++++++---- build_flags_template.sh | 16 ++++++++++++++++ lighthub/main.cpp | 29 ++++++++++++++++++++--------- lighthub/main.h | 6 ++++++ lighthub/utils.cpp | 13 ++++++++++++- lighthub/utils.h | 1 + platformio.ini | 4 ++-- 7 files changed, 74 insertions(+), 16 deletions(-) create mode 100644 build_flags_template.sh diff --git a/README.md b/README.md index 0c17f19..77cc70c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LightHub is Flexible, Arduino-Mega/Arduino DUE/ESP8266 based SmartHome controller -It allow to connect together: +It allows connecting together: * Contact sensors (switches, buttons etc) * 1-Wire temperature sensors (up to 20 on single bus) @@ -29,7 +29,7 @@ or to flash your DUE (need to correct path and port, of course) -# Dependences +# Dependencies (quite big number of libs required. Use git clone to have your local copy in your Arduino libs folder) Please check updates for all dependences. @@ -93,14 +93,27 @@ In linux you can open terminal, navigate to your programming directory, then * rm -Rf .piolibdeps // this will clean libraries folder. Try it if you have compilation problem * pio run -e megaatmega2560 //build for arduino mega * pio run -e due -t upload //build and upload firmware to arduino due +* platformio device monitor -b 115200 // open com port monitor with specified baud rate # Custom build flags * MY_CONFIG_SERVER=192.168.1.1 // address of external JSON-config http://192.168.1.1/de-ad-be-ef-fe-00.config.json * WATCH_DOG_TICKER_DISABLE=1 //disable wdt feature -* USE_1W_PIN=49 // use direct connection to 1W devices, no I2C bridge DS2482-100 +* USE_1W_PIN=49 // use direct connection to 1W devices on 49 pin, no I2C bridge DS2482-100 * SD_CARD_INSERTED=1 // enable sd-card support and fix lan starting * SERIAL_BAUD=115200 // set baud rate for console on Serial0 +* Wiz5500 //Use Wiznet 5500 library instead Wiznet 5100 +* DISABLE_FREERAM_PRINT // disable printing free Ram in bytes +* CUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:00 //set firmware macaddress -export PLATFORMIO_BUILD_FLAGS="-DMY_CONFIG_SERVER=192.168.1.1 -DWATCH_DOG_TICKER_DISABLE=1 -DUSE_1W_PIN=49 -DSERIAL_BAUD=115200 -DSD_CARD_INSERTED=1" +Look at build_flags_template.sh for customizing. +# Default compilation behavior: +* Config server: lazyhome.ru +* Watchdog enabled +* 1-Wire communication with DS2482-100 I2C driver +* No SD +* Serial speed 115200 +* Wiznet 5100 (for MEGA & DUE) +* Free Ram printing enabled +* de:ad:be:ef:fe:00 diff --git a/build_flags_template.sh b/build_flags_template.sh new file mode 100644 index 0000000..882b3d3 --- /dev/null +++ b/build_flags_template.sh @@ -0,0 +1,16 @@ +#! /bin/bash +# usage: +# first make your own copy of template +# cp build_flags_template.sh my_build_flags.sh +# then source it +# source my_build_flags.sh + export FLAGS="-DMY_CONFIG_SERVER=lazyhome.ru" + export FLAGS="$FLAGS -DWATCH_DOG_TICKER_DISABLE" + export FLAGS="$FLAGS -DUSE_1W_PIN=12" + export FLAGS="$FLAGS -DSD_CARD_INSERTED" + export FLAGS="$FLAGS -DSERIAL_BAUD=115200" + export FLAGS="$FLAGS -DWiz5500" + export FLAGS="$FLAGS -DDISABLE_FREERAM_PRINT" + export FLAGS="$FLAGS -DCUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:00" + export PLATFORMIO_BUILD_FLAGS="$FLAGS" + unset FLAGS \ No newline at end of file diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 0ae4104..5741a06 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -906,8 +906,6 @@ int getConfig(int arg_cnt, char **args) return 2; } -#define TXEnablePin 13 - void preTransmission() { digitalWrite(TXEnablePin, 1); } @@ -926,6 +924,10 @@ void setup_main() { Serial.println(F("WATCHDOG TICKER DISABLED")); #endif +#ifdef DISABLE_FREERAM_PRINT + Serial.println(F("FreeRam printing DISABLED")); +#endif + #ifdef SD_CARD_INSERTED sd_card_w5100_setup(); #endif @@ -944,15 +946,22 @@ void setup_main() { #endif short macvalid = 0; - byte defmac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0}; + +#ifdef FIRMWARE_MAC + byte firmwareMacAddress[6] = FIRMWARE_MAC; +#else + byte firmwareMacAddress[6]; + const char* macStr = QUOTE(CUSTOM_FIRMWARE_MAC); + parseBytes(macStr, ':', firmwareMacAddress, 6, 16); +#endif for (short i = 0; i < 6; i++) { mac[i] = EEPROM.read(i); if (mac[i] != 0 && mac[i] != 0xff) macvalid = 1; } if (!macvalid) { - Serial.println(F("Invalid MAC: set default")); - memcpy(mac, defmac, 6); + Serial.println(F("Invalid MAC: set firmware's MAC")); + memcpy(mac, firmwareMacAddress, 6); } printMACAddress(); @@ -1143,7 +1152,7 @@ void thermoLoop(void) { #define IET_ATTEMPTS 1 if (millis() > thermocheck) { - + bool thermostatCheckPrinted = false; aJsonObject *item = items->child; while (item) { @@ -1167,6 +1176,7 @@ void thermoLoop(void) { mqttClient.publish("/alarm", item->name); } + thermostatCheckPrinted = true; Serial.print(item->name); Serial.print(F(" Set:")); Serial.print(temp); @@ -1190,18 +1200,19 @@ void thermoLoop(void) { } //Reached settings else Serial.println(F(" --")); // Nothing to do } - } } item = item->next; } - thermocheck = millis() + 5000; + +#ifndef DISABLE_FREERAM_PRINT + (thermostatCheckPrinted) ? Serial.print(F("\nfree:")) : Serial.print(F(" ")); Serial.print(freeRam()); Serial.print(" "); +#endif } - } diff --git a/lighthub/main.h b/lighthub/main.h index b892a43..e7dc8a2 100644 --- a/lighthub/main.h +++ b/lighthub/main.h @@ -5,11 +5,17 @@ #ifndef LIGHTHUB_MAIN_H #define LIGHTHUB_MAIN_H +#define TXEnablePin 13 #ifndef SERIAL_BAUD #define SERIAL_BAUD 115200 #endif +#define CUSTOM_FIRMWARE_MAC C4:3E:1f:03:1B:1E +#ifndef CUSTOM_FIRMWARE_MAC +#define FIRMWARE_MAC {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0} +#endif + #include "Arduino.h" #include "DallasTemperature.h" diff --git a/lighthub/utils.cpp b/lighthub/utils.cpp index 4459e31..b3178af 100644 --- a/lighthub/utils.cpp +++ b/lighthub/utils.cpp @@ -108,4 +108,15 @@ unsigned long freeRam() return stack_ptr - heapend + mi.fordblks; } - #endif + #endif + +void parseBytes(const char* str, char separator, byte* bytes, int maxBytes, int base) { + for (int i = 0; i < maxBytes; i++) { + bytes[i] = strtoul(str, NULL, base); // Convert byte + str = strchr(str, separator); // Find next separator + if (str == NULL || *str == '\0') { + break; // No more separators, exit + } + str++; // Point to next character after separator + } +} \ No newline at end of file diff --git a/lighthub/utils.h b/lighthub/utils.h index 41eaa7e..79fe317 100644 --- a/lighthub/utils.h +++ b/lighthub/utils.h @@ -25,3 +25,4 @@ void SetAddr(char * out, uint8_t* addr); uint8_t HEX2DEC(char i); int getInt(char ** chan); unsigned long freeRam (); +void parseBytes(const char* str, char separator, byte* bytes, int maxBytes, int base); \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 031343f..c5d2eee 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,8 +10,8 @@ [platformio] src_dir = lighthub env_default = -; megaatmega2560 - due + megaatmega2560 +; due [env:due] platform = atmelsam