mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 19:59:50 +03:00
MAC generaton for DUE changed (more enthropy)
http config URI MUST start with /cnf now
This commit is contained in:
@@ -119,8 +119,10 @@ lan_status lanStatus = INITIAL_STATE;
|
||||
const char configserver[] PROGMEM = CONFIG_SERVER;
|
||||
const char verval_P[] PROGMEM = QUOTE(PIO_SRC_REV);
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
UID UniqueID;
|
||||
#endif
|
||||
|
||||
unsigned int UniqueID[5] = {0,0,0,0,0};
|
||||
char *deviceName = NULL;
|
||||
aJsonObject *topics = NULL;
|
||||
aJsonObject *root = NULL;
|
||||
@@ -273,12 +275,15 @@ else
|
||||
void printMACAddress() {
|
||||
debugSerial<<F("MAC:");
|
||||
for (byte i = 0; i < 6; i++)
|
||||
{
|
||||
if (mac[i]<16) debugSerial<<"0";
|
||||
#ifdef WITH_PRINTEX_LIB
|
||||
(i < 5) ?debugSerial<<hex <<(mac[i])<<F(":"):debugSerial<<hex<<(mac[i])<<endl;
|
||||
#else
|
||||
(i < 5) ?debugSerial<<_HEX(mac[i])<<F(":"):debugSerial<<_HEX(mac[i])<<endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
lan_status lanLoop() {
|
||||
@@ -1142,7 +1147,7 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
{
|
||||
int responseStatusCode = 0;
|
||||
char ch;
|
||||
char URI[40];
|
||||
char URI[64];
|
||||
char configServer[32]="";
|
||||
if (arg_cnt > 1) {
|
||||
strncpy(configServer, args[1], sizeof(configServer) - 1);
|
||||
@@ -1150,13 +1155,13 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
} else if (!loadFlash(OFFSET_CONFIGSERVER, configServer))
|
||||
strncpy_P(configServer,configserver,sizeof(configServer));
|
||||
#ifndef DEVICE_NAME
|
||||
snprintf(URI, sizeof(URI), "/%02x-%02x-%02x-%02x-%02x-%02x.config.json", mac[0], mac[1], mac[2], mac[3], mac[4],
|
||||
snprintf(URI, sizeof(URI), "/cnf/%02x-%02x-%02x-%02x-%02x-%02x.config.json", mac[0], mac[1], mac[2], mac[3], mac[4],
|
||||
mac[5]);
|
||||
#else
|
||||
#ifndef FLASH_64KB
|
||||
snprintf(URI, sizeof(URI), "/%s_config.json",QUOTE(DEVICE_NAME));
|
||||
snprintf(URI, sizeof(URI), "/cnf/%s_config.json",QUOTE(DEVICE_NAME));
|
||||
#else
|
||||
strncpy(URI, "/", sizeof(URI));
|
||||
strncpy(URI, "/cnf/", sizeof(URI));
|
||||
strncat(URI, QUOTE(DEVICE_NAME), sizeof(URI));
|
||||
strncat(URI, "_config.json", sizeof(URI));
|
||||
#endif
|
||||
@@ -1233,7 +1238,7 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
|
||||
htclient.stop();
|
||||
wdt_res();
|
||||
debugSerial<<F("HTTP Status code: ");
|
||||
debugSerial<<responseStatusCode;
|
||||
debugSerial<<responseStatusCode<<" ";
|
||||
//debugSerial<<"GET Response: ");
|
||||
|
||||
if (responseStatusCode == 200) {
|
||||
@@ -1315,6 +1320,10 @@ void postTransmission() {
|
||||
void setup_main() {
|
||||
//Serial.println("Hello");
|
||||
//delay(1000);
|
||||
#if defined(__SAM3X8E__)
|
||||
memset(&UniqueID,0,sizeof(UniqueID));
|
||||
#endif
|
||||
|
||||
setupCmdArduino();
|
||||
printFirmwareVersionAndBuildOptions();
|
||||
|
||||
@@ -1452,11 +1461,11 @@ debugSerial<<endl;
|
||||
#if defined(__SAM3X8E__)
|
||||
|
||||
Serial.println(F("Reading 128 bits unique identifier") ) ;
|
||||
ReadUniqueID( UniqueID ) ;
|
||||
ReadUniqueID( UniqueID.UID_Long ) ;
|
||||
|
||||
Serial.print ("ID: ") ;
|
||||
for (byte b = 0 ; b < 4 ; b++)
|
||||
Serial.print ((unsigned int) UniqueID [b], HEX) ;
|
||||
Serial.print ((unsigned int) UniqueID.UID_Long [b], HEX) ;
|
||||
Serial.println () ;
|
||||
#endif
|
||||
|
||||
@@ -1509,9 +1518,9 @@ if (!isMacValid) {
|
||||
#elif defined(__SAM3X8E__)
|
||||
//Lets make MAC from MPU serial#
|
||||
mac[0]=0xDE;
|
||||
//firmwareMacAddress[1]=0xAD;
|
||||
|
||||
for (byte b = 0 ; b < 5 ; b++)
|
||||
mac[b+1]=UniqueID [b] ;
|
||||
mac[b+1]=UniqueID.UID_Byte [b*3] + UniqueID.UID_Byte [b*3+1] + UniqueID.UID_Byte [b*3+2];
|
||||
|
||||
#elif defined DEFAULT_FIRMWARE_MAC
|
||||
uint8_t defaultMac[6] = DEFAULT_FIRMWARE_MAC;//comma(,) separated hex-array, hard-coded
|
||||
|
||||
@@ -169,6 +169,10 @@ enum lan_status {
|
||||
DO_NOTHING = -14
|
||||
};
|
||||
|
||||
typedef union {
|
||||
uint32_t UID_Long[5];
|
||||
uint8_t UID_Byte[20];
|
||||
} UID;
|
||||
|
||||
//void watchdogSetup(void);
|
||||
|
||||
|
||||
@@ -61,31 +61,24 @@ int in_hdc1080::Poll()
|
||||
float h,t;
|
||||
int reg;
|
||||
|
||||
// #ifdef WAK_PIN
|
||||
// digitalWrite(WAK_PIN,LOW);
|
||||
// #endif
|
||||
|
||||
|
||||
Serial.print("HDC Status=");
|
||||
Serial.println(reg=hdc1080.readRegister().rawData,HEX);
|
||||
if (reg!=0xff)
|
||||
{
|
||||
Serial.print("T=");
|
||||
Serial.print(t=hdc1080.readTemperature());
|
||||
Serial.print("C, RH=");
|
||||
Serial.print(h=hdc1080.readHumidity());
|
||||
Serial.print("% Status=");
|
||||
Serial.print("%");
|
||||
publish(t,"/T");
|
||||
publish(h,"/H");
|
||||
Serial.println(reg=hdc1080.readRegister().rawData,HEX);
|
||||
ccs811.setEnvironmentalData(h,t);
|
||||
|
||||
if (reg==0xff) //ESP I2C glitch
|
||||
}
|
||||
else //ESP I2C glitch
|
||||
{
|
||||
Serial.println("I2C Reset");
|
||||
i2cReset();
|
||||
}
|
||||
|
||||
delay(100);
|
||||
//#ifdef WAK_PIN
|
||||
// digitalWrite(WAK_PIN,HIGH);
|
||||
//#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -247,7 +247,7 @@ Awesome work Mark T!*/
|
||||
|
||||
__attribute__ ((section (".ramfunc")))
|
||||
|
||||
void ReadUniqueID( unsigned int * pdwUniqueID )
|
||||
void ReadUniqueID( uint32_t * pdwUniqueID )
|
||||
{
|
||||
unsigned int status ;
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ unsigned long freeRam ();
|
||||
void parseBytes(const char* str, char separator, byte* bytes, int maxBytes, int base);
|
||||
int log(const char *str, ...);
|
||||
void printFloatValueToStr(float value, char *valstr);
|
||||
void ReadUniqueID( unsigned int * pdwUniqueID );
|
||||
void ReadUniqueID( uint32_t * pdwUniqueID );
|
||||
int inet_aton(const char* aIPAddrString, IPAddress& aResult);
|
||||
char *inet_ntoa_r(IPAddress addr, char *buf, int buflen);
|
||||
void printIPAddress(IPAddress ipAddress);
|
||||
|
||||
Reference in New Issue
Block a user