custom firmware mac address

build_flags_template
disabling freeram print
removing CR if no previous thermostat printing
This commit is contained in:
livello
2018-03-23 01:29:21 +03:00
parent bbf944c482
commit 70c31dd0ea
7 changed files with 74 additions and 16 deletions

View File

@@ -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

16
build_flags_template.sh Normal file
View 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

View File

@@ -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
}
}

View File

@@ -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"

View File

@@ -109,3 +109,14 @@ unsigned long freeRam()
return stack_ptr - heapend + mi.fordblks;
}
#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
}
}

View File

@@ -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);

View File

@@ -10,8 +10,8 @@
[platformio]
src_dir = lighthub
env_default =
; megaatmega2560
due
megaatmega2560
; due
[env:due]
platform = atmelsam