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

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

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

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