MAC generaton for DUE changed (more enthropy)

http config URI MUST start with /cnf now
This commit is contained in:
2019-04-26 03:19:56 +03:00
parent 4c65015327
commit fb3d532e2f
5 changed files with 38 additions and 32 deletions

View File

@@ -119,8 +119,10 @@ lan_status lanStatus = INITIAL_STATE;
const char configserver[] PROGMEM = CONFIG_SERVER; const char configserver[] PROGMEM = CONFIG_SERVER;
const char verval_P[] PROGMEM = QUOTE(PIO_SRC_REV); 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; char *deviceName = NULL;
aJsonObject *topics = NULL; aJsonObject *topics = NULL;
aJsonObject *root = NULL; aJsonObject *root = NULL;
@@ -273,12 +275,15 @@ else
void printMACAddress() { void printMACAddress() {
debugSerial<<F("MAC:"); debugSerial<<F("MAC:");
for (byte i = 0; i < 6; i++) for (byte i = 0; i < 6; i++)
{
if (mac[i]<16) debugSerial<<"0";
#ifdef WITH_PRINTEX_LIB #ifdef WITH_PRINTEX_LIB
(i < 5) ?debugSerial<<hex <<(mac[i])<<F(":"):debugSerial<<hex<<(mac[i])<<endl; (i < 5) ?debugSerial<<hex <<(mac[i])<<F(":"):debugSerial<<hex<<(mac[i])<<endl;
#else #else
(i < 5) ?debugSerial<<_HEX(mac[i])<<F(":"):debugSerial<<_HEX(mac[i])<<endl; (i < 5) ?debugSerial<<_HEX(mac[i])<<F(":"):debugSerial<<_HEX(mac[i])<<endl;
#endif #endif
} }
}
lan_status lanLoop() { lan_status lanLoop() {
@@ -1142,7 +1147,7 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
{ {
int responseStatusCode = 0; int responseStatusCode = 0;
char ch; char ch;
char URI[40]; char URI[64];
char configServer[32]=""; char configServer[32]="";
if (arg_cnt > 1) { if (arg_cnt > 1) {
strncpy(configServer, args[1], sizeof(configServer) - 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)) } else if (!loadFlash(OFFSET_CONFIGSERVER, configServer))
strncpy_P(configServer,configserver,sizeof(configServer)); strncpy_P(configServer,configserver,sizeof(configServer));
#ifndef DEVICE_NAME #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]); mac[5]);
#else #else
#ifndef FLASH_64KB #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 #else
strncpy(URI, "/", sizeof(URI)); strncpy(URI, "/cnf/", sizeof(URI));
strncat(URI, QUOTE(DEVICE_NAME), sizeof(URI)); strncat(URI, QUOTE(DEVICE_NAME), sizeof(URI));
strncat(URI, "_config.json", sizeof(URI)); strncat(URI, "_config.json", sizeof(URI));
#endif #endif
@@ -1233,7 +1238,7 @@ lan_status loadConfigFromHttp(int arg_cnt, char **args)
htclient.stop(); htclient.stop();
wdt_res(); wdt_res();
debugSerial<<F("HTTP Status code: "); debugSerial<<F("HTTP Status code: ");
debugSerial<<responseStatusCode; debugSerial<<responseStatusCode<<" ";
//debugSerial<<"GET Response: "); //debugSerial<<"GET Response: ");
if (responseStatusCode == 200) { if (responseStatusCode == 200) {
@@ -1315,6 +1320,10 @@ void postTransmission() {
void setup_main() { void setup_main() {
//Serial.println("Hello"); //Serial.println("Hello");
//delay(1000); //delay(1000);
#if defined(__SAM3X8E__)
memset(&UniqueID,0,sizeof(UniqueID));
#endif
setupCmdArduino(); setupCmdArduino();
printFirmwareVersionAndBuildOptions(); printFirmwareVersionAndBuildOptions();
@@ -1452,11 +1461,11 @@ debugSerial<<endl;
#if defined(__SAM3X8E__) #if defined(__SAM3X8E__)
Serial.println(F("Reading 128 bits unique identifier") ) ; Serial.println(F("Reading 128 bits unique identifier") ) ;
ReadUniqueID( UniqueID ) ; ReadUniqueID( UniqueID.UID_Long ) ;
Serial.print ("ID: ") ; Serial.print ("ID: ") ;
for (byte b = 0 ; b < 4 ; b++) 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 () ; Serial.println () ;
#endif #endif
@@ -1509,9 +1518,9 @@ if (!isMacValid) {
#elif defined(__SAM3X8E__) #elif defined(__SAM3X8E__)
//Lets make MAC from MPU serial# //Lets make MAC from MPU serial#
mac[0]=0xDE; mac[0]=0xDE;
//firmwareMacAddress[1]=0xAD;
for (byte b = 0 ; b < 5 ; b++) 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 #elif defined DEFAULT_FIRMWARE_MAC
uint8_t defaultMac[6] = DEFAULT_FIRMWARE_MAC;//comma(,) separated hex-array, hard-coded uint8_t defaultMac[6] = DEFAULT_FIRMWARE_MAC;//comma(,) separated hex-array, hard-coded

View File

@@ -169,6 +169,10 @@ enum lan_status {
DO_NOTHING = -14 DO_NOTHING = -14
}; };
typedef union {
uint32_t UID_Long[5];
uint8_t UID_Byte[20];
} UID;
//void watchdogSetup(void); //void watchdogSetup(void);

View File

@@ -61,31 +61,24 @@ int in_hdc1080::Poll()
float h,t; float h,t;
int reg; int reg;
// #ifdef WAK_PIN Serial.print("HDC Status=");
// digitalWrite(WAK_PIN,LOW); Serial.println(reg=hdc1080.readRegister().rawData,HEX);
// #endif if (reg!=0xff)
{
Serial.print("T="); Serial.print("T=");
Serial.print(t=hdc1080.readTemperature()); Serial.print(t=hdc1080.readTemperature());
Serial.print("C, RH="); Serial.print("C, RH=");
Serial.print(h=hdc1080.readHumidity()); Serial.print(h=hdc1080.readHumidity());
Serial.print("% Status="); Serial.print("%");
publish(t,"/T"); publish(t,"/T");
publish(h,"/H"); publish(h,"/H");
Serial.println(reg=hdc1080.readRegister().rawData,HEX);
ccs811.setEnvironmentalData(h,t); ccs811.setEnvironmentalData(h,t);
}
if (reg==0xff) //ESP I2C glitch else //ESP I2C glitch
{ {
Serial.println("I2C Reset"); Serial.println("I2C Reset");
i2cReset(); i2cReset();
} }
delay(100);
//#ifdef WAK_PIN
// digitalWrite(WAK_PIN,HIGH);
//#endif
return 1; return 1;
} }

View File

@@ -247,7 +247,7 @@ Awesome work Mark T!*/
__attribute__ ((section (".ramfunc"))) __attribute__ ((section (".ramfunc")))
void ReadUniqueID( unsigned int * pdwUniqueID ) void ReadUniqueID( uint32_t * pdwUniqueID )
{ {
unsigned int status ; unsigned int status ;

View File

@@ -51,7 +51,7 @@ unsigned long freeRam ();
void parseBytes(const char* str, char separator, byte* bytes, int maxBytes, int base); void parseBytes(const char* str, char separator, byte* bytes, int maxBytes, int base);
int log(const char *str, ...); int log(const char *str, ...);
void printFloatValueToStr(float value, char *valstr); void printFloatValueToStr(float value, char *valstr);
void ReadUniqueID( unsigned int * pdwUniqueID ); void ReadUniqueID( uint32_t * pdwUniqueID );
int inet_aton(const char* aIPAddrString, IPAddress& aResult); int inet_aton(const char* aIPAddrString, IPAddress& aResult);
char *inet_ntoa_r(IPAddress addr, char *buf, int buflen); char *inet_ntoa_r(IPAddress addr, char *buf, int buflen);
void printIPAddress(IPAddress ipAddress); void printIPAddress(IPAddress ipAddress);