mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
custom firmware mac address
build_flags_template disabling freeram print removing CR if no previous thermostat printing
This commit is contained in:
21
README.md
21
README.md
@@ -1,7 +1,7 @@
|
|||||||
# LightHub
|
# LightHub
|
||||||
is Flexible, Arduino-Mega/Arduino DUE/ESP8266 based SmartHome controller
|
is Flexible, Arduino-Mega/Arduino DUE/ESP8266 based SmartHome controller
|
||||||
|
|
||||||
It allow to connect together:
|
It allows connecting together:
|
||||||
|
|
||||||
* Contact sensors (switches, buttons etc)
|
* Contact sensors (switches, buttons etc)
|
||||||
* 1-Wire temperature sensors (up to 20 on single bus)
|
* 1-Wire temperature sensors (up to 20 on single bus)
|
||||||
@@ -29,7 +29,7 @@ or
|
|||||||
to flash your DUE
|
to flash your DUE
|
||||||
|
|
||||||
(need to correct path and port, of course)
|
(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)
|
(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.
|
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
|
* 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 megaatmega2560 //build for arduino mega
|
||||||
* pio run -e due -t upload //build and upload firmware to arduino due
|
* 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
|
# 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
|
* 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
|
* 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
|
* SD_CARD_INSERTED=1 // enable sd-card support and fix lan starting
|
||||||
* SERIAL_BAUD=115200 // set baud rate for console on Serial0
|
* 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
|
||||||
|
|||||||
16
build_flags_template.sh
Normal file
16
build_flags_template.sh
Normal file
@@ -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
|
||||||
@@ -906,8 +906,6 @@ int getConfig(int arg_cnt, char **args)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TXEnablePin 13
|
|
||||||
|
|
||||||
void preTransmission() {
|
void preTransmission() {
|
||||||
digitalWrite(TXEnablePin, 1);
|
digitalWrite(TXEnablePin, 1);
|
||||||
}
|
}
|
||||||
@@ -926,6 +924,10 @@ void setup_main() {
|
|||||||
Serial.println(F("WATCHDOG TICKER DISABLED"));
|
Serial.println(F("WATCHDOG TICKER DISABLED"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef DISABLE_FREERAM_PRINT
|
||||||
|
Serial.println(F("FreeRam printing DISABLED"));
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef SD_CARD_INSERTED
|
#ifdef SD_CARD_INSERTED
|
||||||
sd_card_w5100_setup();
|
sd_card_w5100_setup();
|
||||||
#endif
|
#endif
|
||||||
@@ -944,15 +946,22 @@ void setup_main() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
short macvalid = 0;
|
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++) {
|
for (short i = 0; i < 6; i++) {
|
||||||
mac[i] = EEPROM.read(i);
|
mac[i] = EEPROM.read(i);
|
||||||
if (mac[i] != 0 && mac[i] != 0xff) macvalid = 1;
|
if (mac[i] != 0 && mac[i] != 0xff) macvalid = 1;
|
||||||
}
|
}
|
||||||
if (!macvalid) {
|
if (!macvalid) {
|
||||||
Serial.println(F("Invalid MAC: set default"));
|
Serial.println(F("Invalid MAC: set firmware's MAC"));
|
||||||
memcpy(mac, defmac, 6);
|
memcpy(mac, firmwareMacAddress, 6);
|
||||||
}
|
}
|
||||||
printMACAddress();
|
printMACAddress();
|
||||||
|
|
||||||
@@ -1143,7 +1152,7 @@ void thermoLoop(void) {
|
|||||||
#define IET_ATTEMPTS 1
|
#define IET_ATTEMPTS 1
|
||||||
|
|
||||||
if (millis() > thermocheck) {
|
if (millis() > thermocheck) {
|
||||||
|
bool thermostatCheckPrinted = false;
|
||||||
aJsonObject *item = items->child;
|
aJsonObject *item = items->child;
|
||||||
|
|
||||||
while (item) {
|
while (item) {
|
||||||
@@ -1167,6 +1176,7 @@ void thermoLoop(void) {
|
|||||||
mqttClient.publish("/alarm", item->name);
|
mqttClient.publish("/alarm", item->name);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
thermostatCheckPrinted = true;
|
||||||
Serial.print(item->name);
|
Serial.print(item->name);
|
||||||
Serial.print(F(" Set:"));
|
Serial.print(F(" Set:"));
|
||||||
Serial.print(temp);
|
Serial.print(temp);
|
||||||
@@ -1190,18 +1200,19 @@ void thermoLoop(void) {
|
|||||||
} //Reached settings
|
} //Reached settings
|
||||||
else Serial.println(F(" --")); // Nothing to do
|
else Serial.println(F(" --")); // Nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
item = item->next;
|
item = item->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
thermocheck = millis() + 5000;
|
thermocheck = millis() + 5000;
|
||||||
|
|
||||||
|
#ifndef DISABLE_FREERAM_PRINT
|
||||||
|
(thermostatCheckPrinted) ? Serial.print(F("\nfree:")) : Serial.print(F(" "));
|
||||||
Serial.print(freeRam());
|
Serial.print(freeRam());
|
||||||
Serial.print(" ");
|
Serial.print(" ");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,17 @@
|
|||||||
#ifndef LIGHTHUB_MAIN_H
|
#ifndef LIGHTHUB_MAIN_H
|
||||||
#define LIGHTHUB_MAIN_H
|
#define LIGHTHUB_MAIN_H
|
||||||
|
|
||||||
|
#define TXEnablePin 13
|
||||||
|
|
||||||
#ifndef SERIAL_BAUD
|
#ifndef SERIAL_BAUD
|
||||||
#define SERIAL_BAUD 115200
|
#define SERIAL_BAUD 115200
|
||||||
#endif
|
#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 "Arduino.h"
|
||||||
#include "DallasTemperature.h"
|
#include "DallasTemperature.h"
|
||||||
|
|
||||||
|
|||||||
@@ -108,4 +108,15 @@ unsigned long freeRam()
|
|||||||
|
|
||||||
return stack_ptr - heapend + mi.fordblks;
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,3 +25,4 @@ void SetAddr(char * out, uint8_t* addr);
|
|||||||
uint8_t HEX2DEC(char i);
|
uint8_t HEX2DEC(char i);
|
||||||
int getInt(char ** chan);
|
int getInt(char ** chan);
|
||||||
unsigned long freeRam ();
|
unsigned long freeRam ();
|
||||||
|
void parseBytes(const char* str, char separator, byte* bytes, int maxBytes, int base);
|
||||||
@@ -10,8 +10,8 @@
|
|||||||
[platformio]
|
[platformio]
|
||||||
src_dir = lighthub
|
src_dir = lighthub
|
||||||
env_default =
|
env_default =
|
||||||
; megaatmega2560
|
megaatmega2560
|
||||||
due
|
; due
|
||||||
|
|
||||||
[env:due]
|
[env:due]
|
||||||
platform = atmelsam
|
platform = atmelsam
|
||||||
|
|||||||
Reference in New Issue
Block a user