From a215932f872daa6052d0ae32925dbfb2bddcbe44 Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Mon, 6 May 2019 17:05:55 +0200 Subject: [PATCH 01/39] atlas Sensor for pH an Redox (ORP) added --- src/_P036_FrameOLED.ino | 89 +++++--- src/_P214_Atlas_EZO_pH.ino | 445 ++++++++++++++++++++++++++++++++++++ src/_P222_Atlas_EZO_ORP.ino | 361 +++++++++++++++++++++++++++++ 3 files changed, 866 insertions(+), 29 deletions(-) create mode 100644 src/_P214_Atlas_EZO_pH.ino create mode 100644 src/_P222_Atlas_EZO_ORP.ino diff --git a/src/_P036_FrameOLED.ino b/src/_P036_FrameOLED.ino index 36937fcfb..5d48cca1f 100644 --- a/src/_P036_FrameOLED.ino +++ b/src/_P036_FrameOLED.ino @@ -25,6 +25,9 @@ #define P36_CONTRAST_MED 0xCF #define P36_CONTRAST_HIGH 0xFF +#define P36_SIZE_128X32 32 +#define P36_SIZE_128X64 64 + #include "SSD1306.h" #include "SH1106Wire.h" @@ -170,6 +173,16 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string) optionValues6[2] = P36_CONTRAST_HIGH; addFormSelector(F("Contrast"), F("p036_contrast"), 3, options6, optionValues6, choice6); + // size 64 or 128 + byte choice7 = PCONFIG(7); + String options7[2]; + options7[0] = F("128x32"); + options7[1] = F("128x64"); + int optionValues7[2]; + optionValues7[0] = P36_SIZE_128X32; + optionValues7[1] = P36_SIZE_128X64; + addFormSelector(F("Screen Size"), F("p036_screen_size"), 2, options7, optionValues7, choice7); + success = true; break; } @@ -188,6 +201,7 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string) PCONFIG(4) = getFormItemInt(F("p036_timer")); PCONFIG(5) = getFormItemInt(F("p036_controller")); PCONFIG(6) = getFormItemInt(F("p036_contrast")); + PCONFIG(7) = getFormItemInt(F("p036_screen_size")); String error; char P036_deviceTemplate[P36_Nlines][P36_Nchars]; @@ -224,7 +238,12 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string) uint8_t OLED_address = PCONFIG(0); if (PCONFIG(5) == 1) { - display = new SSD1306Wire(OLED_address, Settings.Pin_i2c_sda, Settings.Pin_i2c_scl); + if(PCONFIG(7) == P36_SIZE_128X32) { + digitalWrite(16, HIGH); + display = new SSD1306Wire(OLED_address, Settings.Pin_i2c_sda, Settings.Pin_i2c_scl, 128, 32); + } else { + display = new SSD1306Wire(OLED_address, Settings.Pin_i2c_sda, Settings.Pin_i2c_scl, 128, 64); + } } else { display = new SH1106Wire(OLED_address, Settings.Pin_i2c_sda, Settings.Pin_i2c_scl); } @@ -381,12 +400,14 @@ boolean Plugin_036(byte function, struct EventStruct *event, String& string) // Update display display_header(); - display_indicator(currentFrameToDisplay, nrFramesToDisplay); + if(PCONFIG(7) != P36_SIZE_128X32) { + display_indicator(currentFrameToDisplay, nrFramesToDisplay); + } // display_indicator(frameCounter, NFrames); display->display(); int scrollspeed = PCONFIG(3); - display_scroll(oldString, newString, linesPerFrame, scrollspeed); + display_scroll(oldString, newString, linesPerFrame, scrollspeed, PCONFIG(7)); success = true; break; @@ -578,7 +599,7 @@ void display_indicator(int iframe, int frameCount) { } } -void display_scroll(String outString[], String inString[], int nlines, int scrollspeed) +void display_scroll(String outString[], String inString[], int nlines, int scrollspeed, int screenSize) { // outString contains the outgoing strings in this frame @@ -587,34 +608,40 @@ void display_scroll(String outString[], String inString[], int nlines, int scrol int ypos[4]; // ypos contains the heights of the various lines - this depends on the font and the number of lines - if (nlines == 1) - { - display->setFont(ArialMT_Plain_24); - ypos[0] = 20; - } - - if (nlines == 2) - { + if(screenSize == P36_SIZE_128X32) { + nlines = 1; display->setFont(ArialMT_Plain_16); ypos[0] = 15; - ypos[1] = 34; - } + } else { + if (nlines == 1) + { + display->setFont(ArialMT_Plain_24); + ypos[0] = 20; + } - if (nlines == 3) - { - display->setFont(Dialog_plain_12); - ypos[0] = 13; - ypos[1] = 25; - ypos[2] = 37; - } + if (nlines == 2) + { + display->setFont(ArialMT_Plain_16); + ypos[0] = 15; + ypos[1] = 34; + } - if (nlines == 4) - { - display->setFont(ArialMT_Plain_10); - ypos[0] = 12; - ypos[1] = 22; - ypos[2] = 32; - ypos[3] = 42; + if (nlines == 3) + { + display->setFont(Dialog_plain_12); + ypos[0] = 13; + ypos[1] = 25; + ypos[2] = 37; + } + + if (nlines == 4) + { + display->setFont(ArialMT_Plain_10); + ypos[0] = 12; + ypos[1] = 22; + ypos[2] = 32; + ypos[3] = 42; + } } display->setTextAlignment(TEXT_ALIGN_CENTER); @@ -626,7 +653,11 @@ void display_scroll(String outString[], String inString[], int nlines, int scrol display->setColor(BLACK); // We allow 12 pixels at the top because otherwise the wifi indicator gets too squashed!! - display->fillRect(0, 12, 128, 42); // scrolling window is 44 pixels high - ie 64 less margin of 10 at top and bottom + if(screenSize == P36_SIZE_128X32) { + display->fillRect(0, 15, 128, 32); + } else { + display->fillRect(0, 12, 128, 42); // scrolling window is 44 pixels high - ie 64 less margin of 10 at top and bottom + } display->setColor(WHITE); // Now draw the strings diff --git a/src/_P214_Atlas_EZO_pH.ino b/src/_P214_Atlas_EZO_pH.ino new file mode 100644 index 000000000..99f441f5d --- /dev/null +++ b/src/_P214_Atlas_EZO_pH.ino @@ -0,0 +1,445 @@ +//######################################################################## +//################## Plugin 214 : Atlas Scientific EZO Ph sensor ######## +//######################################################################## + +// datasheet at https://www.atlas-scientific.com/_files/_datasheets/_circuit/pH_EZO_datasheet.pdf +// works only in i2c mode + +#define PLUGIN_214 +#define PLUGIN_ID_214 214 +#define PLUGIN_NAME_214 "Environment - Atlas Scientific pH EZO [TESTING]" +#define PLUGIN_VALUENAME1_214 "pH" +#define PLUGIN_VALUENAME2_214 "Voltage" + +boolean Plugin_214_init = false; + +boolean Plugin_214(byte function, struct EventStruct *event, String& string) +{ + boolean success = false; + + switch (function) + { + case PLUGIN_DEVICE_ADD: + { + Device[++deviceCount].Number = PLUGIN_ID_214; + Device[deviceCount].Type = DEVICE_TYPE_I2C; + Device[deviceCount].VType = SENSOR_TYPE_SINGLE; + Device[deviceCount].Ports = 0; + Device[deviceCount].PullUpOption = false; + Device[deviceCount].InverseLogicOption = false; + Device[deviceCount].FormulaOption = true; + Device[deviceCount].ValueCount = 2; + Device[deviceCount].SendDataOption = true; + Device[deviceCount].TimerOption = true; + Device[deviceCount].GlobalSyncOption = true; + break; + } + + case PLUGIN_GET_DEVICENAME: + { + string = F(PLUGIN_NAME_214); + break; + } + + case PLUGIN_GET_DEVICEVALUENAMES: + { + strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_214)); + strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_214)); + break; + } + + case PLUGIN_WEBFORM_LOAD: + { + #define _P214_ATLASEZO_I2C_NB_OPTIONS 4 + byte I2Cchoice = Settings.TaskDevicePluginConfig[event->TaskIndex][0]; + int optionValues[_P214_ATLASEZO_I2C_NB_OPTIONS] = { 0x63, 0x64, 0x65, 0x66 }; + addFormSelectorI2C(F("plugin_214_i2c"), _P214_ATLASEZO_I2C_NB_OPTIONS, optionValues, I2Cchoice); + + addFormSubHeader(F("General")); + + char sensordata[32]; + bool info; + info = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"i",sensordata); + + if (info) { + String boardInfo(sensordata); + + addHtml(F("Board type : ")); + int pos1 = boardInfo.indexOf(','); + int pos2 = boardInfo.lastIndexOf(','); + addHtml(boardInfo.substring(pos1+1,pos2)); + if (boardInfo.substring(pos1+1,pos2) != "pH"){ + addHtml(F(" WARNING : Board type should be 'pH', check your i2c Address ? ")); + } + addHtml(F("Board version :")); + addHtml(boardInfo.substring(pos2+1)); + addHtml(F("")); + + addHtml(F("")); + + } else { + addHtml(F("Unable to send command to device")); + success = false; + break; + } + + addFormCheckBox(F("Status LED"),F("Plugin_214_status_led"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]); + + char statussensordata[32]; + bool status; + status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Status",statussensordata); + + if (status) { + String boardStatus(statussensordata); + + addHtml(F("Board restart code: ")); + int pos1 = boardStatus.indexOf(','); + int pos2 = boardStatus.lastIndexOf(','); + switch ((char)boardStatus.substring(pos1+1,pos2)[0]) + { + case 'P': + { + addHtml(F("powered off")); + break; + } + case 'S': + { + addHtml(F("software reset")); + break; + } + case 'B': + { + addHtml(F("brown out")); + break; + } + case 'W': + { + addHtml(F("watch dog")); + break; + } + case 'U': + default: + { + addHtml(F("unknown")); + break; + } + } + + addHtml(F("Board voltage :")); + addHtml(boardStatus.substring(pos2+1)); + addHtml(F(" V")); + + addHtml(F("")); + + } else { + addHtml(F("Unable to send status command to device")); + success = false; + break; + } + + addFormSubHeader(F("Calibration")); + + int nb_calibration_points = -1; + status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0], "Cal,?",sensordata); + + if (status){ + if (strncmp(sensordata,"?Cal,",5)){ + char tmp[2]; + tmp[0] = sensordata[5]; + tmp[1] = '\0', + nb_calibration_points = atoi(tmp); + } + } + + addRowLabel(F("Middle")); + addFormNumericBox(F("Ref Ph"),F("Plugin_214_ref_cal_M' step='0.01"),Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1],1,14); + if (nb_calibration_points > 0) { + addHtml(F(" OK")); + } else { + addHtml(F(" Not yet calibrated")); + } + addFormCheckBox(F("Enable"),F("Plugin_214_enable_cal_M"), false); + addHtml(F("\n\n")); + + addRowLabel(F("Low")); + addFormNumericBox(F("Ref Ph"),F("Plugin_214_ref_cal_L' step='0.01"), Settings.TaskDevicePluginConfigFloat[event->TaskIndex][2],1,14); + if (nb_calibration_points > 1) { + addHtml(F(" OK")); + } else { + addHtml(F(" Not yet calibrated")); + } + addFormCheckBox(F("Enable"),F("Plugin_214_enable_cal_L"), false); + addHtml(F("\n\n")); + + addHtml(F("High")); + addFormNumericBox(F("Ref Ph"),F("Plugin_214_ref_cal_H' step='0.01"), Settings.TaskDevicePluginConfigFloat[event->TaskIndex][3],1,14); + if (nb_calibration_points > 2) { + addHtml(F(" OK")); + } else { + addHtml(F(" Not yet calibrated")); + } + addFormCheckBox(F("Enable"),F("Plugin_214_enable_cal_H"), false); + addHtml(F("\n\n")); + + if (nb_calibration_points > 1){ + char sensordata[32]; + char cmd[8] = "Slope,?"; + bool status; + status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],cmd,sensordata); + + if (status){ + String slopeAnswer("Answer to 'Slope' command : "); + slopeAnswer += sensordata; + addFormNote(slopeAnswer); + } + } + + addFormSubHeader(F("Temperature compensation")); + char deviceTemperatureTemplate[40]; + LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate)); + addFormTextBox(F("Temperature "), F("Plugin_214_temperature_template"), deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate)); + addFormNote(F("You can use a formulae (and idealy refer to a temp sensor). ")); + float value; + char strValue[5]; + String deviceTemperatureTemplateString(deviceTemperatureTemplate); + String pooltempString(parseTemplate(deviceTemperatureTemplateString, 40)); + addHtml(F("
")); + if (Calculate(pooltempString.c_str(),&value) == CALCULATE_OK ){ + addHtml(F("Actual value : ")); + dtostrf(value,5,2,strValue); + addHtml(strValue); + } else { + addHtml(F("(It seems I can't parse your formulae)")); + } + + addHtml(F("
")); + + success = true; + break; + } + + case PLUGIN_WEBFORM_SAVE: + { + Settings.TaskDevicePluginConfig[event->TaskIndex][0] = getFormItemInt(F("plugin_214_i2c")); + + Settings.TaskDevicePluginConfigFloat[event->TaskIndex][0] = getFormItemFloat(F("plugin_214_sensorVersion")); + + char sensordata[32]; + if (isFormItemChecked(F("Plugin_214_status_led"))) { + _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"L,1",sensordata); + } else { + _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"L,0",sensordata); + } + Settings.TaskDevicePluginConfig[event->TaskIndex][1] = isFormItemChecked(F("Plugin_214_status_led")); + + + Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1] = getFormItemFloat(F("Plugin_214_ref_cal_M")); + Settings.TaskDevicePluginConfigFloat[event->TaskIndex][2] = getFormItemFloat(F("Plugin_214_ref_cal_L")); + Settings.TaskDevicePluginConfigFloat[event->TaskIndex][3] = getFormItemFloat(F("Plugin_214_ref_cal_H")); + + String cmd ("Cal,"); + bool triggerCalibrate = false; + if (isFormItemChecked("Plugin_214_enable_cal_M")) { + cmd += "mid,"; + cmd += Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1]; + triggerCalibrate = true; + } else if (isFormItemChecked("Plugin_214_enable_cal_L")){ + cmd += "low,"; + cmd += Settings.TaskDevicePluginConfigFloat[event->TaskIndex][2]; + triggerCalibrate = true; + } else if (isFormItemChecked("Plugin_214_enable_cal_H")){ + cmd += "high,"; + cmd += Settings.TaskDevicePluginConfigFloat[event->TaskIndex][3]; + triggerCalibrate = true; + } + if (triggerCalibrate){ + char sensordata[32]; + _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],cmd.c_str(),sensordata); + } + + char deviceTemperatureTemplate[40]; + String tmpString = WebServer.arg(F("Plugin_214_temperature_template")); + strncpy(deviceTemperatureTemplate, tmpString.c_str(), sizeof(deviceTemperatureTemplate)-1); + deviceTemperatureTemplate[sizeof(deviceTemperatureTemplate)-1]=0; //be sure that our string ends with a \0 + + SaveCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate)); + + Plugin_214_init = false; + success = true; + break; + } + + case PLUGIN_INIT: + { + Plugin_214_init = true; + } + + case PLUGIN_READ: + { + char sensordata[32]; + bool status; + + //first set the temperature of reading + char deviceTemperatureTemplate[40]; + LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate)); + + String deviceTemperatureTemplateString(deviceTemperatureTemplate); + String pooltempString(parseTemplate(deviceTemperatureTemplateString, 40)); + //String setTemperature("T,"); + String setTemperature("RT,"); + float temperatureReading; + if (Calculate(pooltempString.c_str(),&temperatureReading) == CALCULATE_OK ){ + setTemperature += temperatureReading; + } else { + success = false; + break; + } + + //ok, now we can read the pH value with Temperature compensation + status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],setTemperature.c_str(),sensordata); + + //ok, now we can read the pH value + //status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"r",sensordata); + + //we read the voltagedata char statussensordata[32]; + char voltagedata[32]; + status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Status",voltagedata); + + + if (status){ + String sensorString(sensordata); + String voltage(voltagedata); + int pos = voltage.lastIndexOf(','); + UserVar[event->BaseVarIndex] = sensorString.toFloat(); + UserVar[event->BaseVarIndex + 1] = voltage.substring(pos+1).toFloat(); + } + else { + UserVar[event->BaseVarIndex] = -1; + UserVar[event->BaseVarIndex + 1] = -1; + } + + //go to sleep + //status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Sleep",sensordata); + + success = true; + break; + } + case PLUGIN_WRITE: + { + //TODO : do something more usefull ... + + String tmpString = string; + int argIndex = tmpString.indexOf(','); + if (argIndex) + tmpString = tmpString.substring(0, argIndex); + if (tmpString.equalsIgnoreCase(F("ATLASCMD"))) + { + success = true; + argIndex = string.lastIndexOf(','); + tmpString = string.substring(argIndex + 1); + if (tmpString.equalsIgnoreCase(F("CalMid"))){ + String log("Asking for Mid calibration "); + addLog(LOG_LEVEL_INFO, log); + } + else if (tmpString.equalsIgnoreCase(F("CalLow"))){ + String log("Asking for Low calibration "); + addLog(LOG_LEVEL_INFO, log); + } + else if (tmpString.equalsIgnoreCase(F("CalHigh"))){ + String log("Asking for High calibration "); + addLog(LOG_LEVEL_INFO, log); + } + } + break; + } + } + return success; +} + +// Call this function with two char arrays, one containing the command +// The other containing an allocatted char array for answer +// Returns true on success, false otherwise + +bool _P214_send_I2C_command(uint8_t I2Caddress,const char * cmd, char* sensordata) { + uint16_t sensor_bytes_received = 0; + + byte error; + byte i2c_response_code = 0; + byte in_char = 0; + + Serial.println(cmd); + Wire.beginTransmission(I2Caddress); + Wire.write(cmd); + error = Wire.endTransmission(); + + if (error != 0) { + return false; + } + + //don't read answer if we want to go to sleep + if (strncmp(cmd,"Sleep",5) == 0) { + return true; + } + + i2c_response_code = 254; + while (i2c_response_code == 254) { // in case the cammand takes longer to process, we keep looping here until we get a success or an error + + if ( + ( (cmd[0] == 'r' || cmd[0] == 'R') && cmd[1] == '\0' ) + || + ( ( strncmp(cmd,"cal",3) || strncmp(cmd,"Cal",3) ) && !strncmp(cmd,"Cal,?",5) ) + ) + { + delay(900); + } + else { + delay(300); + } + + Wire.requestFrom(I2Caddress, (uint8_t) 32); //call the circuit and request 32 bytes (this is more then we need). + i2c_response_code = Wire.read(); //read response code + + while (Wire.available()) { //read response + in_char = Wire.read(); + + if (in_char == 0) { //if we receive a null caracter, we're done + while (Wire.available()) { //purge the data line if needed + Wire.read(); + } + + break; //exit the while loop. + } + else { + sensordata[sensor_bytes_received] = in_char; //load this byte into our array. + sensor_bytes_received++; + } + } + sensordata[sensor_bytes_received] = '\0'; + + switch (i2c_response_code) { + case 1: + Serial.print( F("< success, answer = ")); + Serial.println(sensordata); + break; + + case 2: + Serial.println( F("< command failed")); + return false; + + case 254: + Serial.println( F("< command pending")); + break; + + case 255: + Serial.println( F("< no data")); + return false; + } + } + + Serial.println(sensordata); + return true; +} diff --git a/src/_P222_Atlas_EZO_ORP.ino b/src/_P222_Atlas_EZO_ORP.ino new file mode 100644 index 000000000..edec85177 --- /dev/null +++ b/src/_P222_Atlas_EZO_ORP.ino @@ -0,0 +1,361 @@ +//######################################################################## +//################## Plugin 222 : Atlas Scientific EZO ORP sensor ######## +//######################################################################## + +// datasheet at https://www.atlas-scientific.com/_files/_datasheets/_circuit/ORP_EZO_datasheet.pdf +// works only in i2c mode + +#define PLUGIN_222 +#define PLUGIN_ID_222 222 +#define PLUGIN_NAME_222 "Environment - Atlas Scientific ORP EZO [TESTING]" +#define PLUGIN_VALUENAME1_222 "ORP" +#define PLUGIN_VALUENAME2_222 "Voltage" + +boolean Plugin_222_init = false; + +boolean Plugin_222(byte function, struct EventStruct *event, String& string) +{ + boolean success = false; + + switch (function) + { + case PLUGIN_DEVICE_ADD: + { + Device[++deviceCount].Number = PLUGIN_ID_222; + Device[deviceCount].Type = DEVICE_TYPE_I2C; + Device[deviceCount].VType = SENSOR_TYPE_SINGLE; + Device[deviceCount].Ports = 0; + Device[deviceCount].PullUpOption = false; + Device[deviceCount].InverseLogicOption = false; + Device[deviceCount].FormulaOption = true; + Device[deviceCount].ValueCount = 2; + Device[deviceCount].SendDataOption = true; + Device[deviceCount].TimerOption = true; + Device[deviceCount].GlobalSyncOption = true; + break; + } + + case PLUGIN_GET_DEVICENAME: + { + string = F(PLUGIN_NAME_222); + break; + } + + case PLUGIN_GET_DEVICEVALUENAMES: + { + strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_222)); + strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_222)); + break; + } + + case PLUGIN_WEBFORM_LOAD: + { + #define _P222_ATLASEZO_I2C_NB_OPTIONS 4 + byte I2Cchoice = Settings.TaskDevicePluginConfig[event->TaskIndex][0]; + int optionValues[_P222_ATLASEZO_I2C_NB_OPTIONS] = { 0x62, 0x63, 0x64, 0x65 }; + addFormSelectorI2C(F("plugin_222_i2c"), _P222_ATLASEZO_I2C_NB_OPTIONS, optionValues, I2Cchoice); + + addFormSubHeader(F("General")); + + char sensordata[32]; + bool info; + info = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"i",sensordata); + + if (info) { + String boardInfo(sensordata); + + addHtml(F("Board type : ")); + int pos1 = boardInfo.indexOf(','); + int pos2 = boardInfo.lastIndexOf(','); + addHtml(boardInfo.substring(pos1+1,pos2)); + if (boardInfo.substring(pos1+1,pos2) != "ORP"){ + addHtml(F(" WARNING : Board type should be 'ORP', check your i2c Address ? ")); + } + addHtml(F("Board version :")); + addHtml(boardInfo.substring(pos2+1)); + addHtml(F("")); + + addHtml(F("")); + + } else { + addHtml(F("Unable to send command to device")); + success = false; + break; + } + + addFormCheckBox(F("Status LED"),F("Plugin_222_status_led"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]); + + char statussensordata[32]; + bool status; + status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Status",statussensordata); + + if (status) { + String boardStatus(statussensordata); + + addHtml(F("Board restart code: ")); + int pos1 = boardStatus.indexOf(','); + int pos2 = boardStatus.lastIndexOf(','); + switch ((char)boardStatus.substring(pos1+1,pos2)[0]) + { + case 'P': + { + addHtml(F("powered off")); + break; + } + case 'S': + { + addHtml(F("software reset")); + break; + } + case 'B': + { + addHtml(F("brown out")); + break; + } + case 'W': + { + addHtml(F("watch dog")); + break; + } + case 'U': + default: + { + addHtml(F("unknown")); + break; + } + } + + addHtml(F("Board voltage :")); + addHtml(boardStatus.substring(pos2+1)); + addHtml(F(" V")); + + addHtml(F("")); + + } else { + addHtml(F("Unable to send status command to device")); + success = false; + break; + } + + addFormSubHeader(F("Calibration")); + + int nb_calibration_points = -1; + status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0], "Cal,?",sensordata); + + if (status){ + if (strncmp(sensordata,"?Cal,",5)){ + char tmp[2]; + tmp[0] = sensordata[5]; + tmp[1] = '\0', + nb_calibration_points = atoi(tmp); + } + } + + addRowLabel(F("ORP Calibration")); + addFormNumericBox(F("Ref ORP"),F("Plugin_222_ref_cal_M' step='1"),Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1],0,1500); + if (nb_calibration_points > 0) { + addHtml(F(" OK")); + } else { + addHtml(F(" Not yet calibrated")); + } + addFormCheckBox(F("Enable"),F("Plugin_222_enable_cal_M"), false); + + if (nb_calibration_points > 1){ + char sensordata[32]; + char cmd[8] = "Slope,?"; + bool status; + status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],cmd,sensordata); + + if (status){ + String slopeAnswer("Answer to 'Slope' command : "); + slopeAnswer += sensordata; + addFormNote(slopeAnswer); + } + } + + addHtml(F("")); + + success = true; + break; + } + + case PLUGIN_WEBFORM_SAVE: + { + Settings.TaskDevicePluginConfig[event->TaskIndex][0] = getFormItemInt(F("plugin_222_i2c")); + + Settings.TaskDevicePluginConfigFloat[event->TaskIndex][0] = getFormItemFloat(F("plugin_222_sensorVersion")); + + char sensordata[32]; + if (isFormItemChecked(F("Plugin_222_status_led"))) { + _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"L,1",sensordata); + } else { + _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"L,0",sensordata); + } + Settings.TaskDevicePluginConfig[event->TaskIndex][1] = isFormItemChecked(F("Plugin_222_status_led")); + + + Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1] = getFormItemFloat(F("Plugin_222_ref_cal_M")); + + String cmd ("Cal,"); + bool triggerCalibrate = false; + if (isFormItemChecked("Plugin_222_enable_cal_M")) { + cmd += Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1]; + triggerCalibrate = true; + } + if (triggerCalibrate){ + char sensordata[32]; + _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],cmd.c_str(),sensordata); + } + + Plugin_222_init = false; + success = true; + break; + } + + case PLUGIN_INIT: + { + Plugin_222_init = true; + } + + case PLUGIN_READ: + { + char sensordata[32]; + bool status; + + //ok, now we can read the ORP value + status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"R",sensordata); + + //we read the voltagedata char statussensordata[32]; + char voltagedata[32]; + status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Status",voltagedata); + + if (status){ + String sensorString(sensordata); + String voltage(voltagedata); + int pos = voltage.lastIndexOf(','); + UserVar[event->BaseVarIndex] = sensorString.toFloat(); + UserVar[event->BaseVarIndex + 1] = voltage.substring(pos+1).toFloat(); + } + else { + UserVar[event->BaseVarIndex] = -1; + UserVar[event->BaseVarIndex + 1] = -1; + } + + //go to sleep + //status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Sleep",sensordata); + + success = true; + break; + } + case PLUGIN_WRITE: + { + //TODO : do something more usefull ... + + String tmpString = string; + int argIndex = tmpString.indexOf(','); + if (argIndex) + tmpString = tmpString.substring(0, argIndex); + if (tmpString.equalsIgnoreCase(F("ATLASCMD"))) + { + success = true; + argIndex = string.lastIndexOf(','); + tmpString = string.substring(argIndex + 1); + if (tmpString.equalsIgnoreCase(F("CalMid"))){ + String log("Asking for calibration "); + addLog(LOG_LEVEL_INFO, log); + } + } + break; + } + } + return success; +} + +// Call this function with two char arrays, one containing the command +// The other containing an allocatted char array for answer +// Returns true on success, false otherwise + +bool _P222_send_I2C_command(uint8_t I2Caddress,const char * cmd, char* sensordata) { + uint16_t sensor_bytes_received = 0; + + byte error; + byte i2c_response_code = 0; + byte in_char = 0; + + Serial.println(cmd); + Wire.beginTransmission(I2Caddress); + Wire.write(cmd); + error = Wire.endTransmission(); + + if (error != 0) { + Serial.println(error); + return false; + } + + //don't read answer if we want to go to sleep + if (strncmp(cmd,"Sleep",5) == 0) { + return true; + } + + i2c_response_code = 254; + while (i2c_response_code == 254) { // in case the cammand takes longer to process, we keep looping here until we get a success or an error + + if ( + ( (cmd[0] == 'r' || cmd[0] == 'R') && cmd[1] == '\0' ) + || + ( ( strncmp(cmd,"cal",3) || strncmp(cmd,"Cal",3) ) && !strncmp(cmd,"Cal,?",5) ) + ) + { + delay(900); + } + else { + delay(300); + } + + Wire.requestFrom(I2Caddress, (uint8_t) 32); //call the circuit and request 32 bytes (this is more then we need). + i2c_response_code = Wire.read(); //read response code + + while (Wire.available()) { //read response + in_char = Wire.read(); + + if (in_char == 0) { //if we receive a null caracter, we're done + while (Wire.available()) { //purge the data line if needed + Wire.read(); + } + + break; //exit the while loop. + } + else { + sensordata[sensor_bytes_received] = in_char; //load this byte into our array. + sensor_bytes_received++; + } + } + sensordata[sensor_bytes_received] = '\0'; + + switch (i2c_response_code) { + case 1: + Serial.print( F("< success, answer = ")); + Serial.println(sensordata); + break; + + case 2: + Serial.println( F("< command failed")); + return false; + + case 254: + Serial.println( F("< command pending")); + break; + + case 255: + Serial.println( F("< no data")); + return false; + } + } + + Serial.println(sensordata); + return true; +} From 137f4e4e37b88d9bbf43b6b3cbb04e12908eac26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Obrembski?= Date: Sun, 22 Mar 2020 13:45:51 +0100 Subject: [PATCH 02/39] Initial Ethernet support --- platformio_esp32_envs.ini | 2 +- src/ESPEasy.ino | 4 ++++ src/ESPEasyWiFiEvent.cpp | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/platformio_esp32_envs.ini b/platformio_esp32_envs.ini index e1d8aecc4..fff572e5e 100644 --- a/platformio_esp32_envs.ini +++ b/platformio_esp32_envs.ini @@ -29,7 +29,7 @@ build_flags = ${mqtt_flags.build_flags} [env:custom_ESP32_4M316k] extends = esp32_common platform = ${esp32_common.platform} -build_flags = ${esp32_common.build_flags} -DPLUGIN_BUILD_CUSTOM +build_flags = ${esp32_common.build_flags} -DPLUGIN_BUILD_CUSTOM -DHAS_ETHERNET board = esp32dev extra_scripts = ${esp32_common.extra_scripts} pre:pre_custom_esp32.py diff --git a/src/ESPEasy.ino b/src/ESPEasy.ino index d5df04936..055296462 100644 --- a/src/ESPEasy.ino +++ b/src/ESPEasy.ino @@ -1,6 +1,9 @@ #include +#ifdef HAS_ETHERNET + #include +#endif #ifdef CONTINUOUS_INTEGRATION #pragma GCC diagnostic error "-Wall" #else @@ -369,6 +372,7 @@ void setup() rulesProcessing(event); // TD-er: Process events in the setup() now. } + ETH.begin(); WiFiConnectRelaxed(); setWebserverRunning(true); diff --git a/src/ESPEasyWiFiEvent.cpp b/src/ESPEasyWiFiEvent.cpp index e8ac039e3..4a8ee84ab 100644 --- a/src/ESPEasyWiFiEvent.cpp +++ b/src/ESPEasyWiFiEvent.cpp @@ -99,6 +99,18 @@ void WiFiEvent(system_event_id_t event, system_event_info_t info) { case SYSTEM_EVENT_SCAN_DONE: processedScanDone = false; break; +#ifdef HAS_ETHERNET + case SYSTEM_EVENT_ETH_START: + break; + case SYSTEM_EVENT_ETH_CONNECTED: + break; + case SYSTEM_EVENT_ETH_DISCONNECTED: + break; + case SYSTEM_EVENT_ETH_STOP: + break; + case SYSTEM_EVENT_ETH_GOT_IP: + break; +#endif default: break; } From 14d91ccf10730808f970c7a5a4702966cfd9e0bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Obrembski?= Date: Sun, 22 Mar 2020 17:01:10 +0100 Subject: [PATCH 03/39] Added displaying Ethernet parameter in sysinfo and root page --- src/ESPEasy.ino | 7 +++-- src/ESPEasyEth.ino | 35 +++++++++++++++++++++++++ src/StringProvider.ino | 49 +++++++++++++++++++++++++++++++++++ src/StringProviderTypes.h | 13 +++++++++- src/WebServer_RootPage.ino | 5 ++++ src/WebServer_SysInfoPage.ino | 17 ++++++++++++ 6 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 src/ESPEasyEth.ino diff --git a/src/ESPEasy.ino b/src/ESPEasy.ino index 055296462..20df7794a 100644 --- a/src/ESPEasy.ino +++ b/src/ESPEasy.ino @@ -1,9 +1,6 @@ #include -#ifdef HAS_ETHERNET - #include -#endif #ifdef CONTINUOUS_INTEGRATION #pragma GCC diagnostic error "-Wall" #else @@ -372,8 +369,10 @@ void setup() rulesProcessing(event); // TD-er: Process events in the setup() now. } - ETH.begin(); WiFiConnectRelaxed(); +#ifdef HAS_ETHERNET + ETHConnectRelaxed(); +#endif setWebserverRunning(true); diff --git a/src/ESPEasyEth.ino b/src/ESPEasyEth.ino new file mode 100644 index 000000000..20502b83b --- /dev/null +++ b/src/ESPEasyEth.ino @@ -0,0 +1,35 @@ + +#ifdef HAS_ETHERNET + #define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT + #define ETH_PHY_POWER 12 + #include + + +String EthGetHostname() +{ + String hostnameToReturn(Settings.getHostname()); + hostnameToReturn.replace(" ", "-"); + hostnameToReturn.replace("_", "-"); // See RFC952 + return hostnameToReturn; +} + +bool prepareEth() { + char hostname[40]; + safe_strncpy(hostname, EthGetHostname(), sizeof(hostname)); + ETH.setHostname(hostname); + return true; +} + +void ETHConnectRelaxed() { + // if (!ethConnectAttemptNeeded) { + // return; // already connected or connect attempt in progress need to disconnect first + // } + if (!prepareEth()) { + // Dead code for now... + addLog(LOG_LEVEL_ERROR, F("ETH : Could not prepare ETH!")); + return; + } + ETH.begin(); +} + +#endif \ No newline at end of file diff --git a/src/StringProvider.ino b/src/StringProvider.ino index c5f541c8d..c9097bde1 100644 --- a/src/StringProvider.ino +++ b/src/StringProvider.ino @@ -97,6 +97,18 @@ String getLabel(LabelType::Enum label) { case LabelType::MAX_OTA_SKETCH_SIZE: return F("Max. OTA Sketch Size"); case LabelType::OTA_2STEP: return F("OTA 2-step Needed"); case LabelType::OTA_POSSIBLE: return F("OTA possible"); +#ifdef HAS_ETHERNET + case LabelType::ETH_IP_ADDRESS: return F("Eth IP Address"); + case LabelType::ETH_IP_SUBNET: return F("Eth IP Subnet"); + case LabelType::ETH_IP_ADDRESS_SUBNET: return F("Eth IP / Subnet"); + case LabelType::ETH_IP_GATEWAY: return F("Eth Gateway"); + case LabelType::ETH_IP_DNS: return F("Eth DNS"); + case LabelType::ETH_MAC: return F("Eth MAC"); + case LabelType::ETH_DUPLEX: return F("Eth Mode"); + case LabelType::ETH_SPEED: return F("Eth Speed"); + case LabelType::ETH_STATE: return F("Eth State"); + case LabelType::ETH_SPEED_STATE: return F("Eth State"); +#endif } return F("MissingString"); @@ -201,11 +213,48 @@ String getValue(LabelType::Enum label) { case LabelType::MAX_OTA_SKETCH_SIZE: break; case LabelType::OTA_2STEP: break; case LabelType::OTA_POSSIBLE: break; +#ifdef HAS_ETHERNET + case LabelType::ETH_IP_ADDRESS: return ETH.localIP().toString(); + case LabelType::ETH_IP_SUBNET: return ETH.subnetMask().toString(); + case LabelType::ETH_IP_ADDRESS_SUBNET: return String(getValue(LabelType::ETH_IP_ADDRESS) + F(" / ") + getValue(LabelType::ETH_IP_SUBNET)); + case LabelType::ETH_IP_GATEWAY: return ETH.gatewayIP().toString(); + case LabelType::ETH_IP_DNS: return ETH.dnsIP().toString(); + case LabelType::ETH_MAC: return ETH.macAddress(); + case LabelType::ETH_DUPLEX: return ETH.fullDuplex() ? F("Full Duplex") : F("Half Duplex"); + case LabelType::ETH_SPEED: return getEthSpeed(); + case LabelType::ETH_STATE: return ETH.linkUp() ? F("Link Up") : F("Link Down"); + case LabelType::ETH_SPEED_STATE: return getEthLinkSpeedState(); +#endif } return F("MissingString"); } +#ifdef HAS_ETHERNET +String getEthSpeed() { + String result; + result.reserve(7); + result += ETH.linkSpeed(); + result += F("Mbps"); + return result; +} + +String getEthLinkSpeedState() { + String result; + result.reserve(29); + if (ETH.linkUp()) { + result += getValue(LabelType::ETH_STATE); + result += ' '; + result += getValue(LabelType::ETH_DUPLEX); + result += ' '; + result += getEthSpeed(); + } else { + result = getValue(LabelType::ETH_STATE); + } + return result; +} +#endif + String getExtendedValue(LabelType::Enum label) { switch (label) { diff --git a/src/StringProviderTypes.h b/src/StringProviderTypes.h index 01c839cd3..bfbb2ae61 100644 --- a/src/StringProviderTypes.h +++ b/src/StringProviderTypes.h @@ -97,7 +97,18 @@ enum Enum : short { MAX_OTA_SKETCH_SIZE, OTA_2STEP, OTA_POSSIBLE, - +#ifdef HAS_ETHERNET + ETH_IP_ADDRESS, + ETH_IP_SUBNET, + ETH_IP_ADDRESS_SUBNET, + ETH_IP_GATEWAY, + ETH_IP_DNS, + ETH_MAC, + ETH_DUPLEX, + ETH_SPEED, + ETH_STATE, + ETH_SPEED_STATE, +#endif }; }; diff --git a/src/WebServer_RootPage.ino b/src/WebServer_RootPage.ino index 150e9230a..3e87cd8cc 100644 --- a/src/WebServer_RootPage.ino +++ b/src/WebServer_RootPage.ino @@ -120,6 +120,11 @@ void handle_root() { addHtml(html); } +#ifdef HAS_ETHERNET + addRowLabelValue(LabelType::ETH_SPEED_STATE); + addRowLabelValue(LabelType::ETH_IP_ADDRESS); +#endif + #ifdef FEATURE_MDNS { addRowLabel(getLabel(LabelType::M_DNS)); diff --git a/src/WebServer_SysInfoPage.ino b/src/WebServer_SysInfoPage.ino index 41c0c36a0..893482bd5 100644 --- a/src/WebServer_SysInfoPage.ino +++ b/src/WebServer_SysInfoPage.ino @@ -218,6 +218,10 @@ void handle_sysinfo() { handle_sysinfo_Network(); +#ifdef HAS_ETHERNET + handle_sysinfo_Ethernet(); +#endif + handle_sysinfo_WiFiSettings(); handle_sysinfo_Firmware(); @@ -311,6 +315,19 @@ void handle_sysinfo_basicInfo() { addRowLabelValue(LabelType::SW_WD_COUNT); } +#ifdef HAS_ETHERNET +void handle_sysinfo_Ethernet() { + addTableSeparator(F("Ethernet"), 2, 3); + addRowLabelValue(LabelType::ETH_STATE); + addRowLabelValue(LabelType::ETH_SPEED); + addRowLabelValue(LabelType::ETH_DUPLEX); + addRowLabelValue(LabelType::ETH_MAC); + addRowLabelValue(LabelType::ETH_IP_ADDRESS_SUBNET); + addRowLabelValue(LabelType::ETH_IP_GATEWAY); + addRowLabelValue(LabelType::ETH_IP_DNS); +} +#endif + void handle_sysinfo_Network() { addTableSeparator(F("Network"), 2, 3, F("Wifi")); From b4f01b4b5ac699978c6722161577ec4bb3c7bf8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Obrembski?= Date: Sun, 22 Mar 2020 22:39:39 +0100 Subject: [PATCH 04/39] Added configuration of Eth Phy via Hardware settings web page --- src/ESPEasyEth.ino | 71 ++++++++++++++++++++++++---- src/ESPEasy_checks.ino | 2 +- src/WebServer_HardwarePage.ino | 25 ++++++++++ src/src/DataStructs/SettingsStruct.h | 8 ++++ 4 files changed, 97 insertions(+), 9 deletions(-) diff --git a/src/ESPEasyEth.ino b/src/ESPEasyEth.ino index 20502b83b..2173e1145 100644 --- a/src/ESPEasyEth.ino +++ b/src/ESPEasyEth.ino @@ -1,9 +1,9 @@ #ifdef HAS_ETHERNET - #define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT - #define ETH_PHY_POWER 12 - #include - + // #define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT + // #define ETH_PHY_POWER 12 + #include "ETH.h" + #include String EthGetHostname() { @@ -13,23 +13,78 @@ String EthGetHostname() return hostnameToReturn; } +bool checkSettings() { + bool result = true; + if (Settings.ETH_Phy_Type != 0 && Settings.ETH_Phy_Type != 1) + result = false; + if (Settings.ETH_Clock_Mode > 3) + result = false; + if (Settings.ETH_Pin_mdc > MAX_GPIO) + result = false; + if (Settings.ETH_Pin_mdio > MAX_GPIO) + result = false; + if (Settings.ETH_Pin_power > MAX_GPIO) + result = false; + return result; +} + bool prepareEth() { - char hostname[40]; - safe_strncpy(hostname, EthGetHostname(), sizeof(hostname)); - ETH.setHostname(hostname); + if (!checkSettings()) + { + addLog(LOG_LEVEL_ERROR, F("ETH: Settings not correct!!!")); + return false; + } + ETH.setHostname(EthGetHostname().c_str()); return true; } +String getDebugClockModeStr() +{ + switch (Settings.ETH_Clock_Mode) + { + case 0: return F("ETH_CLOCK_GPIO0_IN"); + case 1: return F("ETH_CLOCK_GPIO0_OUT"); + case 2: return F("ETH_CLOCK_GPIO16_OUT"); + case 3: return F("ETH_CLOCK_GPIO17_OUT"); + default: return F("ETH_CLOCK_ERR"); + } +} + +void printSettings() +{ + String settingsDebugLog; + settingsDebugLog.reserve(115); + settingsDebugLog += F("ETH: PHY Type: "); + settingsDebugLog += Settings.ETH_Phy_Type == 0 ? F("ETH_PHY_LAN8720") : F("ETH_PHY_TLK110"); + settingsDebugLog += F(" PHY Addr: "); + settingsDebugLog += Settings.ETH_Phy_Addr; + settingsDebugLog += F(" Eth Clock mode: "); + settingsDebugLog += getDebugClockModeStr(); + settingsDebugLog += F(" MDC Pin: "); + settingsDebugLog += String(Settings.ETH_Pin_mdc); + settingsDebugLog += F(" MIO Pin: "); + settingsDebugLog += String(Settings.ETH_Pin_mdio); + settingsDebugLog += F(" Power Pin: "); + settingsDebugLog += String(Settings.ETH_Pin_power); + addLog(LOG_LEVEL_INFO, settingsDebugLog); +} + void ETHConnectRelaxed() { // if (!ethConnectAttemptNeeded) { // return; // already connected or connect attempt in progress need to disconnect first // } + printSettings(); if (!prepareEth()) { // Dead code for now... addLog(LOG_LEVEL_ERROR, F("ETH : Could not prepare ETH!")); return; } - ETH.begin(); + ETH.begin(Settings.ETH_Phy_Addr, + Settings.ETH_Pin_power, + Settings.ETH_Pin_mdc, + Settings.ETH_Pin_mdio, + (eth_phy_type_t)Settings.ETH_Phy_Type, + (eth_clock_mode_t)Settings.ETH_Clock_Mode); } #endif \ No newline at end of file diff --git a/src/ESPEasy_checks.ino b/src/ESPEasy_checks.ino index be00efd91..5de4f950c 100644 --- a/src/ESPEasy_checks.ino +++ b/src/ESPEasy_checks.ino @@ -34,7 +34,7 @@ template constexpr size_t offsetOf(U T::*member) void run_compiletime_checks() { check_size(); check_size(); - const unsigned int SettingsStructSize = (248 + 82 * TASKS_MAX); + const unsigned int SettingsStructSize = (256 + 82 * TASKS_MAX); check_size(); check_size(); check_size(); diff --git a/src/WebServer_HardwarePage.ino b/src/WebServer_HardwarePage.ino index 14ba03f6f..4926b7874 100644 --- a/src/WebServer_HardwarePage.ino +++ b/src/WebServer_HardwarePage.ino @@ -21,6 +21,14 @@ void handle_hardware() { Settings.I2C_clockSpeed = getFormItemInt(F("pi2csp"), DEFAULT_I2C_CLOCK_SPEED); Settings.InitSPI = isFormItemChecked(F("initspi")); // SPI Init Settings.Pin_sd_cs = getFormItemInt(F("sd")); +#ifdef HAS_ETHERNET + Settings.ETH_Phy_Addr = getFormItemInt(F("ethphy")); + Settings.ETH_Pin_mdc = getFormItemInt(F("ethmdc")); + Settings.ETH_Pin_mdio = getFormItemInt(F("ethmdio")); + Settings.ETH_Pin_power = getFormItemInt(F("ethpower")); + Settings.ETH_Phy_Type = getFormItemInt(F("ethtype")); + Settings.ETH_Clock_Mode = getFormItemInt(F("ethclock")); +#endif int gpio = 0; // FIXME TD-er: Max of 17 is a limit in the Settings.PinBootStates array @@ -75,6 +83,23 @@ void handle_hardware() { #ifdef FEATURE_SD addFormPinSelect(formatGpioName_output("SD Card CS"), "sd", Settings.Pin_sd_cs); #endif // ifdef FEATURE_SD +#ifdef HAS_ETHERNET + addFormSubHeader(F("Ethernet")); + addRowLabel_tr_id(F("Ethernet PHY type"), "ethtype"); + String ethPhyTypes[2] = { F("LAN8710"), F("TLK110") }; + addSelector("ethtype", 2, ethPhyTypes, NULL, NULL, Settings.ETH_Phy_Type, false, true); + addFormNumericBox(F("Ethernet PHY Address"), "ethphy", Settings.ETH_Phy_Addr, 0, 255); + addFormNote(F("I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110)")); + addFormPinSelect(formatGpioName_output("Ethernet MDC pin"), "ethmdc", Settings.ETH_Pin_mdc); + addFormPinSelect(formatGpioName_input("Ethernet MIO pin"), "ethmdio", Settings.ETH_Pin_mdio); + addFormPinSelect(formatGpioName_output("Ethernet Power pin"), "ethpower", Settings.ETH_Pin_power); + addRowLabel_tr_id(F("Ethernet Clock"), "ethclock"); + String ethClockOptions[4] = { F("External crystal oscillator"), + F("50MHz APLL Output on GPIO0"), + F("50MHz APLL Output on GPIO16"), + F("50MHz APLL Inverted Output on GPIO17") }; + addSelector("ethclock", 4, ethClockOptions, NULL, NULL, Settings.ETH_Clock_Mode, false, true); +#endif // ifdef HAS_ETHERNET addFormSubHeader(F("GPIO boot states")); int gpio = 0; diff --git a/src/src/DataStructs/SettingsStruct.h b/src/src/DataStructs/SettingsStruct.h index acec419a7..d8e63ca73 100644 --- a/src/src/DataStructs/SettingsStruct.h +++ b/src/src/DataStructs/SettingsStruct.h @@ -177,6 +177,14 @@ class SettingsStruct_tmpl // Try to extend settings to make the checksum 4-byte aligned. // uint8_t ProgmemMd5[16]; // crc of the binary that last saved the struct to file. // uint8_t md5[16]; +#ifdef HAS_ETHERNET + uint8_t ETH_Phy_Addr; + int8_t ETH_Pin_mdc; + int8_t ETH_Pin_mdio; + int8_t ETH_Pin_power; + int8_t ETH_Phy_Type; + uint8_t ETH_Clock_Mode; +#endif }; /* From c7b9f3f55e118dacfaf3e331f2c2ac8782df35da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Obrembski?= Date: Mon, 23 Mar 2020 11:11:07 +0100 Subject: [PATCH 05/39] Added Olimex ESP32-PoE board to DeviceModel and default settings --- src/ESPEasy-Globals.h | 19 +++++++++++++++++++ src/ESPEasy_checks.ino | 6 +++++- src/Hardware.ino | 3 +++ src/Misc.ino | 9 +++++++++ src/src/DataStructs/DeviceModel.h | 1 + src/src/DataStructs/ESPEasyDefaults.h | 21 +++++++++++++++++++++ src/src/DataStructs/SettingsStruct.cpp | 8 ++++++++ 7 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/ESPEasy-Globals.h b/src/ESPEasy-Globals.h index f7dbdda74..f9625739e 100644 --- a/src/ESPEasy-Globals.h +++ b/src/ESPEasy-Globals.h @@ -422,6 +422,17 @@ struct GpioFactorySettingsStruct { i2c_sda = -1; // GPIO4 conflicts with relay control. i2c_scl = -1; // GPIO5 conflicts with SW input break; + case DeviceMode_Olimex_ESP32_PoE: + button[0] = 34; // DUT1 Button + relais[0] = -1; // No LED's or relays on board + status_led = -1; + i2c_sda = 4; + i2c_scl = 5; + #ifdef HAS_ETHERNET + eth_power = 12; + eth_clock_mode = 3; + #endif + break; // case DeviceModel_default: break; default: break; @@ -433,6 +444,14 @@ struct GpioFactorySettingsStruct { int8_t status_led = DEFAULT_PIN_STATUS_LED; int8_t i2c_sda = DEFAULT_PIN_I2C_SDA; int8_t i2c_scl = DEFAULT_PIN_I2C_SCL; +#ifdef HAS_ETHERNET + int8_t eth_phyaddr = DEFAULT_ETH_PHY_ADDR; + int8_t eth_phytype = DEFAULT_ETH_PHY_TYPE; + int8_t eth_mdc = DEFAULT_ETH_PIN_MDC; + int8_t eth_mdio = DEFAULT_ETH_PIN_MDIO; + int8_t eth_power = DEFAULT_ETH_PIN_POWER; + int8_t eth_clock_mode = DEFAULT_ETH_CLOCK_MODE; +#endif }; void addPredefinedPlugins(const GpioFactorySettingsStruct& gpio_settings); diff --git a/src/ESPEasy_checks.ino b/src/ESPEasy_checks.ino index 5de4f950c..aa6c5613f 100644 --- a/src/ESPEasy_checks.ino +++ b/src/ESPEasy_checks.ino @@ -34,7 +34,11 @@ template constexpr size_t offsetOf(U T::*member) void run_compiletime_checks() { check_size(); check_size(); +#ifdef HAS_ETHERNET const unsigned int SettingsStructSize = (256 + 82 * TASKS_MAX); +#else + const unsigned int SettingsStructSize = (248 + 82 * TASKS_MAX); +#endif check_size(); check_size(); check_size(); @@ -54,7 +58,7 @@ void run_compiletime_checks() { check_size(); check_size(); check_size(); - check_size(); + check_size(); #if defined(USE_NON_STANDARD_24_TASKS) && defined(ESP8266) static_assert(TASKS_MAX == 24, "TASKS_MAX invalid size"); #endif diff --git a/src/Hardware.ino b/src/Hardware.ino index e06b9b451..1aed68d5c 100644 --- a/src/Hardware.ino +++ b/src/Hardware.ino @@ -166,6 +166,7 @@ String getDeviceModelBrandString(DeviceModel model) { case DeviceModel_Sonoff_POW: case DeviceModel_Sonoff_POWr2: return F("Sonoff"); case DeviceModel_Shelly1: return F("Shelly"); + case DeviceMode_Olimex_ESP32_PoE: return F("Olimex"); // case DeviceModel_default: default: return ""; @@ -189,6 +190,7 @@ String getDeviceModelString(DeviceModel model) { case DeviceModel_Sonoff_POW: result += F(" POW"); break; case DeviceModel_Sonoff_POWr2: result += F(" POW-r2"); break; case DeviceModel_Shelly1: result += '1'; break; + case DeviceMode_Olimex_ESP32_PoE: result += F(" ESP32-PoE"); break; // case DeviceModel_default: default: result += F("default"); @@ -211,6 +213,7 @@ bool modelMatchingFlashSize(DeviceModel model) { case DeviceModel_Sonoff_POW: case DeviceModel_Sonoff_POWr2: return size_MB == 4; case DeviceModel_Shelly1: return size_MB == 2; + case DeviceMode_Olimex_ESP32_PoE:return size_MB == 4; // case DeviceModel_default: default: return true; diff --git a/src/Misc.ino b/src/Misc.ino index d4dc6666f..4a683dc53 100644 --- a/src/Misc.ino +++ b/src/Misc.ino @@ -1208,6 +1208,15 @@ void ResetFactory() Settings.UseSerial = DEFAULT_USE_SERIAL; Settings.BaudRate = DEFAULT_SERIAL_BAUD; +#ifdef HAS_ETHERNET + Settings.ETH_Phy_Addr = gpio_settings.eth_phyaddr; + Settings.ETH_Pin_mdc = gpio_settings.eth_mdc; + Settings.ETH_Pin_mdio = gpio_settings.eth_mdio; + Settings.ETH_Pin_power = gpio_settings.eth_power; + Settings.ETH_Phy_Type = gpio_settings.eth_phytype; + Settings.ETH_Clock_Mode = gpio_settings.eth_clock_mode; +#endif + /* Settings.GlobalSync = DEFAULT_USE_GLOBAL_SYNC; diff --git a/src/src/DataStructs/DeviceModel.h b/src/src/DataStructs/DeviceModel.h index dca830c92..4fd4cf830 100644 --- a/src/src/DataStructs/DeviceModel.h +++ b/src/src/DataStructs/DeviceModel.h @@ -18,6 +18,7 @@ enum DeviceModel { DeviceModel_Sonoff_POW, DeviceModel_Sonoff_POWr2, DeviceModel_Shelly1, + DeviceMode_Olimex_ESP32_PoE, DeviceModel_MAX }; diff --git a/src/src/DataStructs/ESPEasyDefaults.h b/src/src/DataStructs/ESPEasyDefaults.h index b2597308f..999a328dc 100644 --- a/src/src/DataStructs/ESPEasyDefaults.h +++ b/src/src/DataStructs/ESPEasyDefaults.h @@ -168,6 +168,27 @@ #define DEFAULT_PIN_STATUS_LED_INVERSED true #endif +#ifdef HAS_ETHERNET +#ifndef DEFAULT_ETH_PHY_ADDR +#define DEFAULT_ETH_PHY_ADDR 0 +#endif +#ifndef DEFAULT_ETH_PHY_TYPE +#define DEFAULT_ETH_PHY_TYPE 0 +#endif +#ifndef DEFAULT_ETH_PIN_MDC +#define DEFAULT_ETH_PIN_MDC 23 +#endif +#ifndef DEFAULT_ETH_PIN_MDIO +#define DEFAULT_ETH_PIN_MDIO 18 +#endif +#ifndef DEFAULT_ETH_PIN_POWER +#define DEFAULT_ETH_PIN_POWER -1 +#endif +#ifndef DEFAULT_ETH_CLOCK_MODE +#define DEFAULT_ETH_CLOCK_MODE 3 +#endif +#endif + // --- Advanced Settings --------------------------------------------------------------------------------- diff --git a/src/src/DataStructs/SettingsStruct.cpp b/src/src/DataStructs/SettingsStruct.cpp index 5ef1bc683..1faf47b15 100644 --- a/src/src/DataStructs/SettingsStruct.cpp +++ b/src/src/DataStructs/SettingsStruct.cpp @@ -206,6 +206,14 @@ void SettingsStruct_tmpl::clearMisc() { Pin_i2c_scl = -1; Pin_status_led = -1; Pin_sd_cs = -1; +#ifdef HAS_ETHERNET + ETH_Phy_Addr = 0; + ETH_Pin_mdc = -1; + ETH_Pin_mdio = -1; + ETH_Pin_power = -1; + ETH_Phy_Type = 0; + ETH_Clock_Mode = 0; +#endif for (byte i = 0; i < 17; ++i) { PinBootStates[i] = 0; } BaudRate = 0; From dffd7ebfc1da7f081de49a3efce666db5973934d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Obrembski?= Date: Mon, 23 Mar 2020 12:33:08 +0100 Subject: [PATCH 06/39] Increased BUILD number to 20107 --- src/ESPEasyStorage.ino | 10 ++++++++++ src/ESPEasy_buildinfo.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ESPEasyStorage.ino b/src/ESPEasyStorage.ino index 700e60898..b90ec34e6 100644 --- a/src/ESPEasyStorage.ino +++ b/src/ESPEasyStorage.ino @@ -178,6 +178,16 @@ String BuildFixes() } #endif // USES_MQTT } +#ifdef HAS_ETHERNET + if (Settings.Build < 20107) { + Settings.ETH_Phy_Addr = DEFAULT_ETH_PHY_ADDR; + Settings.ETH_Pin_mdc = DEFAULT_ETH_PIN_MDC; + Settings.ETH_Pin_mdio = DEFAULT_ETH_PIN_MDIO; + Settings.ETH_Pin_power = DEFAULT_ETH_PIN_POWER; + Settings.ETH_Phy_Type = DEFAULT_ETH_PHY_TYPE; + Settings.ETH_Clock_Mode = DEFAULT_ETH_CLOCK_MODE; + } +#endif Settings.Build = BUILD; return SaveSettings(); diff --git a/src/ESPEasy_buildinfo.h b/src/ESPEasy_buildinfo.h index d87055c12..b6647320a 100644 --- a/src/ESPEasy_buildinfo.h +++ b/src/ESPEasy_buildinfo.h @@ -20,7 +20,7 @@ #endif // if defined(ESP32) -#define BUILD 20106 // git version e.g. "20103" can be read as "2.1.03" (stored in int16_t) +#define BUILD 20107 // git version e.g. "20103" can be read as "2.1.03" (stored in int16_t) #if defined(ESP8266) # define BUILD_NOTES " - Mega" #endif // if defined(ESP8266) From 5f15e98e5a93d7c9e6f2baa5d3222702663ebad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Obrembski?= Date: Mon, 23 Mar 2020 12:50:55 +0100 Subject: [PATCH 07/39] Fix build on devices without Ethernet. Forget to adjust size of GpioFactorySettingsStruct. --- src/ESPEasy_checks.ino | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ESPEasy_checks.ino b/src/ESPEasy_checks.ino index aa6c5613f..c3432d664 100644 --- a/src/ESPEasy_checks.ino +++ b/src/ESPEasy_checks.ino @@ -58,7 +58,12 @@ void run_compiletime_checks() { check_size(); check_size(); check_size(); - check_size(); +#ifdef HAS_ETHERNET + const unsigned int GpioFactorySettingsStructSize = 17; +#else + const unsigned int GpioFactorySettingsStructSize = 11; +#endif + check_size(); #if defined(USE_NON_STANDARD_24_TASKS) && defined(ESP8266) static_assert(TASKS_MAX == 24, "TASKS_MAX invalid size"); #endif From 9314523c22ee4e96f9b682bd6ec1a287e3f7c27a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Obrembski?= Date: Mon, 23 Mar 2020 13:20:55 +0100 Subject: [PATCH 08/39] Remove ifdefs for Ethernet in settings --- src/ESPEasy-Globals.h | 4 - src/ESPEasyEth_ProcessEvent.ino | 426 ++++++++++++++++++++++++++ src/ESPEasyStorage.ino | 2 - src/ESPEasy_checks.ino | 11 +- src/Misc.ino | 2 - src/src/DataStructs/ESPEasyDefaults.h | 2 - src/src/DataStructs/SettingsStruct.h | 2 - 7 files changed, 427 insertions(+), 22 deletions(-) create mode 100644 src/ESPEasyEth_ProcessEvent.ino diff --git a/src/ESPEasy-Globals.h b/src/ESPEasy-Globals.h index f9625739e..109000964 100644 --- a/src/ESPEasy-Globals.h +++ b/src/ESPEasy-Globals.h @@ -428,10 +428,8 @@ struct GpioFactorySettingsStruct { status_led = -1; i2c_sda = 4; i2c_scl = 5; - #ifdef HAS_ETHERNET eth_power = 12; eth_clock_mode = 3; - #endif break; // case DeviceModel_default: break; @@ -444,14 +442,12 @@ struct GpioFactorySettingsStruct { int8_t status_led = DEFAULT_PIN_STATUS_LED; int8_t i2c_sda = DEFAULT_PIN_I2C_SDA; int8_t i2c_scl = DEFAULT_PIN_I2C_SCL; -#ifdef HAS_ETHERNET int8_t eth_phyaddr = DEFAULT_ETH_PHY_ADDR; int8_t eth_phytype = DEFAULT_ETH_PHY_TYPE; int8_t eth_mdc = DEFAULT_ETH_PIN_MDC; int8_t eth_mdio = DEFAULT_ETH_PIN_MDIO; int8_t eth_power = DEFAULT_ETH_PIN_POWER; int8_t eth_clock_mode = DEFAULT_ETH_CLOCK_MODE; -#endif }; void addPredefinedPlugins(const GpioFactorySettingsStruct& gpio_settings); diff --git a/src/ESPEasyEth_ProcessEvent.ino b/src/ESPEasyEth_ProcessEvent.ino new file mode 100644 index 000000000..3ed601e46 --- /dev/null +++ b/src/ESPEasyEth_ProcessEvent.ino @@ -0,0 +1,426 @@ +#include "src/Globals/ESPEasyWiFiEvent.h" + +/* +bool unprocessedWifiEvents() { + if (processedConnect && processedDisconnect && processedGotIP && processedDHCPTimeout) + { + return false; + } + return true; +} + +// ******************************************************************************** +// Called from the loop() to make sure events are processed as soon as possible. +// These functions are called from Setup() or Loop() and thus may call delay() or yield() +// ******************************************************************************** +void handle_unprocessedWiFiEvents() +{ + if (WiFi.status() == WL_DISCONNECTED) { + delay(100); + } + + if ((wifiStatus != ESPEASY_WIFI_SERVICES_INITIALIZED) || unprocessedWifiEvents()) { + // WiFi connection is not yet available, so introduce some extra delays to + // help the background tasks managing wifi connections + delay(1); + + if (wifiConnectAttemptNeeded) { + WiFiConnectRelaxed(); + } + + // Process disconnect events before connect events. + if (!processedDisconnect) { + #ifndef BUILD_NO_DEBUG + addLog(LOG_LEVEL_DEBUG, F("WIFI : Entering processDisconnect()")); + #endif // ifndef BUILD_NO_DEBUG + processDisconnect(); + } + + if (!processedConnect) { + #ifndef BUILD_NO_DEBUG + addLog(LOG_LEVEL_DEBUG, F("WIFI : Entering processConnect()")); + #endif // ifndef BUILD_NO_DEBUG + processConnect(); + } + + if (!processedGotIP) { + #ifndef BUILD_NO_DEBUG + addLog(LOG_LEVEL_DEBUG, F("WIFI : Entering processGotIP()")); + #endif // ifndef BUILD_NO_DEBUG + processGotIP(); + } + + if (!processedDHCPTimeout) { + #ifndef BUILD_NO_DEBUG + addLog(LOG_LEVEL_DEBUG, F("WIFI : DHCP timeout, Calling disconnect()")); + #endif // ifndef BUILD_NO_DEBUG + processedDHCPTimeout = true; + processDisconnect(); + } + + if (wifiStatus & ESPEASY_WIFI_CONNECTED) { + // The actual connection has been made, no need to wait for IP to release this semaphore. + wifiConnectInProgress = false; + } + + if ((wifiStatus & ESPEASY_WIFI_GOT_IP) && (wifiStatus & ESPEASY_WIFI_CONNECTED) && WiFi.isConnected()) { + markWiFi_services_initialized(); + } + } else if (!WiFiConnected()) { + // Somehow the WiFi has entered a limbo state. + // FIXME TD-er: This may happen on WiFi config with AP_STA mode active. + // addLog(LOG_LEVEL_ERROR, F("Wifi status out sync")); + // resetWiFi(); + if (loglevelActiveFor(LOG_LEVEL_ERROR)) { + String wifilog = F("WIFI : Wifi status out sync WiFi.status() = "); + wifilog += String(WiFi.status()); + + addLog(LOG_LEVEL_ERROR, wifilog); + } + } + + if (wifiStatus == ESPEASY_WIFI_DISCONNECTED) { + #ifndef BUILD_NO_DEBUG + + if (loglevelActiveFor(LOG_LEVEL_DEBUG)) { + String wifilog = F("WIFI : Disconnected: WiFi.status() = "); + wifilog += String(WiFi.status()); + + addLog(LOG_LEVEL_DEBUG, wifilog); + } + #endif // ifndef BUILD_NO_DEBUG + + // While connecting to WiFi make sure the device has ample time to do so + delay(10); + } + + if (!processedDisconnectAPmode) { processDisconnectAPmode(); } + + if (!processedConnectAPmode) { processConnectAPmode(); } + + if (timerAPoff != 0) { processDisableAPmode(); } + + if (!processedScanDone) { processScanDone(); } + + if (wifi_connect_attempt > 0) { + // We only want to clear this counter if the connection is currently stable. + if (wifiStatus == ESPEASY_WIFI_SERVICES_INITIALIZED) { + if (timePassedSince(lastConnectMoment) > WIFI_CONNECTION_CONSIDERED_STABLE) { + // Connection considered stable + wifi_connect_attempt = 0; + + if (!WiFi.getAutoConnect()) { + WiFi.setAutoConnect(true); + } + } else { + if (WiFi.getAutoConnect()) { + WiFi.setAutoConnect(false); + } + } + } + } +} + +// ******************************************************************************** +// Functions to process the data gathered from the events. +// These functions are called from Setup() or Loop() and thus may call delay() or yield() +// ******************************************************************************** +void processDisconnect() { + if (processedDisconnect) { return; } + processedDisconnect = true; + wifiStatus = ESPEASY_WIFI_DISCONNECTED; +// setWebserverRunning(false); + delay(100); // FIXME TD-er: See https://github.com/letscontrolit/ESPEasy/issues/1987#issuecomment-451644424 + + if (Settings.UseRules) { + eventQueue.add(F("WiFi#Disconnected")); + } + + if (loglevelActiveFor(LOG_LEVEL_INFO)) { + String log = F("WIFI : Disconnected! Reason: '"); + log += getLastDisconnectReason(); + log += '\''; + + if (lastConnectedDuration > 0) { + log += F(" Connected for "); + log += format_msec_duration(lastConnectedDuration); + } + addLog(LOG_LEVEL_INFO, log); + } + + if (Settings.WiFiRestart_connection_lost()) { + setWifiMode(WIFI_OFF); + delay(100); + } + logConnectionStatus(); +} + +void processConnect() { + if (processedConnect) { return; } + processedConnect = true; + wifiStatus |= ESPEASY_WIFI_CONNECTED; + delay(100); // FIXME TD-er: See https://github.com/letscontrolit/ESPEasy/issues/1987#issuecomment-451644424 + ++wifi_reconnects; + + if (wifiStatus < ESPEASY_WIFI_CONNECTED) { return; } + + if (loglevelActiveFor(LOG_LEVEL_INFO)) { + const long connect_duration = timeDiff(last_wifi_connect_attempt_moment, lastConnectMoment); + String log = F("WIFI : Connected! AP: "); + log += WiFi.SSID(); + log += " ("; + log += WiFi.BSSIDstr(); + log += F(") Ch: "); + log += RTC.lastWiFiChannel; + + if ((connect_duration > 0) && (connect_duration < 30000)) { + // Just log times when they make sense. + log += F(" Duration: "); + log += connect_duration; + log += F(" ms"); + } + addLog(LOG_LEVEL_INFO, log); + } + + if (Settings.UseRules) { + if (bssid_changed) { + eventQueue.add(F("WiFi#ChangedAccesspoint")); + } + + if (channel_changed) { + eventQueue.add(F("WiFi#ChangedWiFichannel")); + } + } + + if (useStaticIP()) { + markGotIP(); // in static IP config the got IP event is never fired. + } + saveToRTC(); + + logConnectionStatus(); +} + +void processGotIP() { + if (processedGotIP) { + return; + } + IPAddress ip = WiFi.localIP(); + + if (!useStaticIP()) { + if ((ip[0] == 0) && (ip[1] == 0) && (ip[2] == 0) && (ip[3] == 0)) { + return; + } + } + processedGotIP = true; + wifiStatus |= ESPEASY_WIFI_GOT_IP; + const IPAddress gw = WiFi.gatewayIP(); + const IPAddress subnet = WiFi.subnetMask(); + const long dhcp_duration = timeDiff(lastConnectMoment, lastGetIPmoment); + + if (loglevelActiveFor(LOG_LEVEL_INFO)) { + String log = F("WIFI : "); + + if (useStaticIP()) { + log += F("Static IP: "); + } else { + log += F("DHCP IP: "); + } + log += formatIP(ip); + log += " ("; + log += WifiGetHostname(); + log += F(") GW: "); + log += formatIP(gw); + log += F(" SN: "); + log += formatIP(subnet); + + if ((dhcp_duration > 0) && (dhcp_duration < 30000)) { + // Just log times when they make sense. + log += F(" duration: "); + log += dhcp_duration; + log += F(" ms"); + } + addLog(LOG_LEVEL_INFO, log); + } + + // Might not work in core 2.5.0 + // See https://github.com/esp8266/Arduino/issues/5839 + if ((Settings.IP_Octet != 0) && (Settings.IP_Octet != 255)) + { + ip[3] = Settings.IP_Octet; + + if (loglevelActiveFor(LOG_LEVEL_INFO)) { + String log = F("IP : Fixed IP octet:"); + log += formatIP(ip); + addLog(LOG_LEVEL_INFO, log); + } + WiFi.config(ip, gw, subnet); + } + + // First try to get the time, since that may be used in logs + if (node_time.systemTimePresent()) { + node_time.initTime(); + } +#ifdef USES_MQTT + mqtt_reconnect_count = 0; + MQTTclient_should_reconnect = true; + timermqtt_interval = 100; + setIntervalTimer(TIMER_MQTT); +#endif // USES_MQTT + sendGratuitousARP_now(); + + if (Settings.UseRules) + { + eventQueue.add(F("WiFi#Connected")); + } + statusLED(true); + + // WiFi.scanDelete(); + + if (wifiSetup) { + // Wifi setup was active, Apparently these settings work. + wifiSetup = false; + SaveSettings(); + } + logConnectionStatus(); +} + +// A client disconnected from the AP on this node. +void processDisconnectAPmode() { + if (processedDisconnectAPmode) { return; } + processedDisconnectAPmode = true; + + if (loglevelActiveFor(LOG_LEVEL_INFO)) { + const int nrStationsConnected = WiFi.softAPgetStationNum(); + String log = F("AP Mode: Client disconnected: "); + log += formatMAC(lastMacDisconnectedAPmode); + log += F(" Connected devices: "); + log += nrStationsConnected; + addLog(LOG_LEVEL_INFO, log); + } +} + +// Client connects to AP on this node +void processConnectAPmode() { + if (processedConnectAPmode) { return; } + processedConnectAPmode = true; + // Extend timer to switch off AP. + timerAPoff = millis() + WIFI_AP_OFF_TIMER_DURATION; + + if (loglevelActiveFor(LOG_LEVEL_INFO)) { + String log = F("AP Mode: Client connected: "); + log += formatMAC(lastMacConnectedAPmode); + log += F(" Connected devices: "); + log += WiFi.softAPgetStationNum(); + addLog(LOG_LEVEL_INFO, log); + } + setWebserverRunning(true); + + // Start DNS, only used if the ESP has no valid WiFi config + // It will reply with it's own address on all DNS requests + // (captive portal concept) + if (!dnsServerActive) { + dnsServerActive = true; + dnsServer.start(DNS_PORT, "*", apIP); + } +} + +// Switch of AP mode when timeout reached and no client connected anymore. +void processDisableAPmode() { + if (timerAPoff == 0) { return; } + + if (WifiIsAP(WiFi.getMode())) { + // disable AP after timeout and no clients connected. + if (timeOutReached(timerAPoff) && (WiFi.softAPgetStationNum() == 0)) { + setAP(false); + } + } + + if (!WifiIsAP(WiFi.getMode())) { + timerAPoff = 0; + } +} + +void processScanDone() { + if (processedScanDone) { return; } + + // Better act on the scan done event, as it may get triggered for normal wifi begin calls. + int8_t scanCompleteStatus = WiFi.scanComplete(); + switch (scanCompleteStatus) { + case 0: // Nothing (yet) found + if (timePassedSince(lastGetScanMoment) > 5000) { + processedScanDone = true; + } + return; + case -1: // WIFI_SCAN_RUNNING + return; + case -2: // WIFI_SCAN_FAILED + addLog(LOG_LEVEL_ERROR, F("WiFi : Scan failed")); + processedScanDone = true; + return; + } + + lastGetScanMoment = millis(); + processedScanDone = true; + + if (loglevelActiveFor(LOG_LEVEL_INFO)) { + String log = F("WIFI : Scan finished, found: "); + log += scanCompleteStatus; + addLog(LOG_LEVEL_INFO, log); + } + + int bestScanID = -1; + int32_t bestRssi = -1000; + uint8_t bestWiFiSettings = RTC.lastWiFiSettingsIndex; + + if (selectValidWiFiSettings() && scanCompleteStatus > 0) { + const uint8_t startWiFiSettings = RTC.lastWiFiSettingsIndex; + bool done = false; + while (!done) { + String ssid_to_check = getLastWiFiSettingsSSID(); + for (int i = 0; i < scanCompleteStatus; ++i) { + if (WiFi.SSID(i) == ssid_to_check) { + int32_t rssi = WiFi.RSSI(i); + + if (bestRssi < rssi) { + bestRssi = rssi; + bestScanID = i; + bestWiFiSettings = RTC.lastWiFiSettingsIndex; + } + } + } + + // Select the next WiFi settings. + // RTC.lastWiFiSettingsIndex may be updated. + if (!selectNextWiFiSettings()) { + done = true; + } + if (startWiFiSettings == RTC.lastWiFiSettingsIndex) { + done = true; + } + } + + if (bestScanID >= 0) { + if (loglevelActiveFor(LOG_LEVEL_INFO)) { + String log = F("WIFI : Selected: "); + log += formatScanResult(bestScanID, " "); + addLog(LOG_LEVEL_INFO, log); + } + RTC.lastWiFiSettingsIndex = bestWiFiSettings; + uint8_t *scanbssid = WiFi.BSSID(bestScanID); + + if (scanbssid) { + for (int i = 0; i < 6; ++i) { + RTC.lastBSSID[i] = *(scanbssid + i); + } + } + } + } +} + + +void markWiFi_services_initialized() { + wifiStatus = ESPEASY_WIFI_SERVICES_INITIALIZED; + wifiConnectInProgress = false; + setWebserverRunning(true); +} +*/ \ No newline at end of file diff --git a/src/ESPEasyStorage.ino b/src/ESPEasyStorage.ino index b90ec34e6..2bc92cc1e 100644 --- a/src/ESPEasyStorage.ino +++ b/src/ESPEasyStorage.ino @@ -178,7 +178,6 @@ String BuildFixes() } #endif // USES_MQTT } -#ifdef HAS_ETHERNET if (Settings.Build < 20107) { Settings.ETH_Phy_Addr = DEFAULT_ETH_PHY_ADDR; Settings.ETH_Pin_mdc = DEFAULT_ETH_PIN_MDC; @@ -187,7 +186,6 @@ String BuildFixes() Settings.ETH_Phy_Type = DEFAULT_ETH_PHY_TYPE; Settings.ETH_Clock_Mode = DEFAULT_ETH_CLOCK_MODE; } -#endif Settings.Build = BUILD; return SaveSettings(); diff --git a/src/ESPEasy_checks.ino b/src/ESPEasy_checks.ino index c3432d664..0761d9e61 100644 --- a/src/ESPEasy_checks.ino +++ b/src/ESPEasy_checks.ino @@ -34,11 +34,7 @@ template constexpr size_t offsetOf(U T::*member) void run_compiletime_checks() { check_size(); check_size(); -#ifdef HAS_ETHERNET const unsigned int SettingsStructSize = (256 + 82 * TASKS_MAX); -#else - const unsigned int SettingsStructSize = (248 + 82 * TASKS_MAX); -#endif check_size(); check_size(); check_size(); @@ -58,12 +54,7 @@ void run_compiletime_checks() { check_size(); check_size(); check_size(); -#ifdef HAS_ETHERNET - const unsigned int GpioFactorySettingsStructSize = 17; -#else - const unsigned int GpioFactorySettingsStructSize = 11; -#endif - check_size(); + check_size(); #if defined(USE_NON_STANDARD_24_TASKS) && defined(ESP8266) static_assert(TASKS_MAX == 24, "TASKS_MAX invalid size"); #endif diff --git a/src/Misc.ino b/src/Misc.ino index 4a683dc53..d81d24952 100644 --- a/src/Misc.ino +++ b/src/Misc.ino @@ -1208,14 +1208,12 @@ void ResetFactory() Settings.UseSerial = DEFAULT_USE_SERIAL; Settings.BaudRate = DEFAULT_SERIAL_BAUD; -#ifdef HAS_ETHERNET Settings.ETH_Phy_Addr = gpio_settings.eth_phyaddr; Settings.ETH_Pin_mdc = gpio_settings.eth_mdc; Settings.ETH_Pin_mdio = gpio_settings.eth_mdio; Settings.ETH_Pin_power = gpio_settings.eth_power; Settings.ETH_Phy_Type = gpio_settings.eth_phytype; Settings.ETH_Clock_Mode = gpio_settings.eth_clock_mode; -#endif /* Settings.GlobalSync = DEFAULT_USE_GLOBAL_SYNC; diff --git a/src/src/DataStructs/ESPEasyDefaults.h b/src/src/DataStructs/ESPEasyDefaults.h index 999a328dc..688b5e6da 100644 --- a/src/src/DataStructs/ESPEasyDefaults.h +++ b/src/src/DataStructs/ESPEasyDefaults.h @@ -168,7 +168,6 @@ #define DEFAULT_PIN_STATUS_LED_INVERSED true #endif -#ifdef HAS_ETHERNET #ifndef DEFAULT_ETH_PHY_ADDR #define DEFAULT_ETH_PHY_ADDR 0 #endif @@ -187,7 +186,6 @@ #ifndef DEFAULT_ETH_CLOCK_MODE #define DEFAULT_ETH_CLOCK_MODE 3 #endif -#endif diff --git a/src/src/DataStructs/SettingsStruct.h b/src/src/DataStructs/SettingsStruct.h index d8e63ca73..ae9d27f00 100644 --- a/src/src/DataStructs/SettingsStruct.h +++ b/src/src/DataStructs/SettingsStruct.h @@ -177,14 +177,12 @@ class SettingsStruct_tmpl // Try to extend settings to make the checksum 4-byte aligned. // uint8_t ProgmemMd5[16]; // crc of the binary that last saved the struct to file. // uint8_t md5[16]; -#ifdef HAS_ETHERNET uint8_t ETH_Phy_Addr; int8_t ETH_Pin_mdc; int8_t ETH_Pin_mdio; int8_t ETH_Pin_power; int8_t ETH_Phy_Type; uint8_t ETH_Clock_Mode; -#endif }; /* From 7584ce6cc9ed45a925fdc0d30a1cef9d6f7930f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Obrembski?= Date: Mon, 23 Mar 2020 23:19:48 +0100 Subject: [PATCH 09/39] Renamed functions in ESPEasyEth, added eth* prefix --- src/ESPEasyEth.ino | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/ESPEasyEth.ino b/src/ESPEasyEth.ino index 2173e1145..8016d32ae 100644 --- a/src/ESPEasyEth.ino +++ b/src/ESPEasyEth.ino @@ -1,19 +1,16 @@ #ifdef HAS_ETHERNET - // #define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT - // #define ETH_PHY_POWER 12 - #include "ETH.h" - #include -String EthGetHostname() -{ +#include "ETH.h" + +String ethGetHostname() { String hostnameToReturn(Settings.getHostname()); hostnameToReturn.replace(" ", "-"); hostnameToReturn.replace("_", "-"); // See RFC952 return hostnameToReturn; } -bool checkSettings() { +bool ethCheckSettings() { bool result = true; if (Settings.ETH_Phy_Type != 0 && Settings.ETH_Phy_Type != 1) result = false; @@ -28,18 +25,17 @@ bool checkSettings() { return result; } -bool prepareEth() { - if (!checkSettings()) +bool ethPrepare() { + if (!ethCheckSettings()) { addLog(LOG_LEVEL_ERROR, F("ETH: Settings not correct!!!")); return false; } - ETH.setHostname(EthGetHostname().c_str()); + ETH.setHostname(ethGetHostname().c_str()); return true; } -String getDebugClockModeStr() -{ +String ethGetDebugClockModeStr() { switch (Settings.ETH_Clock_Mode) { case 0: return F("ETH_CLOCK_GPIO0_IN"); @@ -50,8 +46,7 @@ String getDebugClockModeStr() } } -void printSettings() -{ +void ethPrintSettings() { String settingsDebugLog; settingsDebugLog.reserve(115); settingsDebugLog += F("ETH: PHY Type: "); @@ -59,7 +54,7 @@ void printSettings() settingsDebugLog += F(" PHY Addr: "); settingsDebugLog += Settings.ETH_Phy_Addr; settingsDebugLog += F(" Eth Clock mode: "); - settingsDebugLog += getDebugClockModeStr(); + settingsDebugLog += ethGetDebugClockModeStr(); settingsDebugLog += F(" MDC Pin: "); settingsDebugLog += String(Settings.ETH_Pin_mdc); settingsDebugLog += F(" MIO Pin: "); @@ -70,11 +65,8 @@ void printSettings() } void ETHConnectRelaxed() { - // if (!ethConnectAttemptNeeded) { - // return; // already connected or connect attempt in progress need to disconnect first - // } - printSettings(); - if (!prepareEth()) { + ethPrintSettings(); + if (!ethPrepare()) { // Dead code for now... addLog(LOG_LEVEL_ERROR, F("ETH : Could not prepare ETH!")); return; From 6137da89f00d8053d92c11bc15f31ea3cd7085c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Obrembski?= Date: Tue, 24 Mar 2020 09:40:34 +0100 Subject: [PATCH 10/39] Moved WifiGetHostname into more generic createRFCCompliantHostname --- src/ESPEasyEth.ino | 9 +-------- src/ESPEasyWifi.ino | 14 +------------- src/ESPEasyWifi_ProcessEvent.ino | 2 +- src/Networking.ino | 10 ++++++++++ 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/ESPEasyEth.ino b/src/ESPEasyEth.ino index 8016d32ae..de595e0d0 100644 --- a/src/ESPEasyEth.ino +++ b/src/ESPEasyEth.ino @@ -3,13 +3,6 @@ #include "ETH.h" -String ethGetHostname() { - String hostnameToReturn(Settings.getHostname()); - hostnameToReturn.replace(" ", "-"); - hostnameToReturn.replace("_", "-"); // See RFC952 - return hostnameToReturn; -} - bool ethCheckSettings() { bool result = true; if (Settings.ETH_Phy_Type != 0 && Settings.ETH_Phy_Type != 1) @@ -31,7 +24,7 @@ bool ethPrepare() { addLog(LOG_LEVEL_ERROR, F("ETH: Settings not correct!!!")); return false; } - ETH.setHostname(ethGetHostname().c_str()); + ETH.setHostname(createRFCCompliantHostname(Settings.getHostname()).c_str()); return true; } diff --git a/src/ESPEasyWifi.ino b/src/ESPEasyWifi.ino index 9eec41d8d..4d6f56538 100644 --- a/src/ESPEasyWifi.ino +++ b/src/ESPEasyWifi.ino @@ -203,7 +203,7 @@ bool prepareWiFi() { } setSTA(true); char hostname[40]; - safe_strncpy(hostname, WifiGetHostname().c_str(), sizeof(hostname)); + safe_strncpy(hostname, createRFCCompliantHostname(WifiGetAPssid()).c_str(), sizeof(hostname)); #if defined(ESP8266) wifi_station_set_hostname(hostname); @@ -514,18 +514,6 @@ String WifiGetAPssid() return Settings.getHostname(); } -// ******************************************************************************** -// Determine hostname: basically WifiGetAPssid with spaces changed to - -// ******************************************************************************** -String WifiGetHostname() -{ - String hostname(WifiGetAPssid()); - - hostname.replace(" ", "-"); - hostname.replace("_", "-"); // See RFC952 - return hostname; -} - bool useStaticIP() { return Settings.IP[0] != 0 && Settings.IP[0] != 255; } diff --git a/src/ESPEasyWifi_ProcessEvent.ino b/src/ESPEasyWifi_ProcessEvent.ino index 3f8e563d5..ee7ff8d55 100644 --- a/src/ESPEasyWifi_ProcessEvent.ino +++ b/src/ESPEasyWifi_ProcessEvent.ino @@ -246,7 +246,7 @@ void processGotIP() { } log += formatIP(ip); log += " ("; - log += WifiGetHostname(); + log += createRFCCompliantHostname(WifiGetAPssid()); log += F(") GW: "); log += formatIP(gw); log += F(" SN: "); diff --git a/src/Networking.ino b/src/Networking.ino index 8284f7a9f..16ee2fc47 100644 --- a/src/Networking.ino +++ b/src/Networking.ino @@ -1002,6 +1002,16 @@ String splitURL(const String& fullURL, String& host, uint16_t& port, String& fil return fullURL.substring(endhost); } +// Create hostname with - instead of spaces +String createRFCCompliantHostname(String oldString) +{ + String result(oldString); + + result.replace(" ", "-"); + result.replace("_", "-"); // See RFC952 + return result; +} + #ifdef USE_SETTINGS_ARCHIVE // Download a file from a given URL and save to a local file named "file_save" From da1039e7f29cf10aae26a246d54457c9eda7fef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Obrembski?= Date: Mon, 13 Apr 2020 15:04:11 +0200 Subject: [PATCH 11/39] Added basic implementation of Ethernet Static IP --- src/ESPEasyEth.ino | 29 ++++++++++++++++++++++++++ src/ESPEasy_checks.ino | 2 +- src/WebServer_ConfigPage.ino | 22 +++++++++++++++++++ src/src/DataStructs/SettingsStruct.cpp | 6 ++++-- src/src/DataStructs/SettingsStruct.h | 4 ++++ 5 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/ESPEasyEth.ino b/src/ESPEasyEth.ino index de595e0d0..9bc430272 100644 --- a/src/ESPEasyEth.ino +++ b/src/ESPEasyEth.ino @@ -3,6 +3,33 @@ #include "ETH.h" +bool ethUseStaticIP() { + return Settings.ETH_IP[0] != 0 && Settings.ETH_IP[3] != 255; +} + +void ethSetupStaticIPconfig() { + //setUseStaticIP(useStaticIP()); + + if (!ethUseStaticIP()) { return; } + const IPAddress ip = Settings.ETH_IP; + const IPAddress gw = Settings.ETH_Gateway; + const IPAddress subnet = Settings.ETH_Subnet; + const IPAddress dns = Settings.ETH_DNS; + + if (loglevelActiveFor(LOG_LEVEL_INFO)) { + String log = F("ETH IP : Static IP : "); + log += formatIP(ip); + log += F(" GW: "); + log += formatIP(gw); + log += F(" SN: "); + log += formatIP(subnet); + log += F(" DNS: "); + log += formatIP(dns); + addLog(LOG_LEVEL_INFO, log); + } + ETH.config(ip, gw, subnet, dns); +} + bool ethCheckSettings() { bool result = true; if (Settings.ETH_Phy_Type != 0 && Settings.ETH_Phy_Type != 1) @@ -25,6 +52,8 @@ bool ethPrepare() { return false; } ETH.setHostname(createRFCCompliantHostname(Settings.getHostname()).c_str()); + ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); + ethSetupStaticIPconfig(); return true; } diff --git a/src/ESPEasy_checks.ino b/src/ESPEasy_checks.ino index 0761d9e61..df01c948b 100644 --- a/src/ESPEasy_checks.ino +++ b/src/ESPEasy_checks.ino @@ -34,7 +34,7 @@ template constexpr size_t offsetOf(U T::*member) void run_compiletime_checks() { check_size(); check_size(); - const unsigned int SettingsStructSize = (256 + 82 * TASKS_MAX); + const unsigned int SettingsStructSize = (272 + 82 * TASKS_MAX); check_size(); check_size(); check_size(); diff --git a/src/WebServer_ConfigPage.ino b/src/WebServer_ConfigPage.ino index 66a380430..471ab92ff 100644 --- a/src/WebServer_ConfigPage.ino +++ b/src/WebServer_ConfigPage.ino @@ -28,6 +28,12 @@ void handle_config() { String espgateway = web_server.arg(F("espgateway")); String espsubnet = web_server.arg(F("espsubnet")); String espdns = web_server.arg(F("espdns")); +#ifdef HAS_ETHERNET + String espethip = web_server.arg(F("espethip")); + String espethgateway = web_server.arg(F("espethgateway")); + String espethsubnet = web_server.arg(F("espethsubnet")); + String espethdns = web_server.arg(F("espethdns")); +#endif Settings.Unit = getFormItemInt(F("unit"), Settings.Unit); // String apkey = web_server.arg(F("apkey")); @@ -96,6 +102,12 @@ void handle_config() { str2ip(espgateway, Settings.Gateway); str2ip(espsubnet, Settings.Subnet); str2ip(espdns, Settings.DNS); +#ifdef HAS_ETHERNET + str2ip(espethip, Settings.ETH_IP); + str2ip(espethgateway, Settings.ETH_Gateway); + str2ip(espethsubnet, Settings.ETH_Subnet); + str2ip(espethdns, Settings.ETH_DNS); +#endif addHtmlError(SaveSettings()); } @@ -145,6 +157,16 @@ void handle_config() { addFormIPBox(F("ESP DNS"), F("espdns"), Settings.DNS); addFormNote(F("Leave empty for DHCP")); +#ifdef HAS_ETHERNET + addFormSubHeader(F("Ethernet IP Settings")); + + addFormIPBox(F("ESP Ethernet IP"), F("espethip"), Settings.ETH_IP); + addFormIPBox(F("ESP Ethernet GW"), F("espethgateway"), Settings.ETH_Gateway); + addFormIPBox(F("ESP Ethernet Subnetmask"), F("espethsubnet"), Settings.ETH_Subnet); + addFormIPBox(F("ESP Ethernet DNS"), F("espethdns"), Settings.ETH_DNS); + addFormNote(F("Leave empty for DHCP")); +#endif + addFormSubHeader(F("Sleep Mode")); diff --git a/src/src/DataStructs/SettingsStruct.cpp b/src/src/DataStructs/SettingsStruct.cpp index 1faf47b15..3358c60e2 100644 --- a/src/src/DataStructs/SettingsStruct.cpp +++ b/src/src/DataStructs/SettingsStruct.cpp @@ -139,6 +139,10 @@ void SettingsStruct_tmpl::clearNetworkSettings() { Gateway[i] = 0; Subnet[i] = 0; DNS[i] = 0; + ETH_IP[i] = 0; + ETH_Gateway[i] = 0; + ETH_Subnet[i] = 0; + ETH_DNS[i] = 0; } } @@ -206,14 +210,12 @@ void SettingsStruct_tmpl::clearMisc() { Pin_i2c_scl = -1; Pin_status_led = -1; Pin_sd_cs = -1; -#ifdef HAS_ETHERNET ETH_Phy_Addr = 0; ETH_Pin_mdc = -1; ETH_Pin_mdio = -1; ETH_Pin_power = -1; ETH_Phy_Type = 0; ETH_Clock_Mode = 0; -#endif for (byte i = 0; i < 17; ++i) { PinBootStates[i] = 0; } BaudRate = 0; diff --git a/src/src/DataStructs/SettingsStruct.h b/src/src/DataStructs/SettingsStruct.h index ae9d27f00..db57944e5 100644 --- a/src/src/DataStructs/SettingsStruct.h +++ b/src/src/DataStructs/SettingsStruct.h @@ -183,6 +183,10 @@ class SettingsStruct_tmpl int8_t ETH_Pin_power; int8_t ETH_Phy_Type; uint8_t ETH_Clock_Mode; + byte ETH_IP[4]; + byte ETH_Gateway[4]; + byte ETH_Subnet[4]; + byte ETH_DNS[4]; }; /* From 1de04294cc9b6cb6fcb8769a0bce507f28523614 Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Fri, 24 Apr 2020 12:32:35 +0200 Subject: [PATCH 12/39] - Atlas EZO new webserver added - Serial --> logging - No [TESTING] --- src/_P214_Atlas_EZO_pH.ino | 895 ++++++++++++++++++------------------ src/_P222_Atlas_EZO_ORP.ino | 726 ++++++++++++++--------------- 2 files changed, 815 insertions(+), 806 deletions(-) diff --git a/src/_P214_Atlas_EZO_pH.ino b/src/_P214_Atlas_EZO_pH.ino index 99f441f5d..ca4896405 100644 --- a/src/_P214_Atlas_EZO_pH.ino +++ b/src/_P214_Atlas_EZO_pH.ino @@ -1,445 +1,450 @@ -//######################################################################## -//################## Plugin 214 : Atlas Scientific EZO Ph sensor ######## -//######################################################################## - -// datasheet at https://www.atlas-scientific.com/_files/_datasheets/_circuit/pH_EZO_datasheet.pdf -// works only in i2c mode - -#define PLUGIN_214 -#define PLUGIN_ID_214 214 -#define PLUGIN_NAME_214 "Environment - Atlas Scientific pH EZO [TESTING]" -#define PLUGIN_VALUENAME1_214 "pH" -#define PLUGIN_VALUENAME2_214 "Voltage" - -boolean Plugin_214_init = false; - -boolean Plugin_214(byte function, struct EventStruct *event, String& string) -{ - boolean success = false; - - switch (function) - { - case PLUGIN_DEVICE_ADD: - { - Device[++deviceCount].Number = PLUGIN_ID_214; - Device[deviceCount].Type = DEVICE_TYPE_I2C; - Device[deviceCount].VType = SENSOR_TYPE_SINGLE; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = true; - Device[deviceCount].ValueCount = 2; - Device[deviceCount].SendDataOption = true; - Device[deviceCount].TimerOption = true; - Device[deviceCount].GlobalSyncOption = true; - break; - } - - case PLUGIN_GET_DEVICENAME: - { - string = F(PLUGIN_NAME_214); - break; - } - - case PLUGIN_GET_DEVICEVALUENAMES: - { - strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_214)); - strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_214)); - break; - } - - case PLUGIN_WEBFORM_LOAD: - { - #define _P214_ATLASEZO_I2C_NB_OPTIONS 4 - byte I2Cchoice = Settings.TaskDevicePluginConfig[event->TaskIndex][0]; - int optionValues[_P214_ATLASEZO_I2C_NB_OPTIONS] = { 0x63, 0x64, 0x65, 0x66 }; - addFormSelectorI2C(F("plugin_214_i2c"), _P214_ATLASEZO_I2C_NB_OPTIONS, optionValues, I2Cchoice); - - addFormSubHeader(F("General")); - - char sensordata[32]; - bool info; - info = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"i",sensordata); - - if (info) { - String boardInfo(sensordata); - - addHtml(F("Board type : ")); - int pos1 = boardInfo.indexOf(','); - int pos2 = boardInfo.lastIndexOf(','); - addHtml(boardInfo.substring(pos1+1,pos2)); - if (boardInfo.substring(pos1+1,pos2) != "pH"){ - addHtml(F(" WARNING : Board type should be 'pH', check your i2c Address ? ")); - } - addHtml(F("Board version :")); - addHtml(boardInfo.substring(pos2+1)); - addHtml(F("")); - - addHtml(F("")); - - } else { - addHtml(F("Unable to send command to device")); - success = false; - break; - } - - addFormCheckBox(F("Status LED"),F("Plugin_214_status_led"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]); - - char statussensordata[32]; - bool status; - status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Status",statussensordata); - - if (status) { - String boardStatus(statussensordata); - - addHtml(F("Board restart code: ")); - int pos1 = boardStatus.indexOf(','); - int pos2 = boardStatus.lastIndexOf(','); - switch ((char)boardStatus.substring(pos1+1,pos2)[0]) - { - case 'P': - { - addHtml(F("powered off")); - break; - } - case 'S': - { - addHtml(F("software reset")); - break; - } - case 'B': - { - addHtml(F("brown out")); - break; - } - case 'W': - { - addHtml(F("watch dog")); - break; - } - case 'U': - default: - { - addHtml(F("unknown")); - break; - } - } - - addHtml(F("Board voltage :")); - addHtml(boardStatus.substring(pos2+1)); - addHtml(F(" V")); - - addHtml(F("")); - - } else { - addHtml(F("Unable to send status command to device")); - success = false; - break; - } - - addFormSubHeader(F("Calibration")); - - int nb_calibration_points = -1; - status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0], "Cal,?",sensordata); - - if (status){ - if (strncmp(sensordata,"?Cal,",5)){ - char tmp[2]; - tmp[0] = sensordata[5]; - tmp[1] = '\0', - nb_calibration_points = atoi(tmp); - } - } - - addRowLabel(F("Middle")); - addFormNumericBox(F("Ref Ph"),F("Plugin_214_ref_cal_M' step='0.01"),Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1],1,14); - if (nb_calibration_points > 0) { - addHtml(F(" OK")); - } else { - addHtml(F(" Not yet calibrated")); - } - addFormCheckBox(F("Enable"),F("Plugin_214_enable_cal_M"), false); - addHtml(F("\n\n")); - - addRowLabel(F("Low")); - addFormNumericBox(F("Ref Ph"),F("Plugin_214_ref_cal_L' step='0.01"), Settings.TaskDevicePluginConfigFloat[event->TaskIndex][2],1,14); - if (nb_calibration_points > 1) { - addHtml(F(" OK")); - } else { - addHtml(F(" Not yet calibrated")); - } - addFormCheckBox(F("Enable"),F("Plugin_214_enable_cal_L"), false); - addHtml(F("\n\n")); - - addHtml(F("High")); - addFormNumericBox(F("Ref Ph"),F("Plugin_214_ref_cal_H' step='0.01"), Settings.TaskDevicePluginConfigFloat[event->TaskIndex][3],1,14); - if (nb_calibration_points > 2) { - addHtml(F(" OK")); - } else { - addHtml(F(" Not yet calibrated")); - } - addFormCheckBox(F("Enable"),F("Plugin_214_enable_cal_H"), false); - addHtml(F("\n\n")); - - if (nb_calibration_points > 1){ - char sensordata[32]; - char cmd[8] = "Slope,?"; - bool status; - status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],cmd,sensordata); - - if (status){ - String slopeAnswer("Answer to 'Slope' command : "); - slopeAnswer += sensordata; - addFormNote(slopeAnswer); - } - } - - addFormSubHeader(F("Temperature compensation")); - char deviceTemperatureTemplate[40]; - LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate)); - addFormTextBox(F("Temperature "), F("Plugin_214_temperature_template"), deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate)); - addFormNote(F("You can use a formulae (and idealy refer to a temp sensor). ")); - float value; - char strValue[5]; - String deviceTemperatureTemplateString(deviceTemperatureTemplate); - String pooltempString(parseTemplate(deviceTemperatureTemplateString, 40)); - addHtml(F("
")); - if (Calculate(pooltempString.c_str(),&value) == CALCULATE_OK ){ - addHtml(F("Actual value : ")); - dtostrf(value,5,2,strValue); - addHtml(strValue); - } else { - addHtml(F("(It seems I can't parse your formulae)")); - } - - addHtml(F("
")); - - success = true; - break; - } - - case PLUGIN_WEBFORM_SAVE: - { - Settings.TaskDevicePluginConfig[event->TaskIndex][0] = getFormItemInt(F("plugin_214_i2c")); - - Settings.TaskDevicePluginConfigFloat[event->TaskIndex][0] = getFormItemFloat(F("plugin_214_sensorVersion")); - - char sensordata[32]; - if (isFormItemChecked(F("Plugin_214_status_led"))) { - _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"L,1",sensordata); - } else { - _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"L,0",sensordata); - } - Settings.TaskDevicePluginConfig[event->TaskIndex][1] = isFormItemChecked(F("Plugin_214_status_led")); - - - Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1] = getFormItemFloat(F("Plugin_214_ref_cal_M")); - Settings.TaskDevicePluginConfigFloat[event->TaskIndex][2] = getFormItemFloat(F("Plugin_214_ref_cal_L")); - Settings.TaskDevicePluginConfigFloat[event->TaskIndex][3] = getFormItemFloat(F("Plugin_214_ref_cal_H")); - - String cmd ("Cal,"); - bool triggerCalibrate = false; - if (isFormItemChecked("Plugin_214_enable_cal_M")) { - cmd += "mid,"; - cmd += Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1]; - triggerCalibrate = true; - } else if (isFormItemChecked("Plugin_214_enable_cal_L")){ - cmd += "low,"; - cmd += Settings.TaskDevicePluginConfigFloat[event->TaskIndex][2]; - triggerCalibrate = true; - } else if (isFormItemChecked("Plugin_214_enable_cal_H")){ - cmd += "high,"; - cmd += Settings.TaskDevicePluginConfigFloat[event->TaskIndex][3]; - triggerCalibrate = true; - } - if (triggerCalibrate){ - char sensordata[32]; - _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],cmd.c_str(),sensordata); - } - - char deviceTemperatureTemplate[40]; - String tmpString = WebServer.arg(F("Plugin_214_temperature_template")); - strncpy(deviceTemperatureTemplate, tmpString.c_str(), sizeof(deviceTemperatureTemplate)-1); - deviceTemperatureTemplate[sizeof(deviceTemperatureTemplate)-1]=0; //be sure that our string ends with a \0 - - SaveCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate)); - - Plugin_214_init = false; - success = true; - break; - } - - case PLUGIN_INIT: - { - Plugin_214_init = true; - } - - case PLUGIN_READ: - { - char sensordata[32]; - bool status; - - //first set the temperature of reading - char deviceTemperatureTemplate[40]; - LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate)); - - String deviceTemperatureTemplateString(deviceTemperatureTemplate); - String pooltempString(parseTemplate(deviceTemperatureTemplateString, 40)); - //String setTemperature("T,"); - String setTemperature("RT,"); - float temperatureReading; - if (Calculate(pooltempString.c_str(),&temperatureReading) == CALCULATE_OK ){ - setTemperature += temperatureReading; - } else { - success = false; - break; - } - - //ok, now we can read the pH value with Temperature compensation - status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],setTemperature.c_str(),sensordata); - - //ok, now we can read the pH value - //status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"r",sensordata); - - //we read the voltagedata char statussensordata[32]; - char voltagedata[32]; - status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Status",voltagedata); - - - if (status){ - String sensorString(sensordata); - String voltage(voltagedata); - int pos = voltage.lastIndexOf(','); - UserVar[event->BaseVarIndex] = sensorString.toFloat(); - UserVar[event->BaseVarIndex + 1] = voltage.substring(pos+1).toFloat(); - } - else { - UserVar[event->BaseVarIndex] = -1; - UserVar[event->BaseVarIndex + 1] = -1; - } - - //go to sleep - //status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Sleep",sensordata); - - success = true; - break; - } - case PLUGIN_WRITE: - { - //TODO : do something more usefull ... - - String tmpString = string; - int argIndex = tmpString.indexOf(','); - if (argIndex) - tmpString = tmpString.substring(0, argIndex); - if (tmpString.equalsIgnoreCase(F("ATLASCMD"))) - { - success = true; - argIndex = string.lastIndexOf(','); - tmpString = string.substring(argIndex + 1); - if (tmpString.equalsIgnoreCase(F("CalMid"))){ - String log("Asking for Mid calibration "); - addLog(LOG_LEVEL_INFO, log); - } - else if (tmpString.equalsIgnoreCase(F("CalLow"))){ - String log("Asking for Low calibration "); - addLog(LOG_LEVEL_INFO, log); - } - else if (tmpString.equalsIgnoreCase(F("CalHigh"))){ - String log("Asking for High calibration "); - addLog(LOG_LEVEL_INFO, log); - } - } - break; - } - } - return success; -} - -// Call this function with two char arrays, one containing the command -// The other containing an allocatted char array for answer -// Returns true on success, false otherwise - -bool _P214_send_I2C_command(uint8_t I2Caddress,const char * cmd, char* sensordata) { - uint16_t sensor_bytes_received = 0; - - byte error; - byte i2c_response_code = 0; - byte in_char = 0; - - Serial.println(cmd); - Wire.beginTransmission(I2Caddress); - Wire.write(cmd); - error = Wire.endTransmission(); - - if (error != 0) { - return false; - } - - //don't read answer if we want to go to sleep - if (strncmp(cmd,"Sleep",5) == 0) { - return true; - } - - i2c_response_code = 254; - while (i2c_response_code == 254) { // in case the cammand takes longer to process, we keep looping here until we get a success or an error - - if ( - ( (cmd[0] == 'r' || cmd[0] == 'R') && cmd[1] == '\0' ) - || - ( ( strncmp(cmd,"cal",3) || strncmp(cmd,"Cal",3) ) && !strncmp(cmd,"Cal,?",5) ) - ) - { - delay(900); - } - else { - delay(300); - } - - Wire.requestFrom(I2Caddress, (uint8_t) 32); //call the circuit and request 32 bytes (this is more then we need). - i2c_response_code = Wire.read(); //read response code - - while (Wire.available()) { //read response - in_char = Wire.read(); - - if (in_char == 0) { //if we receive a null caracter, we're done - while (Wire.available()) { //purge the data line if needed - Wire.read(); - } - - break; //exit the while loop. - } - else { - sensordata[sensor_bytes_received] = in_char; //load this byte into our array. - sensor_bytes_received++; - } - } - sensordata[sensor_bytes_received] = '\0'; - - switch (i2c_response_code) { - case 1: - Serial.print( F("< success, answer = ")); - Serial.println(sensordata); - break; - - case 2: - Serial.println( F("< command failed")); - return false; - - case 254: - Serial.println( F("< command pending")); - break; - - case 255: - Serial.println( F("< no data")); - return false; - } - } - - Serial.println(sensordata); - return true; -} +//######################################################################## +//################## Plugin 214 : Atlas Scientific EZO Ph sensor ######## +//######################################################################## + +// datasheet at https://www.atlas-scientific.com/_files/_datasheets/_circuit/pH_EZO_datasheet.pdf +// works only in i2c mode + +#define PLUGIN_214 +#define PLUGIN_ID_214 214 +#define PLUGIN_NAME_214 "Environment - Atlas Scientific pH EZO [TESTING]" +#define PLUGIN_VALUENAME1_214 "pH" +#define PLUGIN_VALUENAME2_214 "Voltage" + +boolean Plugin_214_init = false; + +boolean Plugin_214(byte function, struct EventStruct *event, String& string) +{ + boolean success = false; + + switch (function) + { + case PLUGIN_DEVICE_ADD: + { + Device[++deviceCount].Number = PLUGIN_ID_214; + Device[deviceCount].Type = DEVICE_TYPE_I2C; + Device[deviceCount].VType = SENSOR_TYPE_SINGLE; + Device[deviceCount].Ports = 0; + Device[deviceCount].PullUpOption = false; + Device[deviceCount].InverseLogicOption = false; + Device[deviceCount].FormulaOption = true; + Device[deviceCount].ValueCount = 2; + Device[deviceCount].SendDataOption = true; + Device[deviceCount].TimerOption = true; + Device[deviceCount].GlobalSyncOption = true; + break; + } + + case PLUGIN_GET_DEVICENAME: + { + string = F(PLUGIN_NAME_214); + break; + } + + case PLUGIN_GET_DEVICEVALUENAMES: + { + strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_214)); + strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_214)); + break; + } + + case PLUGIN_WEBFORM_LOAD: + { + #define _P214_ATLASEZO_I2C_NB_OPTIONS 4 + byte I2Cchoice = Settings.TaskDevicePluginConfig[event->TaskIndex][0]; + int optionValues[_P214_ATLASEZO_I2C_NB_OPTIONS] = { 0x63, 0x64, 0x65, 0x66 }; + addFormSelectorI2C(F("plugin_214_i2c"), _P214_ATLASEZO_I2C_NB_OPTIONS, optionValues, I2Cchoice); + + addFormSubHeader(F("General")); + + char sensordata[32]; + bool info; + info = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"i",sensordata); + + if (info) { + String boardInfo(sensordata); + + addHtml(F("Board type : ")); + int pos1 = boardInfo.indexOf(','); + int pos2 = boardInfo.lastIndexOf(','); + addHtml(boardInfo.substring(pos1+1,pos2)); + if (boardInfo.substring(pos1+1,pos2) != "pH"){ + addHtml(F(" WARNING : Board type should be 'pH', check your i2c Address ? ")); + } + addHtml(F("Board version :")); + addHtml(boardInfo.substring(pos2+1)); + addHtml(F("")); + + addHtml(F("")); + + } else { + addHtml(F("Unable to send command to device")); + success = false; + break; + } + + addFormCheckBox(F("Status LED"),F("Plugin_214_status_led"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]); + + char statussensordata[32]; + bool status; + status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Status",statussensordata); + + if (status) { + String boardStatus(statussensordata); + + addHtml(F("Board restart code: ")); + int pos1 = boardStatus.indexOf(','); + int pos2 = boardStatus.lastIndexOf(','); + switch ((char)boardStatus.substring(pos1+1,pos2)[0]) + { + case 'P': + { + addHtml(F("powered off")); + break; + } + case 'S': + { + addHtml(F("software reset")); + break; + } + case 'B': + { + addHtml(F("brown out")); + break; + } + case 'W': + { + addHtml(F("watch dog")); + break; + } + case 'U': + default: + { + addHtml(F("unknown")); + break; + } + } + + addHtml(F("Board voltage :")); + addHtml(boardStatus.substring(pos2+1)); + addHtml(F(" V")); + + addHtml(F("")); + + } else { + addHtml(F("Unable to send status command to device")); + success = false; + break; + } + + addFormSubHeader(F("Calibration")); + + int nb_calibration_points = -1; + status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0], "Cal,?",sensordata); + + if (status){ + if (strncmp(sensordata,"?Cal,",5)){ + char tmp[2]; + tmp[0] = sensordata[5]; + tmp[1] = '\0', + nb_calibration_points = atoi(tmp); + } + } + + addRowLabel(F("Middle")); + addFormNumericBox(F("Ref Ph"),F("Plugin_214_ref_cal_M' step='0.01"),Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1],1,14); + if (nb_calibration_points > 0) { + addHtml(F(" OK")); + } else { + addHtml(F(" Not yet calibrated")); + } + addFormCheckBox(F("Enable"),F("Plugin_214_enable_cal_M"), false); + addHtml(F("\n\n")); + + addRowLabel(F("Low")); + addFormNumericBox(F("Ref Ph"),F("Plugin_214_ref_cal_L' step='0.01"), Settings.TaskDevicePluginConfigFloat[event->TaskIndex][2],1,14); + if (nb_calibration_points > 1) { + addHtml(F(" OK")); + } else { + addHtml(F(" Not yet calibrated")); + } + addFormCheckBox(F("Enable"),F("Plugin_214_enable_cal_L"), false); + addHtml(F("\n\n")); + + addHtml(F("High")); + addFormNumericBox(F("Ref Ph"),F("Plugin_214_ref_cal_H' step='0.01"), Settings.TaskDevicePluginConfigFloat[event->TaskIndex][3],1,14); + if (nb_calibration_points > 2) { + addHtml(F(" OK")); + } else { + addHtml(F(" Not yet calibrated")); + } + addFormCheckBox(F("Enable"),F("Plugin_214_enable_cal_H"), false); + addHtml(F("\n\n")); + + if (nb_calibration_points > 1){ + char sensordata[32]; + char cmd[8] = "Slope,?"; + bool status; + status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],cmd,sensordata); + + if (status){ + String slopeAnswer("Answer to 'Slope' command : "); + slopeAnswer += sensordata; + addFormNote(slopeAnswer); + } + } + + addFormSubHeader(F("Temperature compensation")); + char deviceTemperatureTemplate[40]; + LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate)); + addFormTextBox(F("Temperature "), F("Plugin_214_temperature_template"), deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate)); + addFormNote(F("You can use a formulae (and idealy refer to a temp sensor). ")); + float value; + char strValue[5]; + String deviceTemperatureTemplateString(deviceTemperatureTemplate); + String pooltempString(parseTemplate(deviceTemperatureTemplateString, 40)); + addHtml(F("
")); + if (Calculate(pooltempString.c_str(),&value) == CALCULATE_OK ){ + addHtml(F("Actual value : ")); + dtostrf(value,5,2,strValue); + addHtml(strValue); + } else { + addHtml(F("(It seems I can't parse your formulae)")); + } + + addHtml(F("
")); + + success = true; + break; + } + + case PLUGIN_WEBFORM_SAVE: + { + Settings.TaskDevicePluginConfig[event->TaskIndex][0] = getFormItemInt(F("plugin_214_i2c")); + + Settings.TaskDevicePluginConfigFloat[event->TaskIndex][0] = getFormItemFloat(F("plugin_214_sensorVersion")); + + char sensordata[32]; + if (isFormItemChecked(F("Plugin_214_status_led"))) { + _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"L,1",sensordata); + } else { + _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"L,0",sensordata); + } + Settings.TaskDevicePluginConfig[event->TaskIndex][1] = isFormItemChecked(F("Plugin_214_status_led")); + + + Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1] = getFormItemFloat(F("Plugin_214_ref_cal_M")); + Settings.TaskDevicePluginConfigFloat[event->TaskIndex][2] = getFormItemFloat(F("Plugin_214_ref_cal_L")); + Settings.TaskDevicePluginConfigFloat[event->TaskIndex][3] = getFormItemFloat(F("Plugin_214_ref_cal_H")); + + String cmd ("Cal,"); + bool triggerCalibrate = false; + if (isFormItemChecked("Plugin_214_enable_cal_M")) { + cmd += "mid,"; + cmd += Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1]; + triggerCalibrate = true; + } else if (isFormItemChecked("Plugin_214_enable_cal_L")){ + cmd += "low,"; + cmd += Settings.TaskDevicePluginConfigFloat[event->TaskIndex][2]; + triggerCalibrate = true; + } else if (isFormItemChecked("Plugin_214_enable_cal_H")){ + cmd += "high,"; + cmd += Settings.TaskDevicePluginConfigFloat[event->TaskIndex][3]; + triggerCalibrate = true; + } + if (triggerCalibrate){ + char sensordata[32]; + _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],cmd.c_str(),sensordata); + } + + char deviceTemperatureTemplate[40]; + String tmpString = web_server.arg(F("Plugin_214_temperature_template")); + strncpy(deviceTemperatureTemplate, tmpString.c_str(), sizeof(deviceTemperatureTemplate)-1); + deviceTemperatureTemplate[sizeof(deviceTemperatureTemplate)-1]=0; //be sure that our string ends with a \0 + + SaveCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate)); + + Plugin_214_init = false; + success = true; + break; + } + + case PLUGIN_INIT: + { + Plugin_214_init = true; + } + + case PLUGIN_READ: + { + char sensordata[32]; + bool status; + + //first set the temperature of reading + char deviceTemperatureTemplate[40]; + LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate)); + + String deviceTemperatureTemplateString(deviceTemperatureTemplate); + String pooltempString(parseTemplate(deviceTemperatureTemplateString, 40)); + //String setTemperature("T,"); + String setTemperature("RT,"); + float temperatureReading; + if (Calculate(pooltempString.c_str(),&temperatureReading) == CALCULATE_OK ){ + setTemperature += temperatureReading; + } else { + success = false; + break; + } + + //ok, now we can read the pH value with Temperature compensation + status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],setTemperature.c_str(),sensordata); + + //ok, now we can read the pH value + //status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"r",sensordata); + + //we read the voltagedata char statussensordata[32]; + char voltagedata[32]; + status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Status",voltagedata); + + + if (status){ + String sensorString(sensordata); + String voltage(voltagedata); + int pos = voltage.lastIndexOf(','); + UserVar[event->BaseVarIndex] = sensorString.toFloat(); + UserVar[event->BaseVarIndex + 1] = voltage.substring(pos+1).toFloat(); + } + else { + UserVar[event->BaseVarIndex] = -1; + UserVar[event->BaseVarIndex + 1] = -1; + } + + //go to sleep + //status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Sleep",sensordata); + + success = true; + break; + } + case PLUGIN_WRITE: + { + //TODO : do something more usefull ... + + String tmpString = string; + int argIndex = tmpString.indexOf(','); + if (argIndex) + tmpString = tmpString.substring(0, argIndex); + if (tmpString.equalsIgnoreCase(F("ATLASCMD"))) + { + success = true; + argIndex = string.lastIndexOf(','); + tmpString = string.substring(argIndex + 1); + if (tmpString.equalsIgnoreCase(F("CalMid"))){ + String log("Asking for Mid calibration "); + addLog(LOG_LEVEL_INFO, log); + } + else if (tmpString.equalsIgnoreCase(F("CalLow"))){ + String log("Asking for Low calibration "); + addLog(LOG_LEVEL_INFO, log); + } + else if (tmpString.equalsIgnoreCase(F("CalHigh"))){ + String log("Asking for High calibration "); + addLog(LOG_LEVEL_INFO, log); + } + } + break; + } + } + return success; +} + +// Call this function with two char arrays, one containing the command +// The other containing an allocatted char array for answer +// Returns true on success, false otherwise + +bool _P214_send_I2C_command(uint8_t I2Caddress,const char * cmd, char* sensordata) { + uint16_t sensor_bytes_received = 0; + + byte error; + byte i2c_response_code = 0; + byte in_char = 0; + + addLog(LOG_LEVEL_DEBUG, String(cmd)); + Wire.beginTransmission(I2Caddress); + Wire.write(cmd); + error = Wire.endTransmission(); + + if (error != 0) { + //addLog(LOG_LEVEL_ERROR, error); + addLog(LOG_LEVEL_ERROR, F("Wire.endTransmission() returns error: Check pH shield")); + return false; + } + + //don't read answer if we want to go to sleep + if (strncmp(cmd,"Sleep",5) == 0) { + return true; + } + + i2c_response_code = 254; + while (i2c_response_code == 254) { // in case the cammand takes longer to process, we keep looping here until we get a success or an error + + if ( + ( (cmd[0] == 'r' || cmd[0] == 'R') && cmd[1] == '\0' ) + || + ( ( strncmp(cmd,"cal",3) || strncmp(cmd,"Cal",3) ) && !strncmp(cmd,"Cal,?",5) ) + ) + { + delay(900); + } + else { + delay(300); + } + + Wire.requestFrom(I2Caddress, (uint8_t) 32); //call the circuit and request 32 bytes (this is more then we need). + i2c_response_code = Wire.read(); //read response code + + while (Wire.available()) { //read response + in_char = Wire.read(); + + if (in_char == 0) { //if we receive a null caracter, we're done + while (Wire.available()) { //purge the data line if needed + Wire.read(); + } + + break; //exit the while loop. + } + else { + sensordata[sensor_bytes_received] = in_char; //load this byte into our array. + sensor_bytes_received++; + } + } + sensordata[sensor_bytes_received] = '\0'; + + switch (i2c_response_code) { + case 1: + { + String log = F("< success, answer = "); + log += sensordata; + addLog(LOG_LEVEL_DEBUG, log); + } + break; + + case 2: + addLog(LOG_LEVEL_DEBUG, F("< command failed")); + return false; + + case 254: + addLog(LOG_LEVEL_DEBUG, F("< command pending")); + break; + + case 255: + addLog(LOG_LEVEL_DEBUG, F("< no data")); + return false; + } + } + + addLog(LOG_LEVEL_DEBUG, sensordata); + return true; +} diff --git a/src/_P222_Atlas_EZO_ORP.ino b/src/_P222_Atlas_EZO_ORP.ino index edec85177..9515283b7 100644 --- a/src/_P222_Atlas_EZO_ORP.ino +++ b/src/_P222_Atlas_EZO_ORP.ino @@ -1,361 +1,365 @@ -//######################################################################## -//################## Plugin 222 : Atlas Scientific EZO ORP sensor ######## -//######################################################################## - -// datasheet at https://www.atlas-scientific.com/_files/_datasheets/_circuit/ORP_EZO_datasheet.pdf -// works only in i2c mode - -#define PLUGIN_222 -#define PLUGIN_ID_222 222 -#define PLUGIN_NAME_222 "Environment - Atlas Scientific ORP EZO [TESTING]" -#define PLUGIN_VALUENAME1_222 "ORP" -#define PLUGIN_VALUENAME2_222 "Voltage" - -boolean Plugin_222_init = false; - -boolean Plugin_222(byte function, struct EventStruct *event, String& string) -{ - boolean success = false; - - switch (function) - { - case PLUGIN_DEVICE_ADD: - { - Device[++deviceCount].Number = PLUGIN_ID_222; - Device[deviceCount].Type = DEVICE_TYPE_I2C; - Device[deviceCount].VType = SENSOR_TYPE_SINGLE; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = true; - Device[deviceCount].ValueCount = 2; - Device[deviceCount].SendDataOption = true; - Device[deviceCount].TimerOption = true; - Device[deviceCount].GlobalSyncOption = true; - break; - } - - case PLUGIN_GET_DEVICENAME: - { - string = F(PLUGIN_NAME_222); - break; - } - - case PLUGIN_GET_DEVICEVALUENAMES: - { - strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_222)); - strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_222)); - break; - } - - case PLUGIN_WEBFORM_LOAD: - { - #define _P222_ATLASEZO_I2C_NB_OPTIONS 4 - byte I2Cchoice = Settings.TaskDevicePluginConfig[event->TaskIndex][0]; - int optionValues[_P222_ATLASEZO_I2C_NB_OPTIONS] = { 0x62, 0x63, 0x64, 0x65 }; - addFormSelectorI2C(F("plugin_222_i2c"), _P222_ATLASEZO_I2C_NB_OPTIONS, optionValues, I2Cchoice); - - addFormSubHeader(F("General")); - - char sensordata[32]; - bool info; - info = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"i",sensordata); - - if (info) { - String boardInfo(sensordata); - - addHtml(F("Board type : ")); - int pos1 = boardInfo.indexOf(','); - int pos2 = boardInfo.lastIndexOf(','); - addHtml(boardInfo.substring(pos1+1,pos2)); - if (boardInfo.substring(pos1+1,pos2) != "ORP"){ - addHtml(F(" WARNING : Board type should be 'ORP', check your i2c Address ? ")); - } - addHtml(F("Board version :")); - addHtml(boardInfo.substring(pos2+1)); - addHtml(F("")); - - addHtml(F("")); - - } else { - addHtml(F("Unable to send command to device")); - success = false; - break; - } - - addFormCheckBox(F("Status LED"),F("Plugin_222_status_led"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]); - - char statussensordata[32]; - bool status; - status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Status",statussensordata); - - if (status) { - String boardStatus(statussensordata); - - addHtml(F("Board restart code: ")); - int pos1 = boardStatus.indexOf(','); - int pos2 = boardStatus.lastIndexOf(','); - switch ((char)boardStatus.substring(pos1+1,pos2)[0]) - { - case 'P': - { - addHtml(F("powered off")); - break; - } - case 'S': - { - addHtml(F("software reset")); - break; - } - case 'B': - { - addHtml(F("brown out")); - break; - } - case 'W': - { - addHtml(F("watch dog")); - break; - } - case 'U': - default: - { - addHtml(F("unknown")); - break; - } - } - - addHtml(F("Board voltage :")); - addHtml(boardStatus.substring(pos2+1)); - addHtml(F(" V")); - - addHtml(F("")); - - } else { - addHtml(F("Unable to send status command to device")); - success = false; - break; - } - - addFormSubHeader(F("Calibration")); - - int nb_calibration_points = -1; - status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0], "Cal,?",sensordata); - - if (status){ - if (strncmp(sensordata,"?Cal,",5)){ - char tmp[2]; - tmp[0] = sensordata[5]; - tmp[1] = '\0', - nb_calibration_points = atoi(tmp); - } - } - - addRowLabel(F("ORP Calibration")); - addFormNumericBox(F("Ref ORP"),F("Plugin_222_ref_cal_M' step='1"),Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1],0,1500); - if (nb_calibration_points > 0) { - addHtml(F(" OK")); - } else { - addHtml(F(" Not yet calibrated")); - } - addFormCheckBox(F("Enable"),F("Plugin_222_enable_cal_M"), false); - - if (nb_calibration_points > 1){ - char sensordata[32]; - char cmd[8] = "Slope,?"; - bool status; - status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],cmd,sensordata); - - if (status){ - String slopeAnswer("Answer to 'Slope' command : "); - slopeAnswer += sensordata; - addFormNote(slopeAnswer); - } - } - - addHtml(F("")); - - success = true; - break; - } - - case PLUGIN_WEBFORM_SAVE: - { - Settings.TaskDevicePluginConfig[event->TaskIndex][0] = getFormItemInt(F("plugin_222_i2c")); - - Settings.TaskDevicePluginConfigFloat[event->TaskIndex][0] = getFormItemFloat(F("plugin_222_sensorVersion")); - - char sensordata[32]; - if (isFormItemChecked(F("Plugin_222_status_led"))) { - _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"L,1",sensordata); - } else { - _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"L,0",sensordata); - } - Settings.TaskDevicePluginConfig[event->TaskIndex][1] = isFormItemChecked(F("Plugin_222_status_led")); - - - Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1] = getFormItemFloat(F("Plugin_222_ref_cal_M")); - - String cmd ("Cal,"); - bool triggerCalibrate = false; - if (isFormItemChecked("Plugin_222_enable_cal_M")) { - cmd += Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1]; - triggerCalibrate = true; - } - if (triggerCalibrate){ - char sensordata[32]; - _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],cmd.c_str(),sensordata); - } - - Plugin_222_init = false; - success = true; - break; - } - - case PLUGIN_INIT: - { - Plugin_222_init = true; - } - - case PLUGIN_READ: - { - char sensordata[32]; - bool status; - - //ok, now we can read the ORP value - status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"R",sensordata); - - //we read the voltagedata char statussensordata[32]; - char voltagedata[32]; - status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Status",voltagedata); - - if (status){ - String sensorString(sensordata); - String voltage(voltagedata); - int pos = voltage.lastIndexOf(','); - UserVar[event->BaseVarIndex] = sensorString.toFloat(); - UserVar[event->BaseVarIndex + 1] = voltage.substring(pos+1).toFloat(); - } - else { - UserVar[event->BaseVarIndex] = -1; - UserVar[event->BaseVarIndex + 1] = -1; - } - - //go to sleep - //status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Sleep",sensordata); - - success = true; - break; - } - case PLUGIN_WRITE: - { - //TODO : do something more usefull ... - - String tmpString = string; - int argIndex = tmpString.indexOf(','); - if (argIndex) - tmpString = tmpString.substring(0, argIndex); - if (tmpString.equalsIgnoreCase(F("ATLASCMD"))) - { - success = true; - argIndex = string.lastIndexOf(','); - tmpString = string.substring(argIndex + 1); - if (tmpString.equalsIgnoreCase(F("CalMid"))){ - String log("Asking for calibration "); - addLog(LOG_LEVEL_INFO, log); - } - } - break; - } - } - return success; -} - -// Call this function with two char arrays, one containing the command -// The other containing an allocatted char array for answer -// Returns true on success, false otherwise - -bool _P222_send_I2C_command(uint8_t I2Caddress,const char * cmd, char* sensordata) { - uint16_t sensor_bytes_received = 0; - - byte error; - byte i2c_response_code = 0; - byte in_char = 0; - - Serial.println(cmd); - Wire.beginTransmission(I2Caddress); - Wire.write(cmd); - error = Wire.endTransmission(); - - if (error != 0) { - Serial.println(error); - return false; - } - - //don't read answer if we want to go to sleep - if (strncmp(cmd,"Sleep",5) == 0) { - return true; - } - - i2c_response_code = 254; - while (i2c_response_code == 254) { // in case the cammand takes longer to process, we keep looping here until we get a success or an error - - if ( - ( (cmd[0] == 'r' || cmd[0] == 'R') && cmd[1] == '\0' ) - || - ( ( strncmp(cmd,"cal",3) || strncmp(cmd,"Cal",3) ) && !strncmp(cmd,"Cal,?",5) ) - ) - { - delay(900); - } - else { - delay(300); - } - - Wire.requestFrom(I2Caddress, (uint8_t) 32); //call the circuit and request 32 bytes (this is more then we need). - i2c_response_code = Wire.read(); //read response code - - while (Wire.available()) { //read response - in_char = Wire.read(); - - if (in_char == 0) { //if we receive a null caracter, we're done - while (Wire.available()) { //purge the data line if needed - Wire.read(); - } - - break; //exit the while loop. - } - else { - sensordata[sensor_bytes_received] = in_char; //load this byte into our array. - sensor_bytes_received++; - } - } - sensordata[sensor_bytes_received] = '\0'; - - switch (i2c_response_code) { - case 1: - Serial.print( F("< success, answer = ")); - Serial.println(sensordata); - break; - - case 2: - Serial.println( F("< command failed")); - return false; - - case 254: - Serial.println( F("< command pending")); - break; - - case 255: - Serial.println( F("< no data")); - return false; - } - } - - Serial.println(sensordata); - return true; -} +//######################################################################## +//################## Plugin 222 : Atlas Scientific EZO ORP sensor ######## +//######################################################################## + +// datasheet at https://www.atlas-scientific.com/_files/_datasheets/_circuit/ORP_EZO_datasheet.pdf +// works only in i2c mode + +#define PLUGIN_222 +#define PLUGIN_ID_222 222 +#define PLUGIN_NAME_222 "Environment - Atlas Scientific ORP EZO" +#define PLUGIN_VALUENAME1_222 "ORP" +#define PLUGIN_VALUENAME2_222 "Voltage" + +boolean Plugin_222_init = false; + +boolean Plugin_222(byte function, struct EventStruct *event, String& string) +{ + boolean success = false; + + switch (function) + { + case PLUGIN_DEVICE_ADD: + { + Device[++deviceCount].Number = PLUGIN_ID_222; + Device[deviceCount].Type = DEVICE_TYPE_I2C; + Device[deviceCount].VType = SENSOR_TYPE_SINGLE; + Device[deviceCount].Ports = 0; + Device[deviceCount].PullUpOption = false; + Device[deviceCount].InverseLogicOption = false; + Device[deviceCount].FormulaOption = true; + Device[deviceCount].ValueCount = 2; + Device[deviceCount].SendDataOption = true; + Device[deviceCount].TimerOption = true; + Device[deviceCount].GlobalSyncOption = true; + break; + } + + case PLUGIN_GET_DEVICENAME: + { + string = F(PLUGIN_NAME_222); + break; + } + + case PLUGIN_GET_DEVICEVALUENAMES: + { + strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_222)); + strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_222)); + break; + } + + case PLUGIN_WEBFORM_LOAD: + { + #define _P222_ATLASEZO_I2C_NB_OPTIONS 4 + byte I2Cchoice = Settings.TaskDevicePluginConfig[event->TaskIndex][0]; + int optionValues[_P222_ATLASEZO_I2C_NB_OPTIONS] = { 0x62, 0x63, 0x64, 0x65 }; + addFormSelectorI2C(F("plugin_222_i2c"), _P222_ATLASEZO_I2C_NB_OPTIONS, optionValues, I2Cchoice); + + addFormSubHeader(F("General")); + + char sensordata[32]; + bool info; + info = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"i",sensordata); + + if (info) { + String boardInfo(sensordata); + + addHtml(F("Board type : ")); + int pos1 = boardInfo.indexOf(','); + int pos2 = boardInfo.lastIndexOf(','); + addHtml(boardInfo.substring(pos1+1,pos2)); + if (boardInfo.substring(pos1+1,pos2) != "ORP"){ + addHtml(F(" WARNING : Board type should be 'ORP', check your i2c Address ? ")); + } + addHtml(F("Board version :")); + addHtml(boardInfo.substring(pos2+1)); + addHtml(F("")); + + addHtml(F("")); + + } else { + addHtml(F("Unable to send command to device")); + success = false; + break; + } + + addFormCheckBox(F("Status LED"),F("Plugin_222_status_led"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]); + + char statussensordata[32]; + bool status; + status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Status",statussensordata); + + if (status) { + String boardStatus(statussensordata); + + addHtml(F("Board restart code: ")); + int pos1 = boardStatus.indexOf(','); + int pos2 = boardStatus.lastIndexOf(','); + switch ((char)boardStatus.substring(pos1+1,pos2)[0]) + { + case 'P': + { + addHtml(F("powered off")); + break; + } + case 'S': + { + addHtml(F("software reset")); + break; + } + case 'B': + { + addHtml(F("brown out")); + break; + } + case 'W': + { + addHtml(F("watch dog")); + break; + } + case 'U': + default: + { + addHtml(F("unknown")); + break; + } + } + + addHtml(F("Board voltage :")); + addHtml(boardStatus.substring(pos2+1)); + addHtml(F(" V")); + + addHtml(F("")); + + } else { + addHtml(F("Unable to send status command to device")); + success = false; + break; + } + + addFormSubHeader(F("Calibration")); + + int nb_calibration_points = -1; + status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0], "Cal,?",sensordata); + + if (status){ + if (strncmp(sensordata,"?Cal,",5)){ + char tmp[2]; + tmp[0] = sensordata[5]; + tmp[1] = '\0', + nb_calibration_points = atoi(tmp); + } + } + + addRowLabel(F("ORP Calibration")); + addFormNumericBox(F("Ref ORP"),F("Plugin_222_ref_cal_M' step='1"),Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1],0,1500); + if (nb_calibration_points > 0) { + addHtml(F(" OK")); + } else { + addHtml(F(" Not yet calibrated")); + } + addFormCheckBox(F("Enable"),F("Plugin_222_enable_cal_M"), false); + + if (nb_calibration_points > 1){ + char sensordata[32]; + char cmd[8] = "Slope,?"; + bool status; + status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],cmd,sensordata); + + if (status){ + String slopeAnswer("Answer to 'Slope' command : "); + slopeAnswer += sensordata; + addFormNote(slopeAnswer); + } + } + + addHtml(F("")); + + success = true; + break; + } + + case PLUGIN_WEBFORM_SAVE: + { + Settings.TaskDevicePluginConfig[event->TaskIndex][0] = getFormItemInt(F("plugin_222_i2c")); + + Settings.TaskDevicePluginConfigFloat[event->TaskIndex][0] = getFormItemFloat(F("plugin_222_sensorVersion")); + + char sensordata[32]; + if (isFormItemChecked(F("Plugin_222_status_led"))) { + _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"L,1",sensordata); + } else { + _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"L,0",sensordata); + } + Settings.TaskDevicePluginConfig[event->TaskIndex][1] = isFormItemChecked(F("Plugin_222_status_led")); + + + Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1] = getFormItemFloat(F("Plugin_222_ref_cal_M")); + + String cmd ("Cal,"); + bool triggerCalibrate = false; + if (isFormItemChecked("Plugin_222_enable_cal_M")) { + cmd += Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1]; + triggerCalibrate = true; + } + if (triggerCalibrate){ + char sensordata[32]; + _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],cmd.c_str(),sensordata); + } + + Plugin_222_init = false; + success = true; + break; + } + + case PLUGIN_INIT: + { + Plugin_222_init = true; + } + + case PLUGIN_READ: + { + char sensordata[32]; + bool status; + + //ok, now we can read the ORP value + status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"R",sensordata); + + //we read the voltagedata char statussensordata[32]; + char voltagedata[32]; + status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Status",voltagedata); + + if (status){ + String sensorString(sensordata); + String voltage(voltagedata); + int pos = voltage.lastIndexOf(','); + UserVar[event->BaseVarIndex] = sensorString.toFloat(); + UserVar[event->BaseVarIndex + 1] = voltage.substring(pos+1).toFloat(); + } + else { + UserVar[event->BaseVarIndex] = -1; + UserVar[event->BaseVarIndex + 1] = -1; + } + + //go to sleep + //status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Sleep",sensordata); + + success = true; + break; + } + case PLUGIN_WRITE: + { + //TODO : do something more usefull ... + + String tmpString = string; + int argIndex = tmpString.indexOf(','); + if (argIndex) + tmpString = tmpString.substring(0, argIndex); + if (tmpString.equalsIgnoreCase(F("ATLASCMD"))) + { + success = true; + argIndex = string.lastIndexOf(','); + tmpString = string.substring(argIndex + 1); + if (tmpString.equalsIgnoreCase(F("CalMid"))){ + String log("Asking for calibration "); + addLog(LOG_LEVEL_INFO, log); + } + } + break; + } + } + return success; +} + +// Call this function with two char arrays, one containing the command +// The other containing an allocatted char array for answer +// Returns true on success, false otherwise + +bool _P222_send_I2C_command(uint8_t I2Caddress,const char * cmd, char* sensordata) { + uint16_t sensor_bytes_received = 0; + + byte error; + byte i2c_response_code = 0; + byte in_char = 0; + + addLog(LOG_LEVEL_DEBUG, String(cmd)); + Wire.beginTransmission(I2Caddress); + Wire.write(cmd); + error = Wire.endTransmission(); + + if (error != 0) { + //addLog(LOG_LEVEL_ERROR, error); + addLog(LOG_LEVEL_ERROR, F("Wire.endTransmission() returns error: Check ORP shield")); + return false; + } + + //don't read answer if we want to go to sleep + if (strncmp(cmd,"Sleep",5) == 0) { + return true; + } + + i2c_response_code = 254; + while (i2c_response_code == 254) { // in case the cammand takes longer to process, we keep looping here until we get a success or an error + + if ( + ( (cmd[0] == 'r' || cmd[0] == 'R') && cmd[1] == '\0' ) + || + ( ( strncmp(cmd,"cal",3) || strncmp(cmd,"Cal",3) ) && !strncmp(cmd,"Cal,?",5) ) + ) + { + delay(900); + } + else { + delay(300); + } + + Wire.requestFrom(I2Caddress, (uint8_t) 32); //call the circuit and request 32 bytes (this is more then we need). + i2c_response_code = Wire.read(); //read response code + + while (Wire.available()) { //read response + in_char = Wire.read(); + + if (in_char == 0) { //if we receive a null caracter, we're done + while (Wire.available()) { //purge the data line if needed + Wire.read(); + } + + break; //exit the while loop. + } + else { + sensordata[sensor_bytes_received] = in_char; //load this byte into our array. + sensor_bytes_received++; + } + } + sensordata[sensor_bytes_received] = '\0'; + + switch (i2c_response_code) { + case 1: + { + String log = F("< success, answer = "); + log += sensordata; + addLog(LOG_LEVEL_DEBUG, log); + } + break; + + case 2: + addLog(LOG_LEVEL_DEBUG, F("< command failed")); + return false; + + case 254: + addLog(LOG_LEVEL_DEBUG, F("< command pending")); + break; + + case 255: + addLog(LOG_LEVEL_DEBUG, F("< no data")); + return false; + } + } + + addLog(LOG_LEVEL_DEBUG, sensordata); + return true; +} From cba9b600973c7fde457a2c90817113e292a6f650 Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Fri, 24 Apr 2020 13:16:54 +0200 Subject: [PATCH 13/39] =?UTF-8?q?Extended=20the=20great=20work=20from=20Mi?= =?UTF-8?q?cha=C5=82=20Obrembski=20mobrembski,=20so=20that:=20-=20mqtt=20w?= =?UTF-8?q?orks=20-=20WifiConnected=20works=20as=20EthernetConnected?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformio_esp32_envs.ini | 29 ++++++++++++++++++++- src/ESPEasy.ino | 53 ++++++++++++++++++++++++++++++++++++++- src/ESPEasyWifi.ino | 4 +++ 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/platformio_esp32_envs.ini b/platformio_esp32_envs.ini index fff572e5e..2057567ed 100644 --- a/platformio_esp32_envs.ini +++ b/platformio_esp32_envs.ini @@ -29,7 +29,7 @@ build_flags = ${mqtt_flags.build_flags} [env:custom_ESP32_4M316k] extends = esp32_common platform = ${esp32_common.platform} -build_flags = ${esp32_common.build_flags} -DPLUGIN_BUILD_CUSTOM -DHAS_ETHERNET +build_flags = ${esp32_common.build_flags} -DPLUGIN_BUILD_CUSTOM board = esp32dev extra_scripts = ${esp32_common.extra_scripts} pre:pre_custom_esp32.py @@ -52,4 +52,31 @@ debug_tool = ftdi debug_extra_cmds = break Misc.ino:3011 extra_scripts = ${esp32_common.extra_scripts} +; Custom: 4096k version -------------------------- +[env:custom_ESP32_4M316k_ETH] +extends = esp32_common +platform = ${esp32_common.platform} +build_flags = ${esp32_common.build_flags} -DPLUGIN_BUILD_CUSTOM -DHAS_ETHERNET +board = esp32dev +extra_scripts = ${esp32_common.extra_scripts} + pre:pre_custom_esp32.py + +[env:test_ESP32_4M316k_ETH] +extends = esp32_common +platform = ${esp32_common.platform} +build_flags = ${esp32_common.build_flags} -DPLUGIN_SET_TEST_ESP32 -DHAS_ETHERNET +board = esp32dev +extra_scripts = ${esp32_common.extra_scripts} + + +[env:test_ESP32-wrover-kit_4M316k_ETH] +extends = esp32_common +platform = ${esp32_common.platform} +build_flags = ${esp32_common.build_flags} -DPLUGIN_SET_TEST_ESP32 -DHAS_ETHERNET +board = esp-wrover-kit +upload_protocol = ftdi +debug_tool = ftdi +debug_extra_cmds = break Misc.ino:3011 +extra_scripts = ${esp32_common.extra_scripts} + diff --git a/src/ESPEasy.ino b/src/ESPEasy.ino index 20df7794a..9c30d3b0a 100644 --- a/src/ESPEasy.ino +++ b/src/ESPEasy.ino @@ -1,6 +1,11 @@ #include +#ifdef HAS_ETHERNET +#include +static bool eth_connected = false; +#endif + #ifdef CONTINUOUS_INTEGRATION #pragma GCC diagnostic error "-Wall" #else @@ -369,9 +374,11 @@ void setup() rulesProcessing(event); // TD-er: Process events in the setup() now. } - WiFiConnectRelaxed(); #ifdef HAS_ETHERNET + WiFi.onEvent(ETHEvent); ETHConnectRelaxed(); +#else + WiFiConnectRelaxed(); #endif setWebserverRunning(true); @@ -550,7 +557,9 @@ void loop() updateLoopStats(); + #ifndef HAS_ETHERNET handle_unprocessedWiFiEvents(); + #endif bool firstLoopConnectionsEstablished = WiFiConnected() && firstLoop; if (firstLoopConnectionsEstablished) { @@ -1012,3 +1021,45 @@ void backgroundtasks() runningBackgroundTasks=false; STOP_TIMER(BACKGROUND_TASKS); } + +#ifdef HAS_ETHERNET +void ETHEvent(WiFiEvent_t event) +{ + switch (event) { + case SYSTEM_EVENT_ETH_START: + addLog(LOG_LEVEL_INFO, F("ETH Started")); + //set eth hostname here + //ETH.setHostname("esp32-ethernet"); + break; + case SYSTEM_EVENT_ETH_CONNECTED: + addLog(LOG_LEVEL_INFO, F("ETH Connected")); + break; + case SYSTEM_EVENT_ETH_GOT_IP: + { + String log = F("ETH MAC: "); + log += ETH.macAddress(); + log += F(", IPv4: "); + log += ETH.localIP().toString(); + if (ETH.fullDuplex()) { + log += F(", FULL_DUPLEX"); + } + log += F(", "); + log += ETH.linkSpeed(); + log += F("Mbps"); + addLog(LOG_LEVEL_INFO, log); + } + eth_connected = true; + break; + case SYSTEM_EVENT_ETH_DISCONNECTED: + addLog(LOG_LEVEL_ERROR, F("ETH Disconnected")); + eth_connected = false; + break; + case SYSTEM_EVENT_ETH_STOP: + addLog(LOG_LEVEL_INFO, F("ETH Stopped")); + eth_connected = false; + break; + default: + break; + } +} +#endif \ No newline at end of file diff --git a/src/ESPEasyWifi.ino b/src/ESPEasyWifi.ino index 4d6f56538..51898ea60 100644 --- a/src/ESPEasyWifi.ino +++ b/src/ESPEasyWifi.ino @@ -75,6 +75,10 @@ bool WiFiConnected() { START_TIMER; + #ifdef HAS_ETHERNET + return eth_connected; + #endif + if (unprocessedWifiEvents()) { return false; } if ((timerAPstart != 0) && timeOutReached(timerAPstart)) { From 32dfba3d86e5801b5fef86f28ae5165d622dbb8b Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Sat, 25 Apr 2020 00:52:33 +0200 Subject: [PATCH 14/39] - Moved ETHEvent from ESPEasy.ino to ESPEasyEthEvent.ino - Corrected Hostname Setting - ESPEasy P2P works now with some minor changes for IP-Address Handling in Network.ino --- src/ESPEasy.ino | 44 +------------------------------------- src/ESPEasyEth.ino | 1 - src/ESPEasyEthEvent.ino | 47 +++++++++++++++++++++++++++++++++++++++++ src/ESPEasyWifi.ino | 7 +++--- src/Networking.ino | 16 +++++++++++++- 5 files changed, 67 insertions(+), 48 deletions(-) create mode 100644 src/ESPEasyEthEvent.ino diff --git a/src/ESPEasy.ino b/src/ESPEasy.ino index 9c30d3b0a..b638224a9 100644 --- a/src/ESPEasy.ino +++ b/src/ESPEasy.ino @@ -1020,46 +1020,4 @@ void backgroundtasks() runningBackgroundTasks=false; STOP_TIMER(BACKGROUND_TASKS); -} - -#ifdef HAS_ETHERNET -void ETHEvent(WiFiEvent_t event) -{ - switch (event) { - case SYSTEM_EVENT_ETH_START: - addLog(LOG_LEVEL_INFO, F("ETH Started")); - //set eth hostname here - //ETH.setHostname("esp32-ethernet"); - break; - case SYSTEM_EVENT_ETH_CONNECTED: - addLog(LOG_LEVEL_INFO, F("ETH Connected")); - break; - case SYSTEM_EVENT_ETH_GOT_IP: - { - String log = F("ETH MAC: "); - log += ETH.macAddress(); - log += F(", IPv4: "); - log += ETH.localIP().toString(); - if (ETH.fullDuplex()) { - log += F(", FULL_DUPLEX"); - } - log += F(", "); - log += ETH.linkSpeed(); - log += F("Mbps"); - addLog(LOG_LEVEL_INFO, log); - } - eth_connected = true; - break; - case SYSTEM_EVENT_ETH_DISCONNECTED: - addLog(LOG_LEVEL_ERROR, F("ETH Disconnected")); - eth_connected = false; - break; - case SYSTEM_EVENT_ETH_STOP: - addLog(LOG_LEVEL_INFO, F("ETH Stopped")); - eth_connected = false; - break; - default: - break; - } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/ESPEasyEth.ino b/src/ESPEasyEth.ino index 9bc430272..26609fbac 100644 --- a/src/ESPEasyEth.ino +++ b/src/ESPEasyEth.ino @@ -51,7 +51,6 @@ bool ethPrepare() { addLog(LOG_LEVEL_ERROR, F("ETH: Settings not correct!!!")); return false; } - ETH.setHostname(createRFCCompliantHostname(Settings.getHostname()).c_str()); ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); ethSetupStaticIPconfig(); return true; diff --git a/src/ESPEasyEthEvent.ino b/src/ESPEasyEthEvent.ino new file mode 100644 index 000000000..8f7e35d8a --- /dev/null +++ b/src/ESPEasyEthEvent.ino @@ -0,0 +1,47 @@ +#ifdef HAS_ETHERNET +void ETHEvent(WiFiEvent_t event) +{ + switch (event) { + case SYSTEM_EVENT_ETH_START: + addLog(LOG_LEVEL_INFO, F("ETH Started")); + char hostname[40]; + safe_strncpy(hostname, createRFCCompliantHostname(WifiGetAPssid()).c_str(), sizeof(hostname)); + ETH.setHostname(hostname); + { + String log = F("ETH Hostname: "); + log += String(hostname); + addLog(LOG_LEVEL_INFO, log); + } + break; + case SYSTEM_EVENT_ETH_CONNECTED: + addLog(LOG_LEVEL_INFO, F("ETH Connected")); + break; + case SYSTEM_EVENT_ETH_GOT_IP: + { + String log = F("ETH MAC: "); + log += ETH.macAddress(); + log += F(", IPv4: "); + log += ETH.localIP().toString(); + if (ETH.fullDuplex()) { + log += F(", FULL_DUPLEX"); + } + log += F(", "); + log += ETH.linkSpeed(); + log += F("Mbps"); + addLog(LOG_LEVEL_INFO, log); + } + eth_connected = true; + break; + case SYSTEM_EVENT_ETH_DISCONNECTED: + addLog(LOG_LEVEL_ERROR, F("ETH Disconnected")); + eth_connected = false; + break; + case SYSTEM_EVENT_ETH_STOP: + addLog(LOG_LEVEL_INFO, F("ETH Stopped")); + eth_connected = false; + break; + default: + break; + } +} +#endif \ No newline at end of file diff --git a/src/ESPEasyWifi.ino b/src/ESPEasyWifi.ino index 51898ea60..9c0b5af35 100644 --- a/src/ESPEasyWifi.ino +++ b/src/ESPEasyWifi.ino @@ -73,11 +73,11 @@ // - Start/stop of AP mode // ******************************************************************************** bool WiFiConnected() { - START_TIMER; - #ifdef HAS_ETHERNET return eth_connected; - #endif + #else + + START_TIMER; if (unprocessedWifiEvents()) { return false; } @@ -133,6 +133,7 @@ bool WiFiConnected() { delay(1); STOP_TIMER(WIFI_NOTCONNECTED_STATS); return false; + #endif // HAS_ETHERNET } void WiFiConnectRelaxed() { diff --git a/src/Networking.ino b/src/Networking.ino index 16ee2fc47..593289c80 100644 --- a/src/Networking.ino +++ b/src/Networking.ino @@ -354,7 +354,11 @@ void sendSysInfoUDP(byte repeats) for (byte x = 0; x < 6; x++) { data[x + 2] = macread[x]; } + #ifdef HAS_ETHERNET + IPAddress ip = ETH.localIP(); + #else IPAddress ip = WiFi.localIP(); + #endif for (byte x = 0; x < 4; x++) { data[x + 8] = ip[x]; @@ -382,7 +386,11 @@ void sendSysInfoUDP(byte repeats) if (it != Nodes.end()) { + #ifdef HAS_ETHERNET + IPAddress ip = ETH.localIP(); + #else IPAddress ip = WiFi.localIP(); + #endif for (byte x = 0; x < 4; x++) { it->second.ip[x] = ip[x]; @@ -752,8 +760,14 @@ bool getSubnetRange(IPAddress& low, IPAddress& high) if (wifiStatus < ESPEASY_WIFI_GOT_IP) { return false; } - const IPAddress ip = WiFi.localIP(); + #ifdef HAS_ETHERNET + const IPAddress ip = ETH.localIP(); + const IPAddress subnet = ETH.subnetMask(); + #else + const IPAddress ip = WiFi.localIP(); const IPAddress subnet = WiFi.subnetMask(); + #endif + low = ip; high = ip; From 64a4bbcb8ada793155adc93d7553b307b0814e57 Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Sat, 25 Apr 2020 11:17:11 +0200 Subject: [PATCH 15/39] Change requested by TD-er review: clarification of build file https://github.com/letscontrolit/ESPEasy/pull/2962/files/8ba2bb88eadb98c4691cbb1f40c4d5466cb7b5b8 --- platformio_esp32_envs.ini | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/platformio_esp32_envs.ini b/platformio_esp32_envs.ini index 2057567ed..a78e11641 100644 --- a/platformio_esp32_envs.ini +++ b/platformio_esp32_envs.ini @@ -54,29 +54,19 @@ extra_scripts = ${esp32_common.extra_scripts} ; Custom: 4096k version -------------------------- [env:custom_ESP32_4M316k_ETH] -extends = esp32_common -platform = ${esp32_common.platform} -build_flags = ${esp32_common.build_flags} -DPLUGIN_BUILD_CUSTOM -DHAS_ETHERNET -board = esp32dev -extra_scripts = ${esp32_common.extra_scripts} - pre:pre_custom_esp32.py +extends = env:custom_ESP32_4M316k +platform = ${env:custom_ESP32_4M316k.platform} +build_flags = ${env:custom_ESP32_4M316k.build_flags} -DHAS_ETHERNET [env:test_ESP32_4M316k_ETH] -extends = esp32_common -platform = ${esp32_common.platform} -build_flags = ${esp32_common.build_flags} -DPLUGIN_SET_TEST_ESP32 -DHAS_ETHERNET -board = esp32dev -extra_scripts = ${esp32_common.extra_scripts} +extends = env:test_ESP32_4M316k +platform = ${env:test_ESP32_4M316k.platform} +build_flags = ${env:test_ESP32_4M316k.build_flags} -DHAS_ETHERNET [env:test_ESP32-wrover-kit_4M316k_ETH] -extends = esp32_common -platform = ${esp32_common.platform} -build_flags = ${esp32_common.build_flags} -DPLUGIN_SET_TEST_ESP32 -DHAS_ETHERNET -board = esp-wrover-kit -upload_protocol = ftdi -debug_tool = ftdi -debug_extra_cmds = break Misc.ino:3011 -extra_scripts = ${esp32_common.extra_scripts} +extends = env:test_ESP32-wrover-kit_4M316k +platform = ${env:test_ESP32-wrover-kit_4M316k.platform} +build_flags = ${env:test_ESP32-wrover-kit_4M316k.build_flags} -DHAS_ETHERNET From 6632dec482e8266e9cc5c4e9d8ffc5ba622f637d Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Sun, 26 Apr 2020 22:29:56 +0200 Subject: [PATCH 16/39] ESP32 with Ethernet or Wifi, not both at the same time configurable via Hardware Page. - ESP P2P is working - Only ETH.beginPacket() with Standard Parameter is working at the moment, configuration will follow. - Network.in not cpp/h files but this will be changed in future - Some TODO: PKR: comments will be removed in the future, too --- platformio_esp32_envs.ini | 3 +- src/Controller.ino | 2 +- src/ESPEasy-Globals.cpp | 9 ++ src/ESPEasy-Globals.h | 7 + src/ESPEasy.ino | 52 ++++--- src/ESPEasyEth.ino | 49 +++++- src/ESPEasyEthEvent.ino | 3 + src/ESPEasyEthWifi.h | 14 ++ src/ESPEasyEth_ProcessEvent.ino | 6 +- src/ESPEasyStorage.ino | 1 + src/ESPEasyWiFiEvent.cpp | 18 +-- src/ESPEasyWifi.ino | 5 - src/ESPEasyWifi_ProcessEvent.ino | 10 +- src/ESPEasy_checks.ino | 2 +- src/ESPEasy_fdwdecl.h | 19 ++- src/Misc.ino | 5 +- src/Network.ino | 145 ++++++++++++++++++ src/Networking.ino | 53 +++---- src/StringProvider.ino | 15 +- src/StringProviderTypes.h | 1 + src/WebServer_HardwarePage.ino | 7 +- src/WebServer_RootPage.ino | 13 +- src/WebServer_SetupPage.ino | 4 +- src/WebServer_SysInfoPage.ino | 37 +++-- src/WebServer_SysVarPage.ino | 4 + src/WebServer_ToolsPage.ino | 1 + src/_C006.ino | 2 +- src/_C009.ino | 4 +- src/_C011.ino | 2 +- src/_C012.ino | 2 +- src/_C013.ino | 6 +- src/_C014.ino | 3 +- src/_C015.ino | 4 +- src/_C017.ino | 2 +- src/_CPlugin_Helper.cpp | 4 +- src/_P026_Sysinfo.ino | 8 +- src/_P036_FrameOLED.ino | 6 +- src/_P037_MQTTImport.ino | 2 +- src/_P089_Ping.ino | 2 +- src/src/Commands/HTTP.cpp | 2 +- src/src/Commands/UDP.cpp | 2 +- .../ControllerDelayHandlerStruct.h | 2 +- .../DataStructs/ControllerSettingsStruct.cpp | 4 +- src/src/DataStructs/ESPEasyDefaults.h | 7 +- src/src/DataStructs/SettingsStruct.cpp | 1 + src/src/DataStructs/SettingsStruct.h | 1 + src/src/Helpers/ESPEasy_time.cpp | 2 +- src/src/Helpers/SystemVariables.cpp | 8 + src/src/Helpers/SystemVariables.h | 2 + 49 files changed, 417 insertions(+), 146 deletions(-) create mode 100644 src/ESPEasyEthWifi.h create mode 100644 src/Network.ino diff --git a/platformio_esp32_envs.ini b/platformio_esp32_envs.ini index 051ae11e5..52d3a24e8 100644 --- a/platformio_esp32_envs.ini +++ b/platformio_esp32_envs.ini @@ -22,7 +22,8 @@ build_flags = ${mqtt_flags.build_flags} -DCONFIG_FREERTOS_ASSERT_DISABLE -DCONFIG_LWIP_ESP_GRATUITOUS_ARP -DCONFIG_LWIP_GARP_TMR_INTERVAL=30 - +upload_flags = + -b921600 ; Custom: 4096k version -------------------------- diff --git a/src/Controller.ino b/src/Controller.ino index 652746f39..29ed7b4a9 100644 --- a/src/Controller.ino +++ b/src/Controller.ino @@ -285,7 +285,7 @@ String getMQTTclientID(const ControllerSettingsStruct& ControllerSettings) { \*********************************************************************************************/ bool MQTTCheck(controllerIndex_t controller_idx) { - if (!WiFiConnected(10)) { + if (!NetworkConnected(10)) { return false; } protocolIndex_t ProtocolIndex = getProtocolIndex_from_ControllerIndex(controller_idx); diff --git a/src/ESPEasy-Globals.cpp b/src/ESPEasy-Globals.cpp index be9ea4f31..b463ecf46 100644 --- a/src/ESPEasy-Globals.cpp +++ b/src/ESPEasy-Globals.cpp @@ -2,6 +2,7 @@ #include "ESPEasy-Globals.h" #include "ESPEasy_plugindefs.h" +#include "ESPEasyEthWifi.h" #if defined(ESP32) @@ -23,6 +24,14 @@ bool dnsServerActive = false; //NTP status bool statusNTPInitialized = false; +// Ethernet Connectiopn status +#ifdef HAS_ETHERNET +uint8_t eth_wifi_mode = ETHERNET; + // WIFI = 0 + // ETHERNET = 1 +bool eth_connected = false; +#endif + // udp protocol stuff (syslog, global sync, node info list, ntp time) WiFiUDP portUDP; diff --git a/src/ESPEasy-Globals.h b/src/ESPEasy-Globals.h index 109000964..ce759fca6 100644 --- a/src/ESPEasy-Globals.h +++ b/src/ESPEasy-Globals.h @@ -224,6 +224,11 @@ extern bool statusNTPInitialized; // udp protocol stuff (syslog, global sync, node info list, ntp time) extern WiFiUDP portUDP; +// Ethernet Connectiopn status +#ifdef HAS_ETHERNET +extern uint8_t eth_wifi_mode; +extern bool eth_connected; +#endif @@ -430,6 +435,7 @@ struct GpioFactorySettingsStruct { i2c_scl = 5; eth_power = 12; eth_clock_mode = 3; + eth_wifi_mode = 1; break; // case DeviceModel_default: break; @@ -448,6 +454,7 @@ struct GpioFactorySettingsStruct { int8_t eth_mdio = DEFAULT_ETH_PIN_MDIO; int8_t eth_power = DEFAULT_ETH_PIN_POWER; int8_t eth_clock_mode = DEFAULT_ETH_CLOCK_MODE; + int8_t eth_wifi_mode = DEFAULT_ETH_WIFI_MODE; }; void addPredefinedPlugins(const GpioFactorySettingsStruct& gpio_settings); diff --git a/src/ESPEasy.ino b/src/ESPEasy.ino index b638224a9..8234a7b44 100644 --- a/src/ESPEasy.ino +++ b/src/ESPEasy.ino @@ -1,11 +1,6 @@ #include -#ifdef HAS_ETHERNET -#include -static bool eth_connected = false; -#endif - #ifdef CONTINUOUS_INTEGRATION #pragma GCC diagnostic error "-Wall" #else @@ -227,7 +222,7 @@ void setup() } emergencyReset(); - + String log = F("\n\n\rINIT : Booting version: "); log += F(BUILD_GIT); log += " ("; @@ -238,7 +233,6 @@ void setup() log += FreeMem(); addLog(LOG_LEVEL_INFO, log); - //warm boot if (readFromRTC()) { @@ -285,6 +279,18 @@ void setup() progMemMD5check(); LoadSettings(); + #ifdef HAS_ETHERNET + // This ensures, that changing WIFI OR ETHERNET MODE happens properly only after reboot. Changing without reboot would not be a good idea. + // This only works after LoadSettings(); + eth_wifi_mode = Settings.ETH_Wifi_Mode; + log = F("INIT : ETH_WIFI_MODE:"); + log += String(eth_wifi_mode); + log += F(" ("); + log += (eth_wifi_mode == WIFI ? F("WIFI") : F("ETHERNET")); + log += F(")"); + addLog(LOG_LEVEL_INFO, log); + #endif + Settings.UseRTOSMultitasking = false; // For now, disable it, we experience heap corruption. if (RTC.bootFailedCount > 10 && RTC.bootCounter > 10) { byte toDisable = RTC.bootFailedCount - 10; @@ -374,12 +380,11 @@ void setup() rulesProcessing(event); // TD-er: Process events in the setup() now. } -#ifdef HAS_ETHERNET + #ifdef HAS_ETHERNET WiFi.onEvent(ETHEvent); - ETHConnectRelaxed(); -#else - WiFiConnectRelaxed(); -#endif + #endif + + NetworkConnectRelaxed(); setWebserverRunning(true); @@ -557,11 +562,16 @@ void loop() updateLoopStats(); - #ifndef HAS_ETHERNET + #ifdef HAS_ETHERNET + // Handle WiFiEvents when compiled with HAS_ETHERNET but in WiFi Mode eth_wifi_mode (WIFI = 0, ETHERNET = 1) + if(eth_wifi_mode == WIFI) { + handle_unprocessedWiFiEvents(); + } + #else handle_unprocessedWiFiEvents(); #endif - bool firstLoopConnectionsEstablished = WiFiConnected() && firstLoop; + bool firstLoopConnectionsEstablished = NetworkConnected() && firstLoop; if (firstLoopConnectionsEstablished) { addLog(LOG_LEVEL_INFO, F("firstLoopConnectionsEstablished")); firstLoop = false; @@ -678,7 +688,7 @@ void updateMQTTclient_connected() { void runPeriodicalMQTT() { // MQTT_KEEPALIVE = 15 seconds. - if (!WiFiConnected(10)) { + if (!NetworkConnected(10)) { updateMQTTclient_connected(); return; } @@ -773,7 +783,7 @@ void run10TimesPerSecond() { processNextEvent(); #ifdef USES_C015 - if (WiFiConnected()) + if (NetworkConnected()) Blynk_Run_c015(); #endif #ifndef USE_RTOS_MULTITASKING @@ -964,11 +974,11 @@ void backgroundtasks() return; } START_TIMER - const bool wifiConnected = WiFiConnected(); + const bool networkConnected = NetworkConnected(); runningBackgroundTasks=true; #if defined(ESP8266) - if (wifiConnected) { + if (networkConnected) { tcpCleanup(); } #endif @@ -993,14 +1003,14 @@ void backgroundtasks() dnsServer.processNextRequest(); #ifdef FEATURE_ARDUINO_OTA - if(Settings.ArduinoOTAEnable && wifiConnected) + if(Settings.ArduinoOTAEnable && networkConnected) ArduinoOTA.handle(); //once OTA is triggered, only handle that and dont do other stuff. (otherwise it fails) while (ArduinoOTAtriggered) { delay(0); - if (WiFiConnected()) { + if (NetworkConnected()) { ArduinoOTA.handle(); } } @@ -1009,7 +1019,7 @@ void backgroundtasks() #ifdef FEATURE_MDNS // Allow MDNS processing - if (wifiConnected) { + if (networkConnected) { MDNS.update(); } #endif diff --git a/src/ESPEasyEth.ino b/src/ESPEasyEth.ino index 26609fbac..4b002528f 100644 --- a/src/ESPEasyEth.ino +++ b/src/ESPEasyEth.ino @@ -2,12 +2,15 @@ #ifdef HAS_ETHERNET #include "ETH.h" +#include "ESPEasy-Globals.h" bool ethUseStaticIP() { return Settings.ETH_IP[0] != 0 && Settings.ETH_IP[3] != 255; } void ethSetupStaticIPconfig() { + // TODO: PKR Remove + addLog(LOG_LEVEL_INFO, F("ethSetupStaticIPConfig Started")); //setUseStaticIP(useStaticIP()); if (!ethUseStaticIP()) { return; } @@ -27,15 +30,23 @@ void ethSetupStaticIPconfig() { log += formatIP(dns); addLog(LOG_LEVEL_INFO, log); } + // TODO: PKR Remove + addLog(LOG_LEVEL_INFO, F("Before ETH.config")); ETH.config(ip, gw, subnet, dns); + // TODO: PKR Remove + addLog(LOG_LEVEL_INFO, F("After ETH.config")); } bool ethCheckSettings() { + // TODO: PKR Remove + addLog(LOG_LEVEL_INFO, F("ethCheckSettings Started")); bool result = true; if (Settings.ETH_Phy_Type != 0 && Settings.ETH_Phy_Type != 1) result = false; if (Settings.ETH_Clock_Mode > 3) result = false; + if (Settings.ETH_Wifi_Mode > 1) + result = false; if (Settings.ETH_Pin_mdc > MAX_GPIO) result = false; if (Settings.ETH_Pin_mdio > MAX_GPIO) @@ -46,17 +57,25 @@ bool ethCheckSettings() { } bool ethPrepare() { + // TODO: PKR Remove + addLog(LOG_LEVEL_INFO, F("ethPrepare Started")); if (!ethCheckSettings()) { addLog(LOG_LEVEL_ERROR, F("ETH: Settings not correct!!!")); return false; } + // TODO: PKR Remove + addLog(LOG_LEVEL_INFO, F("Before ETH.config")); ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); + // TODO: PKR Remove + addLog(LOG_LEVEL_INFO, F("After ETH.conif")); ethSetupStaticIPconfig(); return true; } String ethGetDebugClockModeStr() { + // TODO: PKR Remove + addLog(LOG_LEVEL_INFO, F("ethDebugColckModeStr Started")); switch (Settings.ETH_Clock_Mode) { case 0: return F("ETH_CLOCK_GPIO0_IN"); @@ -67,10 +86,25 @@ String ethGetDebugClockModeStr() { } } +String ethGetDebugEthWifiModeStr() { + // TODO: PKR Remove + addLog(LOG_LEVEL_INFO, F("ethGetDebugEthWifiMode Started")); + switch (eth_wifi_mode) + { + case 0: return F("WIFI"); + case 1: return F("ETHERNET"); + default: return F("ETH_WIFI_ERR"); + } +} + void ethPrintSettings() { + // TODO: PKR Remove + addLog(LOG_LEVEL_INFO, F("ethPrintSettings Started")); String settingsDebugLog; settingsDebugLog.reserve(115); - settingsDebugLog += F("ETH: PHY Type: "); + settingsDebugLog += F("Eth Wifi mode: "); + settingsDebugLog += ethGetDebugEthWifiModeStr(); + settingsDebugLog += F(" ETH: PHY Type: "); settingsDebugLog += Settings.ETH_Phy_Type == 0 ? F("ETH_PHY_LAN8720") : F("ETH_PHY_TLK110"); settingsDebugLog += F(" PHY Addr: "); settingsDebugLog += Settings.ETH_Phy_Addr; @@ -86,18 +120,29 @@ void ethPrintSettings() { } void ETHConnectRelaxed() { + // TODO: PKR Remove + addLog(LOG_LEVEL_INFO, F("ETHConnectRelaxed Started")); ethPrintSettings(); - if (!ethPrepare()) { + /*if (!ethPrepare()) { // Dead code for now... addLog(LOG_LEVEL_ERROR, F("ETH : Could not prepare ETH!")); return; } + // TODO: PKR Remove + addLog(LOG_LEVEL_INFO, F("Before ETH.begin")); ETH.begin(Settings.ETH_Phy_Addr, Settings.ETH_Pin_power, Settings.ETH_Pin_mdc, Settings.ETH_Pin_mdio, (eth_phy_type_t)Settings.ETH_Phy_Type, (eth_clock_mode_t)Settings.ETH_Clock_Mode); + // TODO: PKR Remove*/ + ETH.begin(); + addLog(LOG_LEVEL_INFO, F("After ETH.begin")); +} + +bool ETHConnected() { + return eth_connected; } #endif \ No newline at end of file diff --git a/src/ESPEasyEthEvent.ino b/src/ESPEasyEthEvent.ino index 8f7e35d8a..036bdc4af 100644 --- a/src/ESPEasyEthEvent.ino +++ b/src/ESPEasyEthEvent.ino @@ -40,6 +40,9 @@ void ETHEvent(WiFiEvent_t event) addLog(LOG_LEVEL_INFO, F("ETH Stopped")); eth_connected = false; break; + case SYSTEM_EVENT_GOT_IP6: + addLog(LOG_LEVEL_INFO, F("ETH Got IP6")); + break; default: break; } diff --git a/src/ESPEasyEthWifi.h b/src/ESPEasyEthWifi.h new file mode 100644 index 000000000..a7fec2e5d --- /dev/null +++ b/src/ESPEasyEthWifi.h @@ -0,0 +1,14 @@ +#ifdef HAS_ETHERNET +#ifndef ESPEASY_WTH_WIFI_H_ +#define ESPEASY_WTH_WIFI_H_ + +#ifndef WIFI +#define WIFI 0 +#endif + +#ifndef ETHERNET +#define ETHERNET 1 +#endif + +#endif // ESPEASY_WTH_WIFI_H_ +#endif // HAS_ETHERNET \ No newline at end of file diff --git a/src/ESPEasyEth_ProcessEvent.ino b/src/ESPEasyEth_ProcessEvent.ino index 3ed601e46..6353cc88e 100644 --- a/src/ESPEasyEth_ProcessEvent.ino +++ b/src/ESPEasyEth_ProcessEvent.ino @@ -204,7 +204,7 @@ void processGotIP() { if (processedGotIP) { return; } - IPAddress ip = WiFi.localIP(); + IPAddress ip = NetworkLocalIP(); if (!useStaticIP()) { if ((ip[0] == 0) && (ip[1] == 0) && (ip[2] == 0) && (ip[3] == 0)) { @@ -213,8 +213,8 @@ void processGotIP() { } processedGotIP = true; wifiStatus |= ESPEASY_WIFI_GOT_IP; - const IPAddress gw = WiFi.gatewayIP(); - const IPAddress subnet = WiFi.subnetMask(); + const IPAddress gw = NetworkGatewayIP(); + const IPAddress subnet = NetworkSubnetMask(); const long dhcp_duration = timeDiff(lastConnectMoment, lastGetIPmoment); if (loglevelActiveFor(LOG_LEVEL_INFO)) { diff --git a/src/ESPEasyStorage.ino b/src/ESPEasyStorage.ino index 2bc92cc1e..31ce4cf3b 100644 --- a/src/ESPEasyStorage.ino +++ b/src/ESPEasyStorage.ino @@ -185,6 +185,7 @@ String BuildFixes() Settings.ETH_Pin_power = DEFAULT_ETH_PIN_POWER; Settings.ETH_Phy_Type = DEFAULT_ETH_PHY_TYPE; Settings.ETH_Clock_Mode = DEFAULT_ETH_CLOCK_MODE; + Settings.ETH_Wifi_Mode = DEFAULT_ETH_WIFI_MODE; } Settings.Build = BUILD; diff --git a/src/ESPEasyWiFiEvent.cpp b/src/ESPEasyWiFiEvent.cpp index 4a8ee84ab..2892a21aa 100644 --- a/src/ESPEasyWiFiEvent.cpp +++ b/src/ESPEasyWiFiEvent.cpp @@ -1,12 +1,18 @@ +#include "ETH.h" #include "ESPEasyWiFiEvent.h" #include "src/Globals/ESPEasyWiFiEvent.h" #include "src/Globals/RTC.h" #include "ESPEasyTimeTypes.h" +#include "ESPEasy_Log.h" #include "src/DataStructs/RTCStruct.h" #include "src/Helpers/ESPEasy_time_calc.h" +#ifdef HAS_ETHERNET +extern bool eth_connected; +#endif + #ifdef ESP32 void WiFi_Access_Static_IP::set_use_static_ip(bool enabled) { _useStaticIp = enabled; @@ -99,18 +105,6 @@ void WiFiEvent(system_event_id_t event, system_event_info_t info) { case SYSTEM_EVENT_SCAN_DONE: processedScanDone = false; break; -#ifdef HAS_ETHERNET - case SYSTEM_EVENT_ETH_START: - break; - case SYSTEM_EVENT_ETH_CONNECTED: - break; - case SYSTEM_EVENT_ETH_DISCONNECTED: - break; - case SYSTEM_EVENT_ETH_STOP: - break; - case SYSTEM_EVENT_ETH_GOT_IP: - break; -#endif default: break; } diff --git a/src/ESPEasyWifi.ino b/src/ESPEasyWifi.ino index 9c0b5af35..4d6f56538 100644 --- a/src/ESPEasyWifi.ino +++ b/src/ESPEasyWifi.ino @@ -73,10 +73,6 @@ // - Start/stop of AP mode // ******************************************************************************** bool WiFiConnected() { - #ifdef HAS_ETHERNET - return eth_connected; - #else - START_TIMER; if (unprocessedWifiEvents()) { return false; } @@ -133,7 +129,6 @@ bool WiFiConnected() { delay(1); STOP_TIMER(WIFI_NOTCONNECTED_STATS); return false; - #endif // HAS_ETHERNET } void WiFiConnectRelaxed() { diff --git a/src/ESPEasyWifi_ProcessEvent.ino b/src/ESPEasyWifi_ProcessEvent.ino index ee7ff8d55..e24802ff3 100644 --- a/src/ESPEasyWifi_ProcessEvent.ino +++ b/src/ESPEasyWifi_ProcessEvent.ino @@ -24,7 +24,7 @@ void handle_unprocessedWiFiEvents() delay(1); if (wifiConnectAttemptNeeded) { - WiFiConnectRelaxed(); + NetworkConnectRelaxed(); } // Process disconnect events before connect events. @@ -82,7 +82,7 @@ void handle_unprocessedWiFiEvents() markWiFi_services_initialized(); } } - } else if (!WiFiConnected()) { + } else if (!NetworkConnected()) { // Somehow the WiFi has entered a limbo state. // FIXME TD-er: This may happen on WiFi config with AP_STA mode active. // addLog(LOG_LEVEL_ERROR, F("Wifi status out sync")); @@ -223,7 +223,7 @@ void processGotIP() { // Only process GotIP events if we are connected. return; } - IPAddress ip = WiFi.localIP(); + IPAddress ip = NetworkLocalIP(); if (!useStaticIP()) { if ((ip[0] == 0) && (ip[1] == 0) && (ip[2] == 0) && (ip[3] == 0)) { @@ -232,8 +232,8 @@ void processGotIP() { } processedGotIP = true; wifiStatus |= ESPEASY_WIFI_GOT_IP; - const IPAddress gw = WiFi.gatewayIP(); - const IPAddress subnet = WiFi.subnetMask(); + const IPAddress gw = NetworkGatewayIP(); + const IPAddress subnet = NetworkSubnetMask(); const long dhcp_duration = timeDiff(lastConnectMoment, lastGetIPmoment); if (loglevelActiveFor(LOG_LEVEL_INFO)) { diff --git a/src/ESPEasy_checks.ino b/src/ESPEasy_checks.ino index 9eaac617a..58afe912b 100644 --- a/src/ESPEasy_checks.ino +++ b/src/ESPEasy_checks.ino @@ -54,7 +54,7 @@ void run_compiletime_checks() { check_size(); check_size(); check_size(); - check_size(); + check_size(); #if defined(USE_NON_STANDARD_24_TASKS) && defined(ESP8266) static_assert(TASKS_MAX == 24, "TASKS_MAX invalid size"); #endif diff --git a/src/ESPEasy_fdwdecl.h b/src/ESPEasy_fdwdecl.h index 3174b43da..c3ddd752b 100644 --- a/src/ESPEasy_fdwdecl.h +++ b/src/ESPEasy_fdwdecl.h @@ -66,8 +66,8 @@ bool connectClient(WiFiClient& client, String getWifiModeString(WiFiMode_t wifimode); -bool WiFiConnected(uint32_t timeout_ms); -bool WiFiConnected(); +bool NetworkConnected(uint32_t timeout_ms); +bool NetworkConnected(); bool useStaticIP(); bool hostReachable(const IPAddress& ip); bool hostReachable(const String& hostname); @@ -187,11 +187,24 @@ bool SourceNeedsStatusUpdate(byte eventSource); void WifiScan(bool async, bool quick = false); void WifiScan(); -void WiFiConnectRelaxed(); void WifiDisconnect(); void setAP(bool enable); void setSTA(bool enable); +// Used for Networking with Wifi or Ethernet +#include "ESPEasyEthWifi.h" +void NetworkConnectRelaxed(); +bool NetworkConnected(); +IPAddress NetworkLocalIP(); +IPAddress NetworkSubnetMask(); +IPAddress NetworkGatewayIP(); +IPAddress NetworkDnsIP (uint8_t dns_no=0); +// TODO: PKR: Change to NetworkMacAddress +//uint8_t * NetworkMacAddress(uint8_t* mac); +String NetworkMacAddress(); +String WifiGetAPssid(); +String createRFCCompliantHostname(String oldString); + #include "src/Globals/ESPEasyWiFiEvent.h" void setWifiMode(WiFiMode_t wifimode); diff --git a/src/Misc.ino b/src/Misc.ino index 9e85b1263..dfa122221 100644 --- a/src/Misc.ino +++ b/src/Misc.ino @@ -350,7 +350,7 @@ bool readyForSleep() return false; } - if (!WiFiConnected()) { + if (!NetworkConnected()) { // Allow 12 seconds to establish connections return timeOutReached(timerAwakeFromDeepSleep + 12000); } @@ -708,7 +708,7 @@ void statusLED(bool traffic) else { - if (WiFiConnected()) + if (NetworkConnected()) { long int delta = timePassedSince(gnLastUpdate); if (delta>0 || delta<0 ) @@ -1214,6 +1214,7 @@ void ResetFactory() Settings.ETH_Pin_power = gpio_settings.eth_power; Settings.ETH_Phy_Type = gpio_settings.eth_phytype; Settings.ETH_Clock_Mode = gpio_settings.eth_clock_mode; + Settings.ETH_Wifi_Mode = gpio_settings.eth_wifi_mode; /* Settings.GlobalSync = DEFAULT_USE_GLOBAL_SYNC; diff --git a/src/Network.ino b/src/Network.ino new file mode 100644 index 000000000..6f55aaff3 --- /dev/null +++ b/src/Network.ino @@ -0,0 +1,145 @@ +//#include "Network.h" + +/*#include "ESPEasy_fdwdecl.h" +#include "ESPEasy_Log.h" +#include "ESPEasy_common.h" +#include "src/Globals/Settings.h" +#include "src/DataStructs/TimingStats.h" + +#include "ESPEasyEth.ino" +#include "ESPEasyWifi.ino" +#include "ESPEasyWifi_ProcessEvent.ino"*/ + +/*********************************************************************************************\ + Ethernet or Wifi Support for ESP32 Build flag HAS_ETHERNET +\*********************************************************************************************/ +void NetworkConnectRelaxed() { +#ifdef HAS_ETHERNET + addLog(LOG_LEVEL_INFO, F("Connect to: ")); + addLog(LOG_LEVEL_INFO, ethGetDebugEthWifiModeStr()); + if(eth_wifi_mode == ETHERNET) { + ETHConnectRelaxed(); + } else { + WiFiConnectRelaxed(); + } +#else + WiFiConnectRelaxed(); +#endif +} + +bool NetworkConnected() { + #ifdef HAS_ETHERNET + if(eth_wifi_mode == ETHERNET) { + return ETHConnected(); + } else { + return WiFiConnected(); + } + #else + return WiFiConnected(); + #endif +} + +IPAddress NetworkLocalIP() { + #ifdef HAS_ETHERNET + if(eth_wifi_mode == ETHERNET) { + if(eth_connected) { + return ETH.localIP(); + } else { + addLog(LOG_LEVEL_ERROR, F("Call NetworkLocalIP() only on connected Ethernet!")); + return IPAddress(); + } + } else { + return WiFi.localIP(); + } + #else + return WiFi.localIP(); + #endif +} + +IPAddress NetworkSubnetMask() { + #ifdef HAS_ETHERNET + if(eth_wifi_mode == ETHERNET) { + if(eth_connected) { + return ETH.subnetMask(); + } else { + addLog(LOG_LEVEL_ERROR, F("Call NetworkSubnetMask() only on connected Ethernet!")); + return IPAddress(); + } + } else { + return WiFi.subnetMask(); + } + #else + return WiFi.subnetMask(); + #endif +} + +IPAddress NetworkGatewayIP() { + #ifdef HAS_ETHERNET + if(eth_wifi_mode == ETHERNET) { + if(eth_connected) { + return ETH.gatewayIP(); + } else { + addLog(LOG_LEVEL_ERROR, F("Call NetworkGatewayIP() only on connected Ethernet!")); + return IPAddress(); + } + } else { + return WiFi.gatewayIP(); + } + #else + return WiFi.gatewayIP(); + #endif +} + +// TODO: PKR: Check her with default variable +IPAddress NetworkDnsIP (uint8_t dns_no) { + #ifdef HAS_ETHERNET + if(eth_wifi_mode == ETHERNET) { + if(eth_connected) { + return ETH.dnsIP(); + } else { + addLog(LOG_LEVEL_ERROR, F("Call NetworkDnsIP(uint8_t dns_no) only on connected Ethernet!")); + return IPAddress(); + } + } else { + return WiFi.dnsIP(dns_no); + } + #else + return WiFi.dnsIP(dns_no); + #endif +} + +uint8_t * NetworkMacAddressAsBytes(uint8_t* mac) { + #ifdef HAS_ETHERNET + if(eth_wifi_mode == ETHERNET) { + if(eth_connected) { + // TODO: PKR: Change to NetworjMacAddress + return mac; + } else { + addLog(LOG_LEVEL_ERROR, F("Call NetworkMacAddressAsBytes(uint8_t* mac) only on connected Ethernet!")); + return mac; + } + } else { + return WiFi.macAddress(mac); + } + #else + return WiFi.macAddress(mac); + #endif + return WiFi.macAddress(mac); +} + +String NetworkMacAddress() { + #ifdef HAS_ETHERNET + if(eth_wifi_mode == ETHERNET) { + if(!eth_connected) { + addLog(LOG_LEVEL_ERROR, F("Call NetworkMacAddress() only on connected Ethernet!")); + } + } + #endif + + uint8_t mac[] = { 0, 0, 0, 0, 0, 0 }; + uint8_t *macread = NetworkMacAddressAsBytes(mac); + char macaddress[20]; + formatMAC(macread, macaddress); + + return String(macaddress); +} \ No newline at end of file diff --git a/src/Networking.ino b/src/Networking.ino index 593289c80..3463fc3ea 100644 --- a/src/Networking.ino +++ b/src/Networking.ino @@ -59,7 +59,7 @@ void etharp_gratuitous_r(struct netif *netif) { \*********************************************************************************************/ void syslog(byte logLevel, const char *message) { - if ((Settings.Syslog_IP[0] != 0) && WiFiConnected()) + if ((Settings.Syslog_IP[0] != 0) && NetworkConnected()) { IPAddress broadcastIP(Settings.Syslog_IP[0], Settings.Syslog_IP[1], Settings.Syslog_IP[2], Settings.Syslog_IP[3]); portUDP.beginPacket(broadcastIP, 514); @@ -225,7 +225,7 @@ void checkUDP() \*********************************************************************************************/ void SendUDPCommand(byte destUnit, const char *data, byte dataLength) { - if (!WiFiConnected(10)) { + if (!NetworkConnected(10)) { return; } @@ -249,7 +249,7 @@ void SendUDPCommand(byte destUnit, const char *data, byte dataLength) \*********************************************************************************************/ void sendUDP(byte unit, const byte *data, byte size) { - if (!WiFiConnected(10)) { + if (!NetworkConnected(10)) { return; } @@ -324,7 +324,7 @@ void refreshNodeList() \*********************************************************************************************/ void sendSysInfoUDP(byte repeats) { - if ((Settings.UDPPort == 0) || !WiFiConnected(10)) { + if ((Settings.UDPPort == 0) || !NetworkConnected(10)) { return; } @@ -354,12 +354,9 @@ void sendSysInfoUDP(byte repeats) for (byte x = 0; x < 6; x++) { data[x + 2] = macread[x]; } - #ifdef HAS_ETHERNET - IPAddress ip = ETH.localIP(); - #else - IPAddress ip = WiFi.localIP(); - #endif - + + IPAddress ip = NetworkLocalIP(); + for (byte x = 0; x < 4; x++) { data[x + 8] = ip[x]; } @@ -386,11 +383,7 @@ void sendSysInfoUDP(byte repeats) if (it != Nodes.end()) { - #ifdef HAS_ETHERNET - IPAddress ip = ETH.localIP(); - #else - IPAddress ip = WiFi.localIP(); - #endif + IPAddress ip = NetworkLocalIP(); for (byte x = 0; x < 4; x++) { it->second.ip[x] = ip[x]; @@ -409,7 +402,7 @@ void sendSysInfoUDP(byte repeats) Respond to HTTP XML requests for SSDP information \*********************************************************************************************/ void SSDP_schema(WiFiClient& client) { - if (!WiFiConnected(10)) { + if (!NetworkConnected(10)) { return; } @@ -760,14 +753,10 @@ bool getSubnetRange(IPAddress& low, IPAddress& high) if (wifiStatus < ESPEASY_WIFI_GOT_IP) { return false; } - #ifdef HAS_ETHERNET - const IPAddress ip = ETH.localIP(); - const IPAddress subnet = ETH.subnetMask(); - #else - const IPAddress ip = WiFi.localIP(); - const IPAddress subnet = WiFi.subnetMask(); - #endif - + + const IPAddress ip = NetworkLocalIP(); + const IPAddress subnet = NetworkSubnetMask(); + low = ip; high = ip; @@ -811,8 +800,8 @@ bool hasIPaddr() { #endif // ifdef CORE_POST_2_5_0 } -// Check WiFi connection. Maximum timeout 500 msec. -bool WiFiConnected(uint32_t timeout_ms) { +// Check connection. Maximum timeout 500 msec. +bool NetworkConnected(uint32_t timeout_ms) { uint32_t timer = millis() + (timeout_ms > 500 ? 500 : timeout_ms); uint32_t min_delay = timeout_ms / 20; @@ -822,7 +811,7 @@ bool WiFiConnected(uint32_t timeout_ms) { } // Apparently something needs network, perform check to see if it is ready now. - while (!WiFiConnected()) { + while (!NetworkConnected()) { if (timeOutReached(timer)) { return false; } @@ -832,7 +821,7 @@ bool WiFiConnected(uint32_t timeout_ms) { } bool hostReachable(const IPAddress& ip) { - if (!WiFiConnected()) { return false; } + if (!NetworkConnected()) { return false; } return true; // Disabled ping as requested here: // https://github.com/letscontrolit/ESPEasy/issues/1494#issuecomment-397872538 @@ -878,7 +867,7 @@ bool connectClient(WiFiClient& client, IPAddress ip, uint16_t port) { START_TIMER; - if (!WiFiConnected()) { + if (!NetworkConnected()) { return false; } bool connected = (client.connect(ip, port) == 1); @@ -901,7 +890,7 @@ bool connectClient(WiFiClient& client, IPAddress ip, uint16_t port) bool resolveHostByName(const char *aHostname, IPAddress& aResult) { START_TIMER; - if (!WiFiConnected()) { + if (!NetworkConnected()) { return false; } #if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ESP32) @@ -933,7 +922,7 @@ bool hostReachable(const String& hostname) { // Create a random port for the UDP connection. // Return true when successful. bool beginWiFiUDP_randomPort(WiFiUDP& udp) { - if (!WiFiConnected()) { + if (!NetworkConnected()) { return false; } unsigned int attempts = 3; @@ -950,7 +939,7 @@ bool beginWiFiUDP_randomPort(WiFiUDP& udp) { } void sendGratuitousARP() { - if (!WiFiConnected()) { + if (!NetworkConnected()) { return; } #ifdef SUPPORT_ARP diff --git a/src/StringProvider.ino b/src/StringProvider.ino index c9097bde1..c063f4b4b 100644 --- a/src/StringProvider.ino +++ b/src/StringProvider.ino @@ -107,7 +107,8 @@ String getLabel(LabelType::Enum label) { case LabelType::ETH_DUPLEX: return F("Eth Mode"); case LabelType::ETH_SPEED: return F("Eth Speed"); case LabelType::ETH_STATE: return F("Eth State"); - case LabelType::ETH_SPEED_STATE: return F("Eth State"); + case LabelType::ETH_SPEED_STATE: return F("Eth Speed State"); + case LabelType::ETH_WIFI_MODE: return F("Eth Wifi Mode"); #endif } @@ -152,19 +153,19 @@ String getValue(LabelType::Enum label) { case LabelType::IP_CONFIG: return useStaticIP() ? getLabel(LabelType::IP_CONFIG_STATIC) : getLabel(LabelType::IP_CONFIG_DYNAMIC); case LabelType::IP_CONFIG_STATIC: break; case LabelType::IP_CONFIG_DYNAMIC: break; - case LabelType::IP_ADDRESS: return WiFi.localIP().toString(); + case LabelType::IP_ADDRESS: return NetworkLocalIP().toString(); case LabelType::IP_SUBNET: return WiFi.subnetMask().toString(); case LabelType::IP_ADDRESS_SUBNET: return String(getValue(LabelType::IP_ADDRESS) + F(" / ") + getValue(LabelType::IP_SUBNET)); - case LabelType::GATEWAY: return WiFi.gatewayIP().toString(); + case LabelType::GATEWAY: return NetworkGatewayIP().toString(); case LabelType::CLIENT_IP: return formatIP(web_server.client().remoteIP()); #ifdef FEATURE_MDNS case LabelType::M_DNS: return String(WifiGetHostname()) + F(".local"); #endif case LabelType::DNS: return String(getValue(LabelType::DNS_1) + F(" / ") + getValue(LabelType::DNS_2)); - case LabelType::DNS_1: return WiFi.dnsIP(0).toString(); - case LabelType::DNS_2: return WiFi.dnsIP(1).toString(); + case LabelType::DNS_1: return NetworkDnsIP(0).toString(); + case LabelType::DNS_2: return NetworkDnsIP(1).toString(); case LabelType::ALLOWED_IP_RANGE: return describeAllowedIPrange(); - case LabelType::STA_MAC: return WiFi.macAddress(); + case LabelType::STA_MAC: return NetworkMacAddress(); case LabelType::AP_MAC: break; case LabelType::SSID: return WiFi.SSID(); case LabelType::BSSID: return WiFi.BSSIDstr(); @@ -224,6 +225,8 @@ String getValue(LabelType::Enum label) { case LabelType::ETH_SPEED: return getEthSpeed(); case LabelType::ETH_STATE: return ETH.linkUp() ? F("Link Up") : F("Link Down"); case LabelType::ETH_SPEED_STATE: return getEthLinkSpeedState(); + // TODO: PKR: Same as ethwifidebug + case LabelType::ETH_WIFI_MODE: return (eth_wifi_mode == WIFI ? F("WIFI") : F("ETHERNET")); #endif } diff --git a/src/StringProviderTypes.h b/src/StringProviderTypes.h index bfbb2ae61..65f9373a4 100644 --- a/src/StringProviderTypes.h +++ b/src/StringProviderTypes.h @@ -108,6 +108,7 @@ enum Enum : short { ETH_SPEED, ETH_STATE, ETH_SPEED_STATE, + ETH_WIFI_MODE, #endif }; diff --git a/src/WebServer_HardwarePage.ino b/src/WebServer_HardwarePage.ino index 4926b7874..4f0d23730 100644 --- a/src/WebServer_HardwarePage.ino +++ b/src/WebServer_HardwarePage.ino @@ -28,6 +28,7 @@ void handle_hardware() { Settings.ETH_Pin_power = getFormItemInt(F("ethpower")); Settings.ETH_Phy_Type = getFormItemInt(F("ethtype")); Settings.ETH_Clock_Mode = getFormItemInt(F("ethclock")); + Settings.ETH_Wifi_Mode = getFormItemInt(F("ethwifi")); #endif int gpio = 0; @@ -85,11 +86,15 @@ void handle_hardware() { #endif // ifdef FEATURE_SD #ifdef HAS_ETHERNET addFormSubHeader(F("Ethernet")); + addRowLabel_tr_id(F("Ethernet or WIFI?"), "ethwifi"); + String ethWifiOptions[2] = { F("WIFI"), F("ETHERNET") }; + addSelector("ethwifi", 2, ethWifiOptions, NULL, NULL, Settings.ETH_Wifi_Mode, false, true); + addFormNote(F("Note: Change Switch between WIFI and ETHERNET requires reboot to activate")); addRowLabel_tr_id(F("Ethernet PHY type"), "ethtype"); String ethPhyTypes[2] = { F("LAN8710"), F("TLK110") }; addSelector("ethtype", 2, ethPhyTypes, NULL, NULL, Settings.ETH_Phy_Type, false, true); addFormNumericBox(F("Ethernet PHY Address"), "ethphy", Settings.ETH_Phy_Addr, 0, 255); - addFormNote(F("I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110)")); + addFormNote(F("Note: I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110)")); addFormPinSelect(formatGpioName_output("Ethernet MDC pin"), "ethmdc", Settings.ETH_Pin_mdc); addFormPinSelect(formatGpioName_input("Ethernet MIO pin"), "ethmdio", Settings.ETH_Pin_mdio); addFormPinSelect(formatGpioName_output("Ethernet Power pin"), "ethpower", Settings.ETH_Pin_power); diff --git a/src/WebServer_RootPage.ino b/src/WebServer_RootPage.ino index 3e87cd8cc..3066b0361 100644 --- a/src/WebServer_RootPage.ino +++ b/src/WebServer_RootPage.ino @@ -45,8 +45,8 @@ void handle_root() { ExecuteCommand_internal(VALUE_SOURCE_HTTP, sCommand.c_str()); } - // IPAddress ip = WiFi.localIP(); - // IPAddress gw = WiFi.gatewayIP(); + // IPAddress ip = NetworkLocalIP(); + // IPAddress gw = NetwrokGatewayIP(); addHtml(printWebString); addHtml(F("
")); @@ -109,7 +109,7 @@ void handle_root() { addRowLabelValue(LabelType::IP_ADDRESS); addRowLabel(getLabel(LabelType::WIFI_RSSI)); - if (WiFiConnected()) + if (NetworkConnected()) { String html; html.reserve(32); @@ -121,8 +121,11 @@ void handle_root() { } #ifdef HAS_ETHERNET - addRowLabelValue(LabelType::ETH_SPEED_STATE); - addRowLabelValue(LabelType::ETH_IP_ADDRESS); + addRowLabelValue(LabelType::ETH_WIFI_MODE); + if(eth_wifi_mode == ETHERNET) { + addRowLabelValue(LabelType::ETH_SPEED_STATE); + addRowLabelValue(LabelType::ETH_IP_ADDRESS); + } #endif #ifdef FEATURE_MDNS diff --git a/src/WebServer_SetupPage.ino b/src/WebServer_SetupPage.ino index b7c7b510f..11f2bc513 100644 --- a/src/WebServer_SetupPage.ino +++ b/src/WebServer_SetupPage.ino @@ -14,7 +14,7 @@ void handle_setup() { // Do not check client IP range allowed. TXBuffer.startStream(); - if (!WiFiConnected()) + if (!NetworkConnected()) { sendHeadandTail(F("TmplAP")); static byte status = 0; @@ -188,7 +188,7 @@ void handle_setup_finish() { html_TD(); if (!clientIPinSubnet()) { - String host = formatIP(WiFi.localIP()); + String host = formatIP(NetworkLocalIP()); String url = F("http://"); url += host; url += F("/config"); diff --git a/src/WebServer_SysInfoPage.ino b/src/WebServer_SysInfoPage.ino index 893482bd5..618010121 100644 --- a/src/WebServer_SysInfoPage.ino +++ b/src/WebServer_SysInfoPage.ino @@ -60,15 +60,16 @@ void handle_sysinfo_json() { } json_number(F("rssi"), String(WiFi.RSSI())); json_prop(F("dhcp"), useStaticIP() ? getLabel(LabelType::IP_CONFIG_STATIC) : getLabel(LabelType::IP_CONFIG_DYNAMIC)); - json_prop(F("ip"), formatIP(WiFi.localIP())); - json_prop(F("subnet"), formatIP(WiFi.subnetMask())); - json_prop(F("gw"), formatIP(WiFi.gatewayIP())); - json_prop(F("dns1"), formatIP(WiFi.dnsIP(0))); - json_prop(F("dns2"), formatIP(WiFi.dnsIP(1))); + json_prop(F("ip"), formatIP(NetworkLocalIP())); + json_prop(F("subnet"), formatIP(NetworkSubnetMask())); + json_prop(F("gw"), formatIP(NetworkGatewayIP())); + json_prop(F("dns1"), formatIP(NetworkDnsIP(0))); + json_prop(F("dns2"), formatIP(NetworkDnsIP(1))); json_prop(F("allowed_range"), describeAllowedIPrange()); uint8_t mac[] = { 0, 0, 0, 0, 0, 0 }; +// TODO: PKR: Change to NetworkMacAddress uint8_t *macread = WiFi.macAddress(mac); char macaddress[20]; formatMAC(macread, macaddress); @@ -313,25 +314,32 @@ void handle_sysinfo_basicInfo() { addRowLabelValue(LabelType::RESET_REASON); addRowLabelValue(LabelType::LAST_TASK_BEFORE_REBOOT); addRowLabelValue(LabelType::SW_WD_COUNT); + + #ifdef HAS_ETHERNET + addRowLabel(F("Network Type")); + addRowLabelValue(LabelType::ETH_WIFI_MODE); + #endif } #ifdef HAS_ETHERNET void handle_sysinfo_Ethernet() { - addTableSeparator(F("Ethernet"), 2, 3); - addRowLabelValue(LabelType::ETH_STATE); - addRowLabelValue(LabelType::ETH_SPEED); - addRowLabelValue(LabelType::ETH_DUPLEX); - addRowLabelValue(LabelType::ETH_MAC); - addRowLabelValue(LabelType::ETH_IP_ADDRESS_SUBNET); - addRowLabelValue(LabelType::ETH_IP_GATEWAY); - addRowLabelValue(LabelType::ETH_IP_DNS); + if(eth_wifi_mode == ETHERNET) { + addTableSeparator(F("Ethernet"), 2, 3); + addRowLabelValue(LabelType::ETH_STATE); + addRowLabelValue(LabelType::ETH_SPEED); + addRowLabelValue(LabelType::ETH_DUPLEX); + addRowLabelValue(LabelType::ETH_MAC); + addRowLabelValue(LabelType::ETH_IP_ADDRESS_SUBNET); + addRowLabelValue(LabelType::ETH_IP_GATEWAY); + addRowLabelValue(LabelType::ETH_IP_DNS); + } } #endif void handle_sysinfo_Network() { addTableSeparator(F("Network"), 2, 3, F("Wifi")); - if (WiFiConnected()) + if (eth_wifi_mode == WIFI && NetworkConnected()) { addRowLabel(F("Wifi")); # if defined(ESP8266) @@ -373,6 +381,7 @@ void handle_sysinfo_Network() { { uint8_t mac[] = { 0, 0, 0, 0, 0, 0 }; +// TODO: PKR: Change to NetworkMacAddress uint8_t *macread = WiFi.macAddress(mac); char macaddress[20]; formatMAC(macread, macaddress); diff --git a/src/WebServer_SysVarPage.ino b/src/WebServer_SysVarPage.ino index c480a2297..a434381fe 100644 --- a/src/WebServer_SysVarPage.ino +++ b/src/WebServer_SysVarPage.ino @@ -62,6 +62,10 @@ void handle_sysvars() { addTableSeparator(F("System status"), 3, 3); addSysVar_enum_html(SystemVariables::ISWIFI); + #ifdef HAS_ETHERNET + addSysVar_enum_html(SystemVariables::ETH_WIFI_MODE); + addSysVar_enum_html(SystemVariables::ETH_CONNECTED); + #endif addSysVar_enum_html(SystemVariables::ISNTP); addSysVar_enum_html(SystemVariables::ISMQTT); #ifdef USES_P037 diff --git a/src/WebServer_ToolsPage.ino b/src/WebServer_ToolsPage.ino index 3d1824e58..dfffe2643 100644 --- a/src/WebServer_ToolsPage.ino +++ b/src/WebServer_ToolsPage.ino @@ -73,6 +73,7 @@ void handle_tools() { addFormSubHeader(F("Wifi")); +// TODO: PKR: Add commands for ETHERNET addWideButtonPlusDescription(F("/?cmd=wificonnect"), F("Connect"), F("Connects to known Wifi network")); addWideButtonPlusDescription(F("/?cmd=wifidisconnect"), F("Disconnect"), F("Disconnect from wifi network")); diff --git a/src/_C006.ino b/src/_C006.ino index 6cc4fa7f0..453cccf1d 100644 --- a/src/_C006.ino +++ b/src/_C006.ino @@ -87,7 +87,7 @@ bool CPlugin_006(CPlugin::Function function, struct EventStruct *event, String& case CPlugin::Function::CPLUGIN_PROTOCOL_SEND: { - if (!WiFiConnected(10)) { + if (!NetworkConnected(10)) { success = false; break; } diff --git a/src/_C009.ino b/src/_C009.ino index c7a86ad3b..af1f77fd2 100644 --- a/src/_C009.ino +++ b/src/_C009.ino @@ -123,9 +123,9 @@ bool do_process_c009_delay_queue(int controller_number, const C009_queue_element // embed IP, important if there is NAT/PAT // char ipStr[20]; - // IPAddress ip = WiFi.localIP(); + // IPAddress ip = NetworkLocalIP(); // sprintf_P(ipStr, PSTR("%u.%u.%u.%u"), ip[0], ip[1], ip[2], ip[3]); - ESP[F("ip")] = WiFi.localIP().toString(); + ESP[F("ip")] = NetworkLocalIP().toString(); // Create nested SENSOR json object JsonObject SENSOR = data.createNestedObject(String(F("SENSOR"))); diff --git a/src/_C011.ino b/src/_C011.ino index 6beab4c61..080402f5f 100644 --- a/src/_C011.ino +++ b/src/_C011.ino @@ -155,7 +155,7 @@ bool do_process_c011_delay_queue(int controller_number, const C011_queue_element boolean Create_schedule_HTTP_C011(struct EventStruct *event) { int controller_number = CPLUGIN_ID_011; - if (!WiFiConnected(10)) { + if (!NetworkConnected(10)) { return false; } MakeControllerSettings(ControllerSettings); diff --git a/src/_C012.ino b/src/_C012.ino index 35ba99aeb..9122791c5 100644 --- a/src/_C012.ino +++ b/src/_C012.ino @@ -93,7 +93,7 @@ bool do_process_c012_delay_queue(int controller_number, const C012_queue_element if (element.checkDone(true)) return true; } - if (!WiFiConnected()) { + if (!NetworkConnected()) { return false; } return element.checkDone(Blynk_get(element.txt[element.valuesSent], element.controller_idx)); diff --git a/src/_C013.ino b/src/_C013.ino index 2b17d2332..005119814 100644 --- a/src/_C013.ino +++ b/src/_C013.ino @@ -114,7 +114,7 @@ bool CPlugin_013(CPlugin::Function function, struct EventStruct *event, String& // ******************************************************************************** void C013_SendUDPTaskInfo(byte destUnit, byte sourceTaskIndex, byte destTaskIndex) { - if (!WiFiConnected(10)) { + if (!NetworkConnected(10)) { return; } @@ -158,7 +158,7 @@ void C013_SendUDPTaskInfo(byte destUnit, byte sourceTaskIndex, byte destTaskInde void C013_SendUDPTaskData(byte destUnit, byte sourceTaskIndex, byte destTaskIndex) { - if (!WiFiConnected(10)) { + if (!NetworkConnected(10)) { return; } struct C013_SensorDataStruct dataReply; @@ -196,7 +196,7 @@ void C013_SendUDPTaskData(byte destUnit, byte sourceTaskIndex, byte destTaskInde \*********************************************************************************************/ void C013_sendUDP(byte unit, byte *data, byte size) { - if (!WiFiConnected(10)) { + if (!NetworkConnected(10)) { return; } NodesMap::iterator it; diff --git a/src/_C014.ino b/src/_C014.ino index 966d6d65e..abfafe828 100644 --- a/src/_C014.ino +++ b/src/_C014.ino @@ -243,9 +243,10 @@ bool CPlugin_014(CPlugin::Function function, struct EventStruct *event, String& // $localip Device → Controller IP of the device on the local network Yes Yes #ifdef CPLUGIN_014_V3 - CPlugin_014_sendMQTTdevice(pubname,"$localip",formatIP(WiFi.localIP()).c_str(),errorCounter); + CPlugin_014_sendMQTTdevice(pubname,"$localip",formatIP(NetworkLocalIP()).c_str(),errorCounter); // $mac Device → Controller Mac address of the device network interface. The format MUST be of the type A1:B2:C3:D4:E5:F6 Yes Yes + // TODO: PKR: Change to NetworkMacAddress CPlugin_014_sendMQTTdevice(pubname,"$mac",WiFi.macAddress().c_str(),errorCounter); // $implementation Device → Controller An identifier for the Homie implementation (example esp8266) Yes Yes diff --git a/src/_C015.ino b/src/_C015.ino index ed64025a3..7d1ccca0e 100644 --- a/src/_C015.ino +++ b/src/_C015.ino @@ -212,7 +212,7 @@ bool do_process_c015_delay_queue(int controller_plugin_number, const C015_queue_ // controller has been disabled. Answer true to flush queue. return true; - if (!WiFiConnected()) { + if (!NetworkConnected()) { return false; } @@ -231,7 +231,7 @@ bool do_process_c015_delay_queue(int controller_plugin_number, const C015_queue_ boolean Blynk_keep_connection_c015(int controllerIndex, ControllerSettingsStruct& ControllerSettings){ - if (!WiFiConnected()) + if (!NetworkConnected()) return false; if (!Blynk.connected()){ diff --git a/src/_C017.ino b/src/_C017.ino index 8e9cf7190..0ba051f5f 100644 --- a/src/_C017.ino +++ b/src/_C017.ino @@ -86,7 +86,7 @@ bool do_process_c017_delay_queue(int controller_number, const C017_queue_element if (valueCount == 0) return true; //exit if we don't have anything to send. - if (!WiFiConnected(10)) + if (!NetworkConnected(10)) { return false; } diff --git a/src/_CPlugin_Helper.cpp b/src/_CPlugin_Helper.cpp index 0428d449d..23c0cc5a1 100644 --- a/src/_CPlugin_Helper.cpp +++ b/src/_CPlugin_Helper.cpp @@ -273,7 +273,7 @@ bool count_connection_results(bool success, const String& prefix, int controller bool try_connect_host(int controller_number, WiFiUDP& client, ControllerSettingsStruct& ControllerSettings) { START_TIMER; - if (!WiFiConnected()) { return false; } + if (!NetworkConnected()) { return false; } client.setTimeout(ControllerSettings.ClientTimeout); #ifndef BUILD_NO_DEBUG log_connecting_to(F("UDP : "), controller_number, ControllerSettings); @@ -293,7 +293,7 @@ bool try_connect_host(int controller_number, WiFiClient& client, ControllerSetti bool try_connect_host(int controller_number, WiFiClient& client, ControllerSettingsStruct& ControllerSettings, const String& loglabel) { START_TIMER; - if (!WiFiConnected()) { return false; } + if (!NetworkConnected()) { return false; } // Use WiFiClient class to create TCP connections client.setTimeout(ControllerSettings.ClientTimeout); diff --git a/src/_P026_Sysinfo.ino b/src/_P026_Sysinfo.ino index 33ed4424b..d1f60864b 100644 --- a/src/_P026_Sysinfo.ino +++ b/src/_P026_Sysinfo.ino @@ -212,22 +212,22 @@ float P026_get_value(int type) } case 5: { - value = WiFi.localIP()[0]; + value = NetworkLocalIP()[0]; break; } case 6: { - value = WiFi.localIP()[1]; + value = NetworkLocalIP()[1]; break; } case 7: { - value = WiFi.localIP()[2]; + value = NetworkLocalIP()[2]; break; } case 8: { - value = WiFi.localIP()[3]; + value = NetworkLocalIP()[3]; break; } case 9: diff --git a/src/_P036_FrameOLED.ino b/src/_P036_FrameOLED.ino index 1535d3b75..36405f260 100644 --- a/src/_P036_FrameOLED.ino +++ b/src/_P036_FrameOLED.ino @@ -867,7 +867,7 @@ void display_header() { } switch (_HeaderContent) { case eSSID: - if (WiFiConnected()) { + if (NetworkConnected()) { strHeader = WiFi.SSID(); } else { @@ -1344,7 +1344,7 @@ void display_scrolling_lines(int nlines) { //Draw Signal Strength Bars, return true when there was an update. bool display_wifibars() { - const bool connected = WiFiConnected(); + const bool connected = NetworkConnected(); const int nbars_filled = (WiFi.RSSI() + 100) / 12; // all bars filled if RSSI better than -46dB const int newState = connected ? nbars_filled : P36_WIFI_STATE_NOT_CONNECTED; if (newState == lastWiFiState) @@ -1366,7 +1366,7 @@ bool display_wifibars() { display->setColor(BLACK); display->fillRect(x , y, size_x, size_y); display->setColor(WHITE); - if (WiFiConnected()) { + if (NetworkConnected()) { for (uint8_t ibar = 0; ibar < nbars; ibar++) { int16_t height = size_y * (ibar + 1) / nbars; int16_t xpos = x + ibar * width; diff --git a/src/_P037_MQTTImport.ino b/src/_P037_MQTTImport.ino index 594ca60ab..31ffa64f9 100644 --- a/src/_P037_MQTTImport.ino +++ b/src/_P037_MQTTImport.ino @@ -418,7 +418,7 @@ boolean MQTTConnect_037() if (MQTTclient_037->connected()) return true; // define stuff for the client - this could also be done in the intial declaration of MQTTclient_037 - if (!WiFiConnected(100)) { + if (!NetworkConnected(100)) { Plugin_037_update_connect_status(); return false; // Not connected, so no use in wasting time to connect to a host. } diff --git a/src/_P089_Ping.ino b/src/_P089_Ping.ino index 5ad4a6dd5..1273eebc4 100644 --- a/src/_P089_Ping.ino +++ b/src/_P089_Ping.ino @@ -76,7 +76,7 @@ public: is_failure = true; /* This ping lost for sure */ - if (!WiFiConnected()) { + if (!NetworkConnected()) { return true; } diff --git a/src/src/Commands/HTTP.cpp b/src/src/Commands/HTTP.cpp index bd69b7394..96abdbcb1 100644 --- a/src/src/Commands/HTTP.cpp +++ b/src/src/Commands/HTTP.cpp @@ -14,7 +14,7 @@ String Command_HTTP_SendToHTTP(struct EventStruct *event, const char* Line) { - if (WiFiConnected()) { + if (NetworkConnected()) { String host = parseString(Line, 2); const int port = parseCommandArgumentInt(Line, 2); if (loglevelActiveFor(LOG_LEVEL_DEBUG)) { diff --git a/src/src/Commands/UDP.cpp b/src/src/Commands/UDP.cpp index 252386c23..09c58e11c 100644 --- a/src/src/Commands/UDP.cpp +++ b/src/src/Commands/UDP.cpp @@ -39,7 +39,7 @@ String Command_UPD_SendTo(struct EventStruct *event, const char *Line) String Command_UDP_SendToUPD(struct EventStruct *event, const char *Line) { - if (WiFiConnected()) { + if (NetworkConnected()) { String ip = parseString(Line, 2); int port = parseCommandArgumentInt(Line, 2); diff --git a/src/src/ControllerQueue/ControllerDelayHandlerStruct.h b/src/src/ControllerQueue/ControllerDelayHandlerStruct.h index abe68e766..94ecd7188 100644 --- a/src/src/ControllerQueue/ControllerDelayHandlerStruct.h +++ b/src/src/ControllerQueue/ControllerDelayHandlerStruct.h @@ -192,7 +192,7 @@ struct ControllerDelayHandlerStruct { MakeControllerSettings (ControllerSettings); \ LoadControllerSettings(element->controller_idx, ControllerSettings); \ C##NNN####M##_DelayHandler.configureControllerSettings(ControllerSettings); \ - if (!WiFiConnected(10)) { \ + if (!NetworkConnected(10)) { \ scheduleNextDelayQueue(TIMER_C##NNN####M##_DELAY_QUEUE, C##NNN####M##_DelayHandler.getNextScheduleTime()); \ return; \ } \ diff --git a/src/src/DataStructs/ControllerSettingsStruct.cpp b/src/src/DataStructs/ControllerSettingsStruct.cpp index 8036aec50..8b9bb08a1 100644 --- a/src/src/DataStructs/ControllerSettingsStruct.cpp +++ b/src/src/DataStructs/ControllerSettingsStruct.cpp @@ -85,7 +85,7 @@ void ControllerSettingsStruct::setHostname(const String& controllerhostname) { } boolean ControllerSettingsStruct::checkHostReachable(bool quick) { - if (!WiFiConnected(10)) { + if (!NetworkConnected(10)) { return false; // Not connected, so no use in wasting time to connect to a host. } delay(1); // Make sure the Watchdog will not trigger a reset. @@ -166,7 +166,7 @@ bool ControllerSettingsStruct::updateIPcache() { return true; } - if (!WiFiConnected()) { return false; } + if (!NetworkConnected()) { return false; } IPAddress tmpIP; if (resolveHostByName(HostName, tmpIP)) { diff --git a/src/src/DataStructs/ESPEasyDefaults.h b/src/src/DataStructs/ESPEasyDefaults.h index 68b659996..fb3068d2f 100644 --- a/src/src/DataStructs/ESPEasyDefaults.h +++ b/src/src/DataStructs/ESPEasyDefaults.h @@ -187,7 +187,12 @@ #define DEFAULT_ETH_PIN_POWER -1 #endif #ifndef DEFAULT_ETH_CLOCK_MODE -#define DEFAULT_ETH_CLOCK_MODE 3 +#define DEFAULT_ETH_CLOCK_MODE 0 +#endif +#ifndef DEFAULT_ETH_WIFI_MODE +#define DEFAULT_ETH_WIFI_MODE 1 // TODO: PKR: Change perhaps to 0 + // 0 WIFI + // 1 ETHERNET #endif diff --git a/src/src/DataStructs/SettingsStruct.cpp b/src/src/DataStructs/SettingsStruct.cpp index 3358c60e2..91ceef28d 100644 --- a/src/src/DataStructs/SettingsStruct.cpp +++ b/src/src/DataStructs/SettingsStruct.cpp @@ -216,6 +216,7 @@ void SettingsStruct_tmpl::clearMisc() { ETH_Pin_power = -1; ETH_Phy_Type = 0; ETH_Clock_Mode = 0; + ETH_Wifi_Mode = 0; for (byte i = 0; i < 17; ++i) { PinBootStates[i] = 0; } BaudRate = 0; diff --git a/src/src/DataStructs/SettingsStruct.h b/src/src/DataStructs/SettingsStruct.h index db57944e5..0f83d8219 100644 --- a/src/src/DataStructs/SettingsStruct.h +++ b/src/src/DataStructs/SettingsStruct.h @@ -187,6 +187,7 @@ class SettingsStruct_tmpl byte ETH_Gateway[4]; byte ETH_Subnet[4]; byte ETH_DNS[4]; + uint8_t ETH_Wifi_Mode; }; /* diff --git a/src/src/Helpers/ESPEasy_time.cpp b/src/src/Helpers/ESPEasy_time.cpp index b39e7eb78..d759ccc22 100644 --- a/src/src/Helpers/ESPEasy_time.cpp +++ b/src/src/Helpers/ESPEasy_time.cpp @@ -215,7 +215,7 @@ bool ESPEasy_time::systemTimePresent() const { bool ESPEasy_time::getNtpTime(double& unixTime_d) { - if (!Settings.UseNTP || !WiFiConnected(10)) { + if (!Settings.UseNTP || !NetworkConnected(10)) { return false; } IPAddress timeServerIP; diff --git a/src/src/Helpers/SystemVariables.cpp b/src/src/Helpers/SystemVariables.cpp index 2a8fa647c..4963d644c 100644 --- a/src/src/Helpers/SystemVariables.cpp +++ b/src/src/Helpers/SystemVariables.cpp @@ -89,6 +89,10 @@ void SystemVariables::parseSystemVariables(String& s, boolean useURLencode) case ISNTP: value = String(statusNTPInitialized); break; case ISWIFI: value = String(wifiStatus); break; // 0=disconnected, 1=connected, 2=got ip, 3=services initialized + #ifdef HAS_ETHERNET + case ETH_WIFI_MODE: value = (eth_wifi_mode == WIFI ? "WIFI" : "ETHERNET"); break; // 0=WIFI, 1=ETH + case ETH_CONNECTED: value = String(eth_connected); break; // 0=disconnected, 1=connected + #endif case LCLTIME: value = getValue(LabelType::LOCAL_TIME); break; case LCLTIME_AM: value = node_time.getDateTimeString_ampm('-', ':', ' '); break; case LF: value = "\n"; break; @@ -243,6 +247,10 @@ String SystemVariables::toString(SystemVariables::Enum enumval) case Enum::ISMQTTIMP: return F("%ismqttimp%"); case Enum::ISNTP: return F("%isntp%"); case Enum::ISWIFI: return F("%iswifi%"); + #ifdef HAS_ETHERNET + case Enum::ETH_WIFI_MODE: return F("%eth_wifi_mode%"); + case Enum::ETH_CONNECTED: return F("%eth_connected%"); + #endif case Enum::LCLTIME: return F("%lcltime%"); case Enum::LCLTIME_AM: return F("%lcltime_am%"); case Enum::LF: return F("%LF%"); diff --git a/src/src/Helpers/SystemVariables.h b/src/src/Helpers/SystemVariables.h index 67421791b..ec24e684b 100644 --- a/src/src/Helpers/SystemVariables.h +++ b/src/src/Helpers/SystemVariables.h @@ -17,6 +17,8 @@ public: ISMQTTIMP, ISNTP, ISWIFI, + ETH_WIFI_MODE, + ETH_CONNECTED, LCLTIME, LCLTIME_AM, LF, From 09a149e7c42aea94113e02cdb94b2395d133ee04 Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Sun, 26 Apr 2020 23:16:33 +0200 Subject: [PATCH 17/39] Removed some comments Build now working with HAS_ETHERNET not defined --- src/ESPEasy_fdwdecl.h | 3 +-- src/Network.ino | 4 +--- src/StringProvider.ino | 1 - src/WebServer_HardwarePage.ino | 4 ++-- src/WebServer_JSON.ino | 1 + src/WebServer_SysInfoPage.ino | 8 +++++--- src/WebServer_ToolsPage.ino | 1 - src/_C014.ino | 1 - src/src/DataStructs/ESPEasyDefaults.h | 2 +- src/src/Helpers/SystemVariables.cpp | 2 ++ 10 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/ESPEasy_fdwdecl.h b/src/ESPEasy_fdwdecl.h index c3ddd752b..f1880a48f 100644 --- a/src/ESPEasy_fdwdecl.h +++ b/src/ESPEasy_fdwdecl.h @@ -199,8 +199,7 @@ IPAddress NetworkLocalIP(); IPAddress NetworkSubnetMask(); IPAddress NetworkGatewayIP(); IPAddress NetworkDnsIP (uint8_t dns_no=0); -// TODO: PKR: Change to NetworkMacAddress -//uint8_t * NetworkMacAddress(uint8_t* mac); +uint8_t * NetworkMacAddressAsBytes(uint8_t* mac); String NetworkMacAddress(); String WifiGetAPssid(); String createRFCCompliantHostname(String oldString); diff --git a/src/Network.ino b/src/Network.ino index 6f55aaff3..bb8060651 100644 --- a/src/Network.ino +++ b/src/Network.ino @@ -90,7 +90,6 @@ IPAddress NetworkGatewayIP() { #endif } -// TODO: PKR: Check her with default variable IPAddress NetworkDnsIP (uint8_t dns_no) { #ifdef HAS_ETHERNET if(eth_wifi_mode == ETHERNET) { @@ -112,8 +111,7 @@ uint8_t * NetworkMacAddressAsBytes(uint8_t* mac) { #ifdef HAS_ETHERNET if(eth_wifi_mode == ETHERNET) { if(eth_connected) { - // TODO: PKR: Change to NetworjMacAddress - return mac; + return WiFi.macAddress(mac); } else { addLog(LOG_LEVEL_ERROR, F("Call NetworkMacAddressAsBytes(uint8_t* mac) only on connected Ethernet!")); return mac; diff --git a/src/StringProvider.ino b/src/StringProvider.ino index c063f4b4b..947c0fcd7 100644 --- a/src/StringProvider.ino +++ b/src/StringProvider.ino @@ -225,7 +225,6 @@ String getValue(LabelType::Enum label) { case LabelType::ETH_SPEED: return getEthSpeed(); case LabelType::ETH_STATE: return ETH.linkUp() ? F("Link Up") : F("Link Down"); case LabelType::ETH_SPEED_STATE: return getEthLinkSpeedState(); - // TODO: PKR: Same as ethwifidebug case LabelType::ETH_WIFI_MODE: return (eth_wifi_mode == WIFI ? F("WIFI") : F("ETHERNET")); #endif diff --git a/src/WebServer_HardwarePage.ino b/src/WebServer_HardwarePage.ino index 4f0d23730..f143be84d 100644 --- a/src/WebServer_HardwarePage.ino +++ b/src/WebServer_HardwarePage.ino @@ -89,12 +89,12 @@ void handle_hardware() { addRowLabel_tr_id(F("Ethernet or WIFI?"), "ethwifi"); String ethWifiOptions[2] = { F("WIFI"), F("ETHERNET") }; addSelector("ethwifi", 2, ethWifiOptions, NULL, NULL, Settings.ETH_Wifi_Mode, false, true); - addFormNote(F("Note: Change Switch between WIFI and ETHERNET requires reboot to activate")); + addFormNote(F("Change Switch between WIFI and ETHERNET requires reboot to activate")); addRowLabel_tr_id(F("Ethernet PHY type"), "ethtype"); String ethPhyTypes[2] = { F("LAN8710"), F("TLK110") }; addSelector("ethtype", 2, ethPhyTypes, NULL, NULL, Settings.ETH_Phy_Type, false, true); addFormNumericBox(F("Ethernet PHY Address"), "ethphy", Settings.ETH_Phy_Addr, 0, 255); - addFormNote(F("Note: I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110)")); + addFormNote(F("I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110)")); addFormPinSelect(formatGpioName_output("Ethernet MDC pin"), "ethmdc", Settings.ETH_Pin_mdc); addFormPinSelect(formatGpioName_input("Ethernet MIO pin"), "ethmdio", Settings.ETH_Pin_mdio); addFormPinSelect(formatGpioName_output("Ethernet Power pin"), "ethpower", Settings.ETH_Pin_power); diff --git a/src/WebServer_JSON.ino b/src/WebServer_JSON.ino index 5625d65dd..7e3ed9b04 100644 --- a/src/WebServer_JSON.ino +++ b/src/WebServer_JSON.ino @@ -97,6 +97,7 @@ void handle_json() #endif // ifdef SUPPORT_ARP stream_next_json_object_value(LabelType::CONNECTION_FAIL_THRESH); stream_last_json_object_value(LabelType::WIFI_RSSI); + // TODO: PKR: Add ETH Objects addHtml(F(",\n")); } diff --git a/src/WebServer_SysInfoPage.ino b/src/WebServer_SysInfoPage.ino index 618010121..b85f670e3 100644 --- a/src/WebServer_SysInfoPage.ino +++ b/src/WebServer_SysInfoPage.ino @@ -69,7 +69,6 @@ void handle_sysinfo_json() { uint8_t mac[] = { 0, 0, 0, 0, 0, 0 }; -// TODO: PKR: Change to NetworkMacAddress uint8_t *macread = WiFi.macAddress(mac); char macaddress[20]; formatMAC(macread, macaddress); @@ -339,7 +338,11 @@ void handle_sysinfo_Ethernet() { void handle_sysinfo_Network() { addTableSeparator(F("Network"), 2, 3, F("Wifi")); - if (eth_wifi_mode == WIFI && NetworkConnected()) + if ( + #ifdef HAS_ETHERNET + eth_wifi_mode == WIFI && + #endif + NetworkConnected()) { addRowLabel(F("Wifi")); # if defined(ESP8266) @@ -381,7 +384,6 @@ void handle_sysinfo_Network() { { uint8_t mac[] = { 0, 0, 0, 0, 0, 0 }; -// TODO: PKR: Change to NetworkMacAddress uint8_t *macread = WiFi.macAddress(mac); char macaddress[20]; formatMAC(macread, macaddress); diff --git a/src/WebServer_ToolsPage.ino b/src/WebServer_ToolsPage.ino index dfffe2643..3d1824e58 100644 --- a/src/WebServer_ToolsPage.ino +++ b/src/WebServer_ToolsPage.ino @@ -73,7 +73,6 @@ void handle_tools() { addFormSubHeader(F("Wifi")); -// TODO: PKR: Add commands for ETHERNET addWideButtonPlusDescription(F("/?cmd=wificonnect"), F("Connect"), F("Connects to known Wifi network")); addWideButtonPlusDescription(F("/?cmd=wifidisconnect"), F("Disconnect"), F("Disconnect from wifi network")); diff --git a/src/_C014.ino b/src/_C014.ino index abfafe828..1e668d252 100644 --- a/src/_C014.ino +++ b/src/_C014.ino @@ -246,7 +246,6 @@ bool CPlugin_014(CPlugin::Function function, struct EventStruct *event, String& CPlugin_014_sendMQTTdevice(pubname,"$localip",formatIP(NetworkLocalIP()).c_str(),errorCounter); // $mac Device → Controller Mac address of the device network interface. The format MUST be of the type A1:B2:C3:D4:E5:F6 Yes Yes - // TODO: PKR: Change to NetworkMacAddress CPlugin_014_sendMQTTdevice(pubname,"$mac",WiFi.macAddress().c_str(),errorCounter); // $implementation Device → Controller An identifier for the Homie implementation (example esp8266) Yes Yes diff --git a/src/src/DataStructs/ESPEasyDefaults.h b/src/src/DataStructs/ESPEasyDefaults.h index fb3068d2f..8bf9fcf67 100644 --- a/src/src/DataStructs/ESPEasyDefaults.h +++ b/src/src/DataStructs/ESPEasyDefaults.h @@ -190,7 +190,7 @@ #define DEFAULT_ETH_CLOCK_MODE 0 #endif #ifndef DEFAULT_ETH_WIFI_MODE -#define DEFAULT_ETH_WIFI_MODE 1 // TODO: PKR: Change perhaps to 0 +#define DEFAULT_ETH_WIFI_MODE 0 // 0 WIFI // 1 ETHERNET #endif diff --git a/src/src/Helpers/SystemVariables.cpp b/src/src/Helpers/SystemVariables.cpp index 4963d644c..1aab35692 100644 --- a/src/src/Helpers/SystemVariables.cpp +++ b/src/src/Helpers/SystemVariables.cpp @@ -89,6 +89,7 @@ void SystemVariables::parseSystemVariables(String& s, boolean useURLencode) case ISNTP: value = String(statusNTPInitialized); break; case ISWIFI: value = String(wifiStatus); break; // 0=disconnected, 1=connected, 2=got ip, 3=services initialized + // TODO: PKR: Add ETH Objects #ifdef HAS_ETHERNET case ETH_WIFI_MODE: value = (eth_wifi_mode == WIFI ? "WIFI" : "ETHERNET"); break; // 0=WIFI, 1=ETH case ETH_CONNECTED: value = String(eth_connected); break; // 0=disconnected, 1=connected @@ -247,6 +248,7 @@ String SystemVariables::toString(SystemVariables::Enum enumval) case Enum::ISMQTTIMP: return F("%ismqttimp%"); case Enum::ISNTP: return F("%isntp%"); case Enum::ISWIFI: return F("%iswifi%"); + // TODO: PKR: Add ETH Objects #ifdef HAS_ETHERNET case Enum::ETH_WIFI_MODE: return F("%eth_wifi_mode%"); case Enum::ETH_CONNECTED: return F("%eth_connected%"); From a6f75806f0e133631398940963ad1b3c6f38aee3 Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Mon, 27 Apr 2020 21:59:21 +0200 Subject: [PATCH 18/39] - Ethernet Commands - remove useless comments - ETH.config moved after ETH.begin - Added note: Be aware with ESPEasyP2P Network, since IP Address will change. There could be conflicts. - Ethernet JSON - Ethernet Variables --- src/Command.ino | 13 ++++++ src/ESPEasyEth.ino | 38 +++--------------- src/StringProvider.ino | 23 ++++++----- src/StringProviderTypes.h | 1 + src/WebServer_HardwarePage.ino | 1 + src/WebServer_JSON.ino | 18 +++++++++ src/WebServer_SysInfoPage.ino | 11 +++++ src/WebServer_SysVarPage.ino | 17 ++++++-- src/src/Commands/Common.cpp | 60 ++++++++++++++++++++++++++++ src/src/Commands/Common.h | 12 ++++++ src/src/Commands/Networks.cpp | 62 ++++++++++++++++++++++++++++- src/src/Commands/Networks.h | 11 +++++ src/src/Helpers/SystemVariables.cpp | 28 ++++++++++--- src/src/Helpers/SystemVariables.h | 14 ++++++- 14 files changed, 252 insertions(+), 57 deletions(-) diff --git a/src/Command.ino b/src/Command.ino index d43feabfd..57b7f2460 100644 --- a/src/Command.ino +++ b/src/Command.ino @@ -168,6 +168,19 @@ bool executeInternalCommand(const char *cmd, struct EventStruct *event, const ch break; } case 'e': { + #ifdef HAS_ETHERNET + COMMAND_CASE( "ethphyadr", Command_ETH_Phy_Addr, 1); // Network Command + COMMAND_CASE( "ethpinmdc", Command_ETH_Pin_mdc, 1); // Network Command + COMMAND_CASE( "ethpinmdio", Command_ETH_Pin_mdio, 1); // Network Command + COMMAND_CASE( "ethpinpower", Command_ETH_Pin_power, 1); // Network Command + COMMAND_CASE( "ethphytype", Command_ETH_Phy_Type, 1); // Network Command + COMMAND_CASE("ethclockmode", Command_ETH_Clock_Mode, 1); // Network Command + COMMAND_CASE( "ethip", Command_ETH_IP, 1); // Network Command + COMMAND_CASE( "ethgateway", Command_ETH_Gateway, 1); // Network Command + COMMAND_CASE( "ethsubnet", Command_ETH_Subnet, 1); // Network Command + COMMAND_CASE( "ethdns", Command_ETH_DNS, 1); // Network Command + COMMAND_CASE( "ethwifimode", Command_ETH_Wifi_Mode, 1); // Network Command + #endif // HAS_ETHERNET COMMAND_CASE("erasesdkwifi", Command_WiFi_Erase, 0); // WiFi.h COMMAND_CASE( "event", Command_Rules_Events, -1); // Rule.h COMMAND_CASE("executerules", Command_Rules_Execute, -1); // Rule.h diff --git a/src/ESPEasyEth.ino b/src/ESPEasyEth.ino index 4b002528f..11a9759ff 100644 --- a/src/ESPEasyEth.ino +++ b/src/ESPEasyEth.ino @@ -9,10 +9,6 @@ bool ethUseStaticIP() { } void ethSetupStaticIPconfig() { - // TODO: PKR Remove - addLog(LOG_LEVEL_INFO, F("ethSetupStaticIPConfig Started")); - //setUseStaticIP(useStaticIP()); - if (!ethUseStaticIP()) { return; } const IPAddress ip = Settings.ETH_IP; const IPAddress gw = Settings.ETH_Gateway; @@ -30,16 +26,10 @@ void ethSetupStaticIPconfig() { log += formatIP(dns); addLog(LOG_LEVEL_INFO, log); } - // TODO: PKR Remove - addLog(LOG_LEVEL_INFO, F("Before ETH.config")); ETH.config(ip, gw, subnet, dns); - // TODO: PKR Remove - addLog(LOG_LEVEL_INFO, F("After ETH.config")); } bool ethCheckSettings() { - // TODO: PKR Remove - addLog(LOG_LEVEL_INFO, F("ethCheckSettings Started")); bool result = true; if (Settings.ETH_Phy_Type != 0 && Settings.ETH_Phy_Type != 1) result = false; @@ -57,25 +47,17 @@ bool ethCheckSettings() { } bool ethPrepare() { - // TODO: PKR Remove - addLog(LOG_LEVEL_INFO, F("ethPrepare Started")); if (!ethCheckSettings()) { addLog(LOG_LEVEL_ERROR, F("ETH: Settings not correct!!!")); return false; } - // TODO: PKR Remove - addLog(LOG_LEVEL_INFO, F("Before ETH.config")); ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); - // TODO: PKR Remove - addLog(LOG_LEVEL_INFO, F("After ETH.conif")); ethSetupStaticIPconfig(); return true; } String ethGetDebugClockModeStr() { - // TODO: PKR Remove - addLog(LOG_LEVEL_INFO, F("ethDebugColckModeStr Started")); switch (Settings.ETH_Clock_Mode) { case 0: return F("ETH_CLOCK_GPIO0_IN"); @@ -87,8 +69,6 @@ String ethGetDebugClockModeStr() { } String ethGetDebugEthWifiModeStr() { - // TODO: PKR Remove - addLog(LOG_LEVEL_INFO, F("ethGetDebugEthWifiMode Started")); switch (eth_wifi_mode) { case 0: return F("WIFI"); @@ -98,8 +78,6 @@ String ethGetDebugEthWifiModeStr() { } void ethPrintSettings() { - // TODO: PKR Remove - addLog(LOG_LEVEL_INFO, F("ethPrintSettings Started")); String settingsDebugLog; settingsDebugLog.reserve(115); settingsDebugLog += F("Eth Wifi mode: "); @@ -120,25 +98,19 @@ void ethPrintSettings() { } void ETHConnectRelaxed() { - // TODO: PKR Remove - addLog(LOG_LEVEL_INFO, F("ETHConnectRelaxed Started")); ethPrintSettings(); - /*if (!ethPrepare()) { - // Dead code for now... - addLog(LOG_LEVEL_ERROR, F("ETH : Could not prepare ETH!")); - return; - } - // TODO: PKR Remove - addLog(LOG_LEVEL_INFO, F("Before ETH.begin")); ETH.begin(Settings.ETH_Phy_Addr, Settings.ETH_Pin_power, Settings.ETH_Pin_mdc, Settings.ETH_Pin_mdio, (eth_phy_type_t)Settings.ETH_Phy_Type, (eth_clock_mode_t)Settings.ETH_Clock_Mode); - // TODO: PKR Remove*/ - ETH.begin(); addLog(LOG_LEVEL_INFO, F("After ETH.begin")); + if (!ethPrepare()) { + // Dead code for now... + addLog(LOG_LEVEL_ERROR, F("ETH : Could not prepare ETH!")); + return; + } } bool ETHConnected() { diff --git a/src/StringProvider.ino b/src/StringProvider.ino index 947c0fcd7..fbe9602e3 100644 --- a/src/StringProvider.ino +++ b/src/StringProvider.ino @@ -109,6 +109,7 @@ String getLabel(LabelType::Enum label) { case LabelType::ETH_STATE: return F("Eth State"); case LabelType::ETH_SPEED_STATE: return F("Eth Speed State"); case LabelType::ETH_WIFI_MODE: return F("Eth Wifi Mode"); + case LabelType::ETH_CONNECTED: return F("Eth connected"); #endif } @@ -154,10 +155,11 @@ String getValue(LabelType::Enum label) { case LabelType::IP_CONFIG_STATIC: break; case LabelType::IP_CONFIG_DYNAMIC: break; case LabelType::IP_ADDRESS: return NetworkLocalIP().toString(); - case LabelType::IP_SUBNET: return WiFi.subnetMask().toString(); + case LabelType::IP_SUBNET: return NetworkSubnetMask().toString(); case LabelType::IP_ADDRESS_SUBNET: return String(getValue(LabelType::IP_ADDRESS) + F(" / ") + getValue(LabelType::IP_SUBNET)); case LabelType::GATEWAY: return NetworkGatewayIP().toString(); case LabelType::CLIENT_IP: return formatIP(web_server.client().remoteIP()); + #ifdef FEATURE_MDNS case LabelType::M_DNS: return String(WifiGetHostname()) + F(".local"); #endif @@ -215,17 +217,18 @@ String getValue(LabelType::Enum label) { case LabelType::OTA_2STEP: break; case LabelType::OTA_POSSIBLE: break; #ifdef HAS_ETHERNET - case LabelType::ETH_IP_ADDRESS: return ETH.localIP().toString(); - case LabelType::ETH_IP_SUBNET: return ETH.subnetMask().toString(); + case LabelType::ETH_IP_ADDRESS: return NetworkLocalIP().toString(); + case LabelType::ETH_IP_SUBNET: return NetworkSubnetMask().toString(); case LabelType::ETH_IP_ADDRESS_SUBNET: return String(getValue(LabelType::ETH_IP_ADDRESS) + F(" / ") + getValue(LabelType::ETH_IP_SUBNET)); - case LabelType::ETH_IP_GATEWAY: return ETH.gatewayIP().toString(); - case LabelType::ETH_IP_DNS: return ETH.dnsIP().toString(); - case LabelType::ETH_MAC: return ETH.macAddress(); - case LabelType::ETH_DUPLEX: return ETH.fullDuplex() ? F("Full Duplex") : F("Half Duplex"); - case LabelType::ETH_SPEED: return getEthSpeed(); - case LabelType::ETH_STATE: return ETH.linkUp() ? F("Link Up") : F("Link Down"); - case LabelType::ETH_SPEED_STATE: return getEthLinkSpeedState(); + case LabelType::ETH_IP_GATEWAY: return NetworkGatewayIP().toString(); + case LabelType::ETH_IP_DNS: return NetworkDnsIP().toString(); + case LabelType::ETH_MAC: return NetworkMacAddress(); + case LabelType::ETH_DUPLEX: return eth_connected ? (ETH.fullDuplex() ? F("Full Duplex") : F("Half Duplex")) : F("No Ethernet"); + case LabelType::ETH_SPEED: return eth_connected ? getEthSpeed() : F("No Ethernet"); + case LabelType::ETH_STATE: return eth_connected ? (ETH.linkUp() ? F("Link Up") : F("Link Down")) : F("No Ethernet"); + case LabelType::ETH_SPEED_STATE: return eth_connected ? getEthLinkSpeedState() : F("No Ethernet"); case LabelType::ETH_WIFI_MODE: return (eth_wifi_mode == WIFI ? F("WIFI") : F("ETHERNET")); + case LabelType::ETH_CONNECTED: return String(eth_connected); // 0=disconnected, 1=connected #endif } diff --git a/src/StringProviderTypes.h b/src/StringProviderTypes.h index 65f9373a4..0ced1ae16 100644 --- a/src/StringProviderTypes.h +++ b/src/StringProviderTypes.h @@ -109,6 +109,7 @@ enum Enum : short { ETH_STATE, ETH_SPEED_STATE, ETH_WIFI_MODE, + ETH_CONNECTED, #endif }; diff --git a/src/WebServer_HardwarePage.ino b/src/WebServer_HardwarePage.ino index f143be84d..71a5a2541 100644 --- a/src/WebServer_HardwarePage.ino +++ b/src/WebServer_HardwarePage.ino @@ -90,6 +90,7 @@ void handle_hardware() { String ethWifiOptions[2] = { F("WIFI"), F("ETHERNET") }; addSelector("ethwifi", 2, ethWifiOptions, NULL, NULL, Settings.ETH_Wifi_Mode, false, true); addFormNote(F("Change Switch between WIFI and ETHERNET requires reboot to activate")); + addFormNote(F("Be aware with ESPEasyP2P Network, since IP Address will change. There could be conflicts.")); addRowLabel_tr_id(F("Ethernet PHY type"), "ethtype"); String ethPhyTypes[2] = { F("LAN8710"), F("TLK110") }; addSelector("ethtype", 2, ethPhyTypes, NULL, NULL, Settings.ETH_Phy_Type, false, true); diff --git a/src/WebServer_JSON.ino b/src/WebServer_JSON.ino index 7e3ed9b04..b4364addc 100644 --- a/src/WebServer_JSON.ino +++ b/src/WebServer_JSON.ino @@ -13,6 +13,9 @@ void handle_json() const bool showSpecificTask = validTaskIndex(taskNr); bool showSystem = true; bool showWifi = true; + #ifdef HAS_ETHERNET + bool showEthernet = true; + #endif bool showDataAcquisition = true; bool showTaskDetails = true; bool showNodes = true; @@ -23,6 +26,9 @@ void handle_json() if (view == F("sensorupdate")) { showSystem = false; showWifi = false; + #ifdef HAS_ETHERNET + showEthernet = false; + #endif showDataAcquisition = false; showTaskDetails = false; showNodes = false; @@ -101,6 +107,18 @@ void handle_json() addHtml(F(",\n")); } + #ifdef HAS_ETHERNET + if (showEthernet) { + addHtml(F("\"Ethernet\":{\n")); + stream_next_json_object_value(LabelType::ETH_WIFI_MODE); + stream_next_json_object_value(LabelType::ETH_CONNECTED); + stream_next_json_object_value(LabelType::ETH_DUPLEX); + stream_next_json_object_value(LabelType::ETH_SPEED); + stream_next_json_object_value(LabelType::ETH_STATE); + stream_last_json_object_value(LabelType::ETH_SPEED_STATE); + } + #endif + if (showNodes) { bool comma_between = false; diff --git a/src/WebServer_SysInfoPage.ino b/src/WebServer_SysInfoPage.ino index b85f670e3..ebc5b6a29 100644 --- a/src/WebServer_SysInfoPage.ino +++ b/src/WebServer_SysInfoPage.ino @@ -87,6 +87,17 @@ void handle_sysinfo_json() { json_number(F("reconnects"), String(wifi_reconnects)); json_close(); +#ifdef HAS_ETHERNET + json_open(false, F("ethernet")); + json_prop(F("ethwifimode"), getValue(LabelType::ETH_WIFI_MODE)); + json_prop(F("ethconnected"), getValue(LabelType::ETH_CONNECTED); + json_prop(F("ethduplex"), getValue(LabelType::ETH_DUPLEX); + json_prop(F("ethspeed"), getValue(LabelType::ETH_SPEED); + json_prop(F("ethstate"), getValue(LabelType::ETH_STATE); + json_prop(F("ethspeedstate"), getValue(LabelType::ETH_SPEED_STATE); + json.close(); +#endif + json_open(false, F("firmware")); json_prop(F("build"), String(BUILD)); json_prop(F("notes"), F(BUILD_NOTES)); diff --git a/src/WebServer_SysVarPage.ino b/src/WebServer_SysVarPage.ino index a434381fe..f0e70f2e8 100644 --- a/src/WebServer_SysVarPage.ino +++ b/src/WebServer_SysVarPage.ino @@ -44,11 +44,24 @@ void handle_sysvars() { #endif // if defined(ESP8266) addSysVar_enum_html(SystemVariables::IP); addSysVar_enum_html(SystemVariables::IP4); + addSysVar_enum_html(SystemVariables::SUBNET); + addSysVar_enum_html(SystemVariables::GATEWAY); + addSysVar_enum_html(SystemVariables::DNS); addSysVar_enum_html(SystemVariables::RSSI); addSysVar_enum_html(SystemVariables::SSID); addSysVar_enum_html(SystemVariables::BSSID); addSysVar_enum_html(SystemVariables::WI_CH); +#ifdef HAS_ETHERNET + addTableSeparator(F("Ethernet"), 3, 3); + addSysVar_enum_html(SystemVariables::ETHWIFIMODE); + addSysVar_enum_html(SystemVariables::ETHCONNECTED); + addSysVar_enum_html(SystemVariables::ETHDUPLEX); + addSysVar_enum_html(SystemVariables::ETHSPEED); + addSysVar_enum_html(SystemVariables::ETHSTATE); + addSysVar_enum_html(SystemVariables::ETHSPEEDSTATE); + #endif + addTableSeparator(F("System"), 3, 3); addSysVar_enum_html(SystemVariables::UNIT_sysvar); addSysVar_enum_html(SystemVariables::SYSLOAD); @@ -62,10 +75,6 @@ void handle_sysvars() { addTableSeparator(F("System status"), 3, 3); addSysVar_enum_html(SystemVariables::ISWIFI); - #ifdef HAS_ETHERNET - addSysVar_enum_html(SystemVariables::ETH_WIFI_MODE); - addSysVar_enum_html(SystemVariables::ETH_CONNECTED); - #endif addSysVar_enum_html(SystemVariables::ISNTP); addSysVar_enum_html(SystemVariables::ISMQTT); #ifdef USES_P037 diff --git a/src/src/Commands/Common.cpp b/src/src/Commands/Common.cpp index 0df55f0ab..79113e08a 100644 --- a/src/src/Commands/Common.cpp +++ b/src/src/Commands/Common.cpp @@ -153,3 +153,63 @@ String Command_GetORSetBool(struct EventStruct *event, } return return_command_success(); } + +String Command_GetORSetUint8_t(struct EventStruct *event, + const String & targetDescription, + const char *Line, + uint8_t *value, + int arg) +{ + bool hasArgument = false; + { + // Check if command is valid. Leave in separate scope to delete the TmpStr1 + String TmpStr1; + + if (GetArgv(Line, TmpStr1, arg + 1)) { + hasArgument = true; + TmpStr1.toLowerCase(); + + if (isInt(TmpStr1)) { + *value = (uint8_t)atoi(TmpStr1.c_str()); + } + else if (strcmp_P(PSTR("WIFI"), TmpStr1.c_str()) == 0) { *value = 0; } + else if (strcmp_P(PSTR("ETHERNET"), TmpStr1.c_str()) == 0) { *value = 1; } + } + } + + if (hasArgument) { + String result = targetDescription; + result += *value; + return return_result(event, result); + } + return return_command_success(); +} + +String Command_GetORSetInt8_t(struct EventStruct *event, + const String & targetDescription, + const char *Line, + int8_t *value, + int arg) +{ + bool hasArgument = false; + { + // Check if command is valid. Leave in separate scope to delete the TmpStr1 + String TmpStr1; + + if (GetArgv(Line, TmpStr1, arg + 1)) { + hasArgument = true; + TmpStr1.toLowerCase(); + + if (isInt(TmpStr1)) { + *value = (int8_t)atoi(TmpStr1.c_str()); + } + } + } + + if (hasArgument) { + String result = targetDescription; + result += *value; + return return_result(event, result); + } + return return_command_success(); +} diff --git a/src/src/Commands/Common.h b/src/src/Commands/Common.h index 4fc0e86f6..014d870f8 100644 --- a/src/src/Commands/Common.h +++ b/src/src/Commands/Common.h @@ -37,4 +37,16 @@ String Command_GetORSetBool(struct EventStruct *event, bool *value, int arg); +String Command_GetORSetUint8_t(struct EventStruct *event, + const String & targetDescription, + const char *Line, + uint8_t *value, + int arg); + +String Command_GetORSetInt8_t(struct EventStruct *event, + const String & targetDescription, + const char *Line, + int8_t *value, + int arg); + #endif // COMMAND_COMMON_H diff --git a/src/src/Commands/Networks.cpp b/src/src/Commands/Networks.cpp index a1c2a36e7..24bf82613 100644 --- a/src/src/Commands/Networks.cpp +++ b/src/src/Commands/Networks.cpp @@ -5,7 +5,7 @@ #include "../Globals/Settings.h" #include "../../ESPEasy_fdwdecl.h" - +#include "ETH.h" String Command_AccessInfo_Ls(struct EventStruct *event, const char* Line) { @@ -38,4 +38,62 @@ String Command_IP (struct EventStruct *event, const char* Line) String Command_Subnet (struct EventStruct *event, const char* Line) { return Command_GetORSetIP(event, F("Subnet:"), Line, Settings.Subnet,WiFi.subnetMask(),1); -} \ No newline at end of file +} + +#ifdef HAS_ETHERNET +String Command_ETH_Phy_Addr (struct EventStruct *event, const char* Line) +{ + return Command_GetORSetUint8_t(event, F("ETH_Phy_Addr:"), Line, (uint8_t*)&Settings.ETH_Phy_Addr,1); +} + +String Command_ETH_Pin_mdc (struct EventStruct *event, const char* Line) +{ + return Command_GetORSetInt8_t(event, F("ETH_Pin_mdc:"), Line, (int8_t*)&Settings.ETH_Pin_mdc,1); +} + +String Command_ETH_Pin_mdio (struct EventStruct *event, const char* Line) +{ + return Command_GetORSetInt8_t(event, F("ETH_Pin_mdio:"), Line, (int8_t*)&Settings.ETH_Pin_mdio,1); +} + +String Command_ETH_Pin_power (struct EventStruct *event, const char* Line) +{ + return Command_GetORSetInt8_t(event, F("ETH_Pin_power:"), Line, (int8_t*)&Settings.ETH_Pin_power,1); +} + +String Command_ETH_Phy_Type (struct EventStruct *event, const char* Line) +{ + return Command_GetORSetInt8_t(event, F("ETH_Phy_Type:"), Line, (int8_t*)&Settings.ETH_Phy_Type,1); +} + +String Command_ETH_Clock_Mode (struct EventStruct *event, const char* Line) +{ + return Command_GetORSetUint8_t(event, F("ETH_Clock_Mode:"), Line, (uint8_t*)&Settings.ETH_Clock_Mode,1); +} + +String Command_ETH_IP (struct EventStruct *event, const char* Line) +{ + return Command_GetORSetIP(event, F("ETH_IP:"), Line, Settings.ETH_IP,ETH.localIP(),1); +} + +String Command_ETH_Gateway (struct EventStruct *event, const char* Line) +{ + return Command_GetORSetIP(event, F("ETH_Gateway:"), Line, Settings.ETH_Gateway,ETH.gatewayIP(),1); +} + +String Command_ETH_Subnet (struct EventStruct *event, const char* Line) +{ + return Command_GetORSetIP(event, F("ETH_Subnet:"), Line, Settings.ETH_Subnet,ETH.subnetMask(),1); +} + +String Command_ETH_DNS (struct EventStruct *event, const char* Line) +{ + return Command_GetORSetIP(event, F("ETH_DNS:"), Line, Settings.ETH_DNS,ETH.dnsIP(),1); +} + +String Command_ETH_Wifi_Mode (struct EventStruct *event, const char* Line) +{ + return Command_GetORSetUint8_t(event, F("ETH_Wifi_Mode:"), Line, (uint8_t*)&Settings.ETH_Wifi_Mode,1); +} + +#endif \ No newline at end of file diff --git a/src/src/Commands/Networks.h b/src/src/Commands/Networks.h index 4a55c7676..1b6745f52 100644 --- a/src/src/Commands/Networks.h +++ b/src/src/Commands/Networks.h @@ -10,5 +10,16 @@ String Command_DNS (struct EventStruct *event, const char* Line); String Command_Gateway (struct EventStruct *event, const char* Line); String Command_IP (struct EventStruct *event, const char* Line); String Command_Subnet (struct EventStruct *event, const char* Line); +String Command_ETH_Phy_Addr (struct EventStruct *event, const char* Line); +String Command_ETH_Pin_mdc (struct EventStruct *event, const char* Line); +String Command_ETH_Pin_mdio (struct EventStruct *event, const char* Line); +String Command_ETH_Pin_power (struct EventStruct *event, const char* Line); +String Command_ETH_Phy_Type (struct EventStruct *event, const char* Line); +String Command_ETH_Clock_Mode (struct EventStruct *event, const char* Line); +String Command_ETH_IP (struct EventStruct *event, const char* Line); +String Command_ETH_Gateway (struct EventStruct *event, const char* Line); +String Command_ETH_Subnet (struct EventStruct *event, const char* Line); +String Command_ETH_DNS (struct EventStruct *event, const char* Line); +String Command_ETH_Wifi_Mode (struct EventStruct *event, const char* Line); #endif // COMMAND_NETWORKS_H diff --git a/src/src/Helpers/SystemVariables.cpp b/src/src/Helpers/SystemVariables.cpp index 1aab35692..96d09811f 100644 --- a/src/src/Helpers/SystemVariables.cpp +++ b/src/src/Helpers/SystemVariables.cpp @@ -73,7 +73,11 @@ void SystemVariables::parseSystemVariables(String& s, boolean useURLencode) case BSSID: value = String((wifiStatus == ESPEASY_WIFI_DISCONNECTED) ? F("00:00:00:00:00:00") : WiFi.BSSIDstr()); break; case CR: value = "\r"; break; case IP: value = getValue(LabelType::IP_ADDRESS); break; - case IP4: value = String( (int) WiFi.localIP()[3] ); break; // 4th IP octet + case IP4: value = String( (int) NetworkLocalIP()[3] ); break; // 4th IP octet + case SUBNET: value = getValue(LabelType::IP_SUBNET); break; + case DNS: value = getValue(LabelType::DNS); break; + case GATEWAY: value = getValue(LabelType::GATEWAY); break; + case CLIENTIP: value = getValue(LabelType::CLIENT_IP); break; #ifdef USES_MQTT case ISMQTT: value = String(MQTTclient_connected); break; #else // ifdef USES_MQTT @@ -91,8 +95,13 @@ void SystemVariables::parseSystemVariables(String& s, boolean useURLencode) case ISWIFI: value = String(wifiStatus); break; // 0=disconnected, 1=connected, 2=got ip, 3=services initialized // TODO: PKR: Add ETH Objects #ifdef HAS_ETHERNET - case ETH_WIFI_MODE: value = (eth_wifi_mode == WIFI ? "WIFI" : "ETHERNET"); break; // 0=WIFI, 1=ETH - case ETH_CONNECTED: value = String(eth_connected); break; // 0=disconnected, 1=connected + + case ETHWIFIMODE: value = getValue(LabelType::ETH_WIFI_MODE); break; // 0=WIFI, 1=ETH + case ETHCONNECTED: value = getValue(LabelType::ETH_CONNECTED); break; // 0=disconnected, 1=connected + case ETHDUPLEX: value = getValue(LabelType::ETH_DUPLEX); break; + case ETHSPEED: value = getValue(LabelType::ETH_SPEED); break; + case ETHSTATE: value = getValue(LabelType::ETH_STATE); break; + case ETHSPEEDSTATE: value = getValue(LabelType::ETH_SPEED_STATE); break; #endif case LCLTIME: value = getValue(LabelType::LOCAL_TIME); break; case LCLTIME_AM: value = node_time.getDateTimeString_ampm('-', ':', ' '); break; @@ -244,14 +253,21 @@ String SystemVariables::toString(SystemVariables::Enum enumval) case Enum::CR: return F("%CR%"); case Enum::IP4: return F("%ip4%"); case Enum::IP: return F("%ip%"); + case Enum::SUBNET: return F("%subnet%"); + case Enum::DNS: return F("%dns%"); + case Enum::GATEWAY: return F("%gateway%"); + case Enum::CLIENTIP: return F("%clientip%"); case Enum::ISMQTT: return F("%ismqtt%"); case Enum::ISMQTTIMP: return F("%ismqttimp%"); case Enum::ISNTP: return F("%isntp%"); case Enum::ISWIFI: return F("%iswifi%"); - // TODO: PKR: Add ETH Objects #ifdef HAS_ETHERNET - case Enum::ETH_WIFI_MODE: return F("%eth_wifi_mode%"); - case Enum::ETH_CONNECTED: return F("%eth_connected%"); + case Enum::ETHWIFIMODE: return F("%ethwifimode%"); + case Enum::ETHCONNECTED: return F("%ethconnected%"); + case Enum::ETHDUPLEX: return F("%ethduplex%"); + case Enum::ETHSPEED: return F("%ethspeed%"); + case Enum::ETHSTATE: return F("%ethstate%"); + case Enum::ETHSPEEDSTATE: return F("%ethspeedstate%"); #endif case Enum::LCLTIME: return F("%lcltime%"); case Enum::LCLTIME_AM: return F("%lcltime_am%"); diff --git a/src/src/Helpers/SystemVariables.h b/src/src/Helpers/SystemVariables.h index ec24e684b..d44920ce7 100644 --- a/src/src/Helpers/SystemVariables.h +++ b/src/src/Helpers/SystemVariables.h @@ -13,12 +13,22 @@ public: CR, IP, IP4, // 4th IP octet + SUBNET, + GATEWAY, + DNS, + CLIENTIP, ISMQTT, ISMQTTIMP, ISNTP, ISWIFI, - ETH_WIFI_MODE, - ETH_CONNECTED, + #ifdef HAS_ETHERNET + ETHWIFIMODE, + ETHCONNECTED, + ETHDUPLEX, + ETHSPEED, + ETHSTATE, + ETHSPEEDSTATE, + #endif LCLTIME, LCLTIME_AM, LF, From 24d9dc19a46f60fdb0904a2f736618718ee2ab2e Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Mon, 27 Apr 2020 22:18:55 +0200 Subject: [PATCH 19/39] - ETHEvents moved to WifiEvents, because they are the same type --- src/ESPEasy.ino | 4 ---- src/ESPEasyEthEvent.ino | 50 ---------------------------------------- src/ESPEasyWiFiEvent.cpp | 44 +++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 54 deletions(-) delete mode 100644 src/ESPEasyEthEvent.ino diff --git a/src/ESPEasy.ino b/src/ESPEasy.ino index 8234a7b44..0f55651d0 100644 --- a/src/ESPEasy.ino +++ b/src/ESPEasy.ino @@ -380,10 +380,6 @@ void setup() rulesProcessing(event); // TD-er: Process events in the setup() now. } - #ifdef HAS_ETHERNET - WiFi.onEvent(ETHEvent); - #endif - NetworkConnectRelaxed(); setWebserverRunning(true); diff --git a/src/ESPEasyEthEvent.ino b/src/ESPEasyEthEvent.ino deleted file mode 100644 index 036bdc4af..000000000 --- a/src/ESPEasyEthEvent.ino +++ /dev/null @@ -1,50 +0,0 @@ -#ifdef HAS_ETHERNET -void ETHEvent(WiFiEvent_t event) -{ - switch (event) { - case SYSTEM_EVENT_ETH_START: - addLog(LOG_LEVEL_INFO, F("ETH Started")); - char hostname[40]; - safe_strncpy(hostname, createRFCCompliantHostname(WifiGetAPssid()).c_str(), sizeof(hostname)); - ETH.setHostname(hostname); - { - String log = F("ETH Hostname: "); - log += String(hostname); - addLog(LOG_LEVEL_INFO, log); - } - break; - case SYSTEM_EVENT_ETH_CONNECTED: - addLog(LOG_LEVEL_INFO, F("ETH Connected")); - break; - case SYSTEM_EVENT_ETH_GOT_IP: - { - String log = F("ETH MAC: "); - log += ETH.macAddress(); - log += F(", IPv4: "); - log += ETH.localIP().toString(); - if (ETH.fullDuplex()) { - log += F(", FULL_DUPLEX"); - } - log += F(", "); - log += ETH.linkSpeed(); - log += F("Mbps"); - addLog(LOG_LEVEL_INFO, log); - } - eth_connected = true; - break; - case SYSTEM_EVENT_ETH_DISCONNECTED: - addLog(LOG_LEVEL_ERROR, F("ETH Disconnected")); - eth_connected = false; - break; - case SYSTEM_EVENT_ETH_STOP: - addLog(LOG_LEVEL_INFO, F("ETH Stopped")); - eth_connected = false; - break; - case SYSTEM_EVENT_GOT_IP6: - addLog(LOG_LEVEL_INFO, F("ETH Got IP6")); - break; - default: - break; - } -} -#endif \ No newline at end of file diff --git a/src/ESPEasyWiFiEvent.cpp b/src/ESPEasyWiFiEvent.cpp index 2892a21aa..39319c7ae 100644 --- a/src/ESPEasyWiFiEvent.cpp +++ b/src/ESPEasyWiFiEvent.cpp @@ -4,6 +4,7 @@ #include "src/Globals/RTC.h" #include "ESPEasyTimeTypes.h" #include "ESPEasy_Log.h" +#include "ESPEasy_fdwdecl.h" #include "src/DataStructs/RTCStruct.h" @@ -105,6 +106,49 @@ void WiFiEvent(system_event_id_t event, system_event_info_t info) { case SYSTEM_EVENT_SCAN_DONE: processedScanDone = false; break; +#ifdef HAS_ETHERNET + case SYSTEM_EVENT_ETH_START: + addLog(LOG_LEVEL_INFO, F("ETH Started")); + char hostname[40]; + safe_strncpy(hostname, createRFCCompliantHostname(WifiGetAPssid()).c_str(), sizeof(hostname)); + ETH.setHostname(hostname); + { + String log = F("ETH Hostname: "); + log += String(hostname); + addLog(LOG_LEVEL_INFO, log); + } + break; + case SYSTEM_EVENT_ETH_CONNECTED: + addLog(LOG_LEVEL_INFO, F("ETH Connected")); + break; + case SYSTEM_EVENT_ETH_GOT_IP: + { + String log = F("ETH MAC: "); + log += ETH.macAddress(); + log += F(", IPv4: "); + log += ETH.localIP().toString(); + if (ETH.fullDuplex()) { + log += F(", FULL_DUPLEX"); + } + log += F(", "); + log += ETH.linkSpeed(); + log += F("Mbps"); + addLog(LOG_LEVEL_INFO, log); + } + eth_connected = true; + break; + case SYSTEM_EVENT_ETH_DISCONNECTED: + addLog(LOG_LEVEL_ERROR, F("ETH Disconnected")); + eth_connected = false; + break; + case SYSTEM_EVENT_ETH_STOP: + addLog(LOG_LEVEL_INFO, F("ETH Stopped")); + eth_connected = false; + break; + case SYSTEM_EVENT_GOT_IP6: + addLog(LOG_LEVEL_INFO, F("ETH Got IP6")); + break; +#endif //HAS_ETHERNET default: break; } From 6585a48f396a7a838b1a87abc24437c244673a1f Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Mon, 27 Apr 2020 22:56:26 +0200 Subject: [PATCH 20/39] ESPEasyEth.ino --> ESPEasyEth.cpp/h Network.ino --> Network.cpp/h --- src/{ESPEasyEth.ino => ESPEasyEth.cpp} | 1 + src/ESPEasyEth.h | 16 ++++++++++++++++ src/ESPEasy_fdwdecl.h | 2 ++ src/{Network.ino => Network.cpp} | 16 ++++++++-------- src/Network.h | 16 ++++++++++++++++ src/StringProvider.ino | 1 + 6 files changed, 44 insertions(+), 8 deletions(-) rename src/{ESPEasyEth.ino => ESPEasyEth.cpp} (99%) create mode 100644 src/ESPEasyEth.h rename src/{Network.ino => Network.cpp} (88%) create mode 100644 src/Network.h diff --git a/src/ESPEasyEth.ino b/src/ESPEasyEth.cpp similarity index 99% rename from src/ESPEasyEth.ino rename to src/ESPEasyEth.cpp index 11a9759ff..e6b340911 100644 --- a/src/ESPEasyEth.ino +++ b/src/ESPEasyEth.cpp @@ -1,3 +1,4 @@ +#include "ESPEasyEth.h" #ifdef HAS_ETHERNET diff --git a/src/ESPEasyEth.h b/src/ESPEasyEth.h new file mode 100644 index 000000000..a0bf7c8b2 --- /dev/null +++ b/src/ESPEasyEth.h @@ -0,0 +1,16 @@ +#ifndef ESPEASY_ETH_H +#define ESPEASY_ETH_H + +#include "ESPEasy_common.h" + +bool ethUseStaticIP(); +void ethSetupStaticIPconfig(); +bool ethCheckSettings(); +bool ethPrepare(); +String ethGetDebugClockModeStr(); +String ethGetDebugEthWifiModeStr(); +void ethPrintSettings(); +void ETHConnectRelaxed(); +bool ETHConnected(); + +#endif // ESPEASY_ETH_H \ No newline at end of file diff --git a/src/ESPEasy_fdwdecl.h b/src/ESPEasy_fdwdecl.h index f1880a48f..3eeb16ddf 100644 --- a/src/ESPEasy_fdwdecl.h +++ b/src/ESPEasy_fdwdecl.h @@ -203,6 +203,8 @@ uint8_t * NetworkMacAddressAsBytes(uint8_t* mac); String NetworkMacAddress(); String WifiGetAPssid(); String createRFCCompliantHostname(String oldString); +void WiFiConnectRelaxed(); +bool WiFiConnected(); #include "src/Globals/ESPEasyWiFiEvent.h" diff --git a/src/Network.ino b/src/Network.cpp similarity index 88% rename from src/Network.ino rename to src/Network.cpp index bb8060651..77ecf9ccc 100644 --- a/src/Network.ino +++ b/src/Network.cpp @@ -1,14 +1,14 @@ -//#include "Network.h" +#include "Network.h" -/*#include "ESPEasy_fdwdecl.h" +#include "ESPEasy_fdwdecl.h" +#include "ESPEasy-Globals.h" #include "ESPEasy_Log.h" -#include "ESPEasy_common.h" -#include "src/Globals/Settings.h" -#include "src/DataStructs/TimingStats.h" +#include "ESPEasyEth.h" +//#include "ESPEasy_common.h" +//#include "src/Globals/Settings.h" +//#include "src/DataStructs/TimingStats.h" -#include "ESPEasyEth.ino" -#include "ESPEasyWifi.ino" -#include "ESPEasyWifi_ProcessEvent.ino"*/ +#include "ETH.h" /*********************************************************************************************\ Ethernet or Wifi Support for ESP32 Build flag HAS_ETHERNET diff --git a/src/Network.h b/src/Network.h new file mode 100644 index 000000000..90f5c316b --- /dev/null +++ b/src/Network.h @@ -0,0 +1,16 @@ +#ifndef NETWORK_H +#define NETWORK_H + +#include "ESPEasy_common.h" + +void NetworkConnectRelaxed(); +bool NetworkConnected(); +IPAddress NetworkLocalIP(); +IPAddress NetworkSubnetMask(); +IPAddress NetworkGatewayIP(); +IPAddress NetworkDnsIP (uint8_t dns_no); +uint8_t * NetworkMacAddressAsBytes(uint8_t* mac); +String NetworkMacAddress(); + + +#endif // NETWORK_H \ No newline at end of file diff --git a/src/StringProvider.ino b/src/StringProvider.ino index fbe9602e3..4945a5b95 100644 --- a/src/StringProvider.ino +++ b/src/StringProvider.ino @@ -1,4 +1,5 @@ #include "StringProviderTypes.h" +#include "ETH.h" String getInternalLabel(LabelType::Enum label, char replaceSpace) { return to_internal_string(getLabel(label), replaceSpace); From a489b41230c158f6a7b9c07db57041e8d9384507 Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Tue, 28 Apr 2020 19:44:26 +0200 Subject: [PATCH 21/39] ESPEasyWiFi_credentials.ino --> cpp/h ESPEasyWiFi_ProcessEvent.ino --> cpp/h ESPEasyWiFi.ino --> cpp/h --- src/ESPEasy.ino | 2 + src/ESPEasyEth_ProcessEvent.ino | 426 ------------------ src/ESPEasyStorage.ino | 1 + ...ntials.ino => ESPEasyWiFi_credentials.cpp} | 4 + src/ESPEasyWiFi_credentials.h | 11 + src/{ESPEasyWifi.ino => ESPEasyWifi.cpp} | 11 +- src/ESPEasyWifi.h | 44 ++ ...Event.ino => ESPEasyWifi_ProcessEvent.cpp} | 10 + src/ESPEasyWifi_ProcessEvent.h | 15 + src/ESPEasy_fdwdecl.h | 21 +- src/Network.cpp | 5 - src/StringProvider.ino | 2 +- 12 files changed, 105 insertions(+), 447 deletions(-) delete mode 100644 src/ESPEasyEth_ProcessEvent.ino rename src/{ESPEasyWiFi_credentials.ino => ESPEasyWiFi_credentials.cpp} (92%) create mode 100644 src/ESPEasyWiFi_credentials.h rename src/{ESPEasyWifi.ino => ESPEasyWifi.cpp} (98%) create mode 100644 src/ESPEasyWifi.h rename src/{ESPEasyWifi_ProcessEvent.ino => ESPEasyWifi_ProcessEvent.cpp} (97%) create mode 100644 src/ESPEasyWifi_ProcessEvent.h diff --git a/src/ESPEasy.ino b/src/ESPEasy.ino index 0f55651d0..33034c9dc 100644 --- a/src/ESPEasy.ino +++ b/src/ESPEasy.ino @@ -118,6 +118,8 @@ #include "src/Globals/Services.h" #include "src/Globals/Settings.h" #include "src/Globals/Statistics.h" +#include "ESPEasyWiFi_credentials.h" +#include "ESPEasyWifi_ProcessEvent.h" #if FEATURE_ADC_VCC ADC_MODE(ADC_VCC); diff --git a/src/ESPEasyEth_ProcessEvent.ino b/src/ESPEasyEth_ProcessEvent.ino deleted file mode 100644 index 6353cc88e..000000000 --- a/src/ESPEasyEth_ProcessEvent.ino +++ /dev/null @@ -1,426 +0,0 @@ -#include "src/Globals/ESPEasyWiFiEvent.h" - -/* -bool unprocessedWifiEvents() { - if (processedConnect && processedDisconnect && processedGotIP && processedDHCPTimeout) - { - return false; - } - return true; -} - -// ******************************************************************************** -// Called from the loop() to make sure events are processed as soon as possible. -// These functions are called from Setup() or Loop() and thus may call delay() or yield() -// ******************************************************************************** -void handle_unprocessedWiFiEvents() -{ - if (WiFi.status() == WL_DISCONNECTED) { - delay(100); - } - - if ((wifiStatus != ESPEASY_WIFI_SERVICES_INITIALIZED) || unprocessedWifiEvents()) { - // WiFi connection is not yet available, so introduce some extra delays to - // help the background tasks managing wifi connections - delay(1); - - if (wifiConnectAttemptNeeded) { - WiFiConnectRelaxed(); - } - - // Process disconnect events before connect events. - if (!processedDisconnect) { - #ifndef BUILD_NO_DEBUG - addLog(LOG_LEVEL_DEBUG, F("WIFI : Entering processDisconnect()")); - #endif // ifndef BUILD_NO_DEBUG - processDisconnect(); - } - - if (!processedConnect) { - #ifndef BUILD_NO_DEBUG - addLog(LOG_LEVEL_DEBUG, F("WIFI : Entering processConnect()")); - #endif // ifndef BUILD_NO_DEBUG - processConnect(); - } - - if (!processedGotIP) { - #ifndef BUILD_NO_DEBUG - addLog(LOG_LEVEL_DEBUG, F("WIFI : Entering processGotIP()")); - #endif // ifndef BUILD_NO_DEBUG - processGotIP(); - } - - if (!processedDHCPTimeout) { - #ifndef BUILD_NO_DEBUG - addLog(LOG_LEVEL_DEBUG, F("WIFI : DHCP timeout, Calling disconnect()")); - #endif // ifndef BUILD_NO_DEBUG - processedDHCPTimeout = true; - processDisconnect(); - } - - if (wifiStatus & ESPEASY_WIFI_CONNECTED) { - // The actual connection has been made, no need to wait for IP to release this semaphore. - wifiConnectInProgress = false; - } - - if ((wifiStatus & ESPEASY_WIFI_GOT_IP) && (wifiStatus & ESPEASY_WIFI_CONNECTED) && WiFi.isConnected()) { - markWiFi_services_initialized(); - } - } else if (!WiFiConnected()) { - // Somehow the WiFi has entered a limbo state. - // FIXME TD-er: This may happen on WiFi config with AP_STA mode active. - // addLog(LOG_LEVEL_ERROR, F("Wifi status out sync")); - // resetWiFi(); - if (loglevelActiveFor(LOG_LEVEL_ERROR)) { - String wifilog = F("WIFI : Wifi status out sync WiFi.status() = "); - wifilog += String(WiFi.status()); - - addLog(LOG_LEVEL_ERROR, wifilog); - } - } - - if (wifiStatus == ESPEASY_WIFI_DISCONNECTED) { - #ifndef BUILD_NO_DEBUG - - if (loglevelActiveFor(LOG_LEVEL_DEBUG)) { - String wifilog = F("WIFI : Disconnected: WiFi.status() = "); - wifilog += String(WiFi.status()); - - addLog(LOG_LEVEL_DEBUG, wifilog); - } - #endif // ifndef BUILD_NO_DEBUG - - // While connecting to WiFi make sure the device has ample time to do so - delay(10); - } - - if (!processedDisconnectAPmode) { processDisconnectAPmode(); } - - if (!processedConnectAPmode) { processConnectAPmode(); } - - if (timerAPoff != 0) { processDisableAPmode(); } - - if (!processedScanDone) { processScanDone(); } - - if (wifi_connect_attempt > 0) { - // We only want to clear this counter if the connection is currently stable. - if (wifiStatus == ESPEASY_WIFI_SERVICES_INITIALIZED) { - if (timePassedSince(lastConnectMoment) > WIFI_CONNECTION_CONSIDERED_STABLE) { - // Connection considered stable - wifi_connect_attempt = 0; - - if (!WiFi.getAutoConnect()) { - WiFi.setAutoConnect(true); - } - } else { - if (WiFi.getAutoConnect()) { - WiFi.setAutoConnect(false); - } - } - } - } -} - -// ******************************************************************************** -// Functions to process the data gathered from the events. -// These functions are called from Setup() or Loop() and thus may call delay() or yield() -// ******************************************************************************** -void processDisconnect() { - if (processedDisconnect) { return; } - processedDisconnect = true; - wifiStatus = ESPEASY_WIFI_DISCONNECTED; -// setWebserverRunning(false); - delay(100); // FIXME TD-er: See https://github.com/letscontrolit/ESPEasy/issues/1987#issuecomment-451644424 - - if (Settings.UseRules) { - eventQueue.add(F("WiFi#Disconnected")); - } - - if (loglevelActiveFor(LOG_LEVEL_INFO)) { - String log = F("WIFI : Disconnected! Reason: '"); - log += getLastDisconnectReason(); - log += '\''; - - if (lastConnectedDuration > 0) { - log += F(" Connected for "); - log += format_msec_duration(lastConnectedDuration); - } - addLog(LOG_LEVEL_INFO, log); - } - - if (Settings.WiFiRestart_connection_lost()) { - setWifiMode(WIFI_OFF); - delay(100); - } - logConnectionStatus(); -} - -void processConnect() { - if (processedConnect) { return; } - processedConnect = true; - wifiStatus |= ESPEASY_WIFI_CONNECTED; - delay(100); // FIXME TD-er: See https://github.com/letscontrolit/ESPEasy/issues/1987#issuecomment-451644424 - ++wifi_reconnects; - - if (wifiStatus < ESPEASY_WIFI_CONNECTED) { return; } - - if (loglevelActiveFor(LOG_LEVEL_INFO)) { - const long connect_duration = timeDiff(last_wifi_connect_attempt_moment, lastConnectMoment); - String log = F("WIFI : Connected! AP: "); - log += WiFi.SSID(); - log += " ("; - log += WiFi.BSSIDstr(); - log += F(") Ch: "); - log += RTC.lastWiFiChannel; - - if ((connect_duration > 0) && (connect_duration < 30000)) { - // Just log times when they make sense. - log += F(" Duration: "); - log += connect_duration; - log += F(" ms"); - } - addLog(LOG_LEVEL_INFO, log); - } - - if (Settings.UseRules) { - if (bssid_changed) { - eventQueue.add(F("WiFi#ChangedAccesspoint")); - } - - if (channel_changed) { - eventQueue.add(F("WiFi#ChangedWiFichannel")); - } - } - - if (useStaticIP()) { - markGotIP(); // in static IP config the got IP event is never fired. - } - saveToRTC(); - - logConnectionStatus(); -} - -void processGotIP() { - if (processedGotIP) { - return; - } - IPAddress ip = NetworkLocalIP(); - - if (!useStaticIP()) { - if ((ip[0] == 0) && (ip[1] == 0) && (ip[2] == 0) && (ip[3] == 0)) { - return; - } - } - processedGotIP = true; - wifiStatus |= ESPEASY_WIFI_GOT_IP; - const IPAddress gw = NetworkGatewayIP(); - const IPAddress subnet = NetworkSubnetMask(); - const long dhcp_duration = timeDiff(lastConnectMoment, lastGetIPmoment); - - if (loglevelActiveFor(LOG_LEVEL_INFO)) { - String log = F("WIFI : "); - - if (useStaticIP()) { - log += F("Static IP: "); - } else { - log += F("DHCP IP: "); - } - log += formatIP(ip); - log += " ("; - log += WifiGetHostname(); - log += F(") GW: "); - log += formatIP(gw); - log += F(" SN: "); - log += formatIP(subnet); - - if ((dhcp_duration > 0) && (dhcp_duration < 30000)) { - // Just log times when they make sense. - log += F(" duration: "); - log += dhcp_duration; - log += F(" ms"); - } - addLog(LOG_LEVEL_INFO, log); - } - - // Might not work in core 2.5.0 - // See https://github.com/esp8266/Arduino/issues/5839 - if ((Settings.IP_Octet != 0) && (Settings.IP_Octet != 255)) - { - ip[3] = Settings.IP_Octet; - - if (loglevelActiveFor(LOG_LEVEL_INFO)) { - String log = F("IP : Fixed IP octet:"); - log += formatIP(ip); - addLog(LOG_LEVEL_INFO, log); - } - WiFi.config(ip, gw, subnet); - } - - // First try to get the time, since that may be used in logs - if (node_time.systemTimePresent()) { - node_time.initTime(); - } -#ifdef USES_MQTT - mqtt_reconnect_count = 0; - MQTTclient_should_reconnect = true; - timermqtt_interval = 100; - setIntervalTimer(TIMER_MQTT); -#endif // USES_MQTT - sendGratuitousARP_now(); - - if (Settings.UseRules) - { - eventQueue.add(F("WiFi#Connected")); - } - statusLED(true); - - // WiFi.scanDelete(); - - if (wifiSetup) { - // Wifi setup was active, Apparently these settings work. - wifiSetup = false; - SaveSettings(); - } - logConnectionStatus(); -} - -// A client disconnected from the AP on this node. -void processDisconnectAPmode() { - if (processedDisconnectAPmode) { return; } - processedDisconnectAPmode = true; - - if (loglevelActiveFor(LOG_LEVEL_INFO)) { - const int nrStationsConnected = WiFi.softAPgetStationNum(); - String log = F("AP Mode: Client disconnected: "); - log += formatMAC(lastMacDisconnectedAPmode); - log += F(" Connected devices: "); - log += nrStationsConnected; - addLog(LOG_LEVEL_INFO, log); - } -} - -// Client connects to AP on this node -void processConnectAPmode() { - if (processedConnectAPmode) { return; } - processedConnectAPmode = true; - // Extend timer to switch off AP. - timerAPoff = millis() + WIFI_AP_OFF_TIMER_DURATION; - - if (loglevelActiveFor(LOG_LEVEL_INFO)) { - String log = F("AP Mode: Client connected: "); - log += formatMAC(lastMacConnectedAPmode); - log += F(" Connected devices: "); - log += WiFi.softAPgetStationNum(); - addLog(LOG_LEVEL_INFO, log); - } - setWebserverRunning(true); - - // Start DNS, only used if the ESP has no valid WiFi config - // It will reply with it's own address on all DNS requests - // (captive portal concept) - if (!dnsServerActive) { - dnsServerActive = true; - dnsServer.start(DNS_PORT, "*", apIP); - } -} - -// Switch of AP mode when timeout reached and no client connected anymore. -void processDisableAPmode() { - if (timerAPoff == 0) { return; } - - if (WifiIsAP(WiFi.getMode())) { - // disable AP after timeout and no clients connected. - if (timeOutReached(timerAPoff) && (WiFi.softAPgetStationNum() == 0)) { - setAP(false); - } - } - - if (!WifiIsAP(WiFi.getMode())) { - timerAPoff = 0; - } -} - -void processScanDone() { - if (processedScanDone) { return; } - - // Better act on the scan done event, as it may get triggered for normal wifi begin calls. - int8_t scanCompleteStatus = WiFi.scanComplete(); - switch (scanCompleteStatus) { - case 0: // Nothing (yet) found - if (timePassedSince(lastGetScanMoment) > 5000) { - processedScanDone = true; - } - return; - case -1: // WIFI_SCAN_RUNNING - return; - case -2: // WIFI_SCAN_FAILED - addLog(LOG_LEVEL_ERROR, F("WiFi : Scan failed")); - processedScanDone = true; - return; - } - - lastGetScanMoment = millis(); - processedScanDone = true; - - if (loglevelActiveFor(LOG_LEVEL_INFO)) { - String log = F("WIFI : Scan finished, found: "); - log += scanCompleteStatus; - addLog(LOG_LEVEL_INFO, log); - } - - int bestScanID = -1; - int32_t bestRssi = -1000; - uint8_t bestWiFiSettings = RTC.lastWiFiSettingsIndex; - - if (selectValidWiFiSettings() && scanCompleteStatus > 0) { - const uint8_t startWiFiSettings = RTC.lastWiFiSettingsIndex; - bool done = false; - while (!done) { - String ssid_to_check = getLastWiFiSettingsSSID(); - for (int i = 0; i < scanCompleteStatus; ++i) { - if (WiFi.SSID(i) == ssid_to_check) { - int32_t rssi = WiFi.RSSI(i); - - if (bestRssi < rssi) { - bestRssi = rssi; - bestScanID = i; - bestWiFiSettings = RTC.lastWiFiSettingsIndex; - } - } - } - - // Select the next WiFi settings. - // RTC.lastWiFiSettingsIndex may be updated. - if (!selectNextWiFiSettings()) { - done = true; - } - if (startWiFiSettings == RTC.lastWiFiSettingsIndex) { - done = true; - } - } - - if (bestScanID >= 0) { - if (loglevelActiveFor(LOG_LEVEL_INFO)) { - String log = F("WIFI : Selected: "); - log += formatScanResult(bestScanID, " "); - addLog(LOG_LEVEL_INFO, log); - } - RTC.lastWiFiSettingsIndex = bestWiFiSettings; - uint8_t *scanbssid = WiFi.BSSID(bestScanID); - - if (scanbssid) { - for (int i = 0; i < 6; ++i) { - RTC.lastBSSID[i] = *(scanbssid + i); - } - } - } - } -} - - -void markWiFi_services_initialized() { - wifiStatus = ESPEASY_WIFI_SERVICES_INITIALIZED; - wifiConnectInProgress = false; - setWebserverRunning(true); -} -*/ \ No newline at end of file diff --git a/src/ESPEasyStorage.ino b/src/ESPEasyStorage.ino index 31ce4cf3b..cbffb745c 100644 --- a/src/ESPEasyStorage.ino +++ b/src/ESPEasyStorage.ino @@ -1,3 +1,4 @@ +#include "ESPEasyWifi.h" #include "src/Globals/Cache.h" #include "src/Globals/CRCValues.h" #include "src/Globals/ResetFactoryDefaultPref.h" diff --git a/src/ESPEasyWiFi_credentials.ino b/src/ESPEasyWiFi_credentials.cpp similarity index 92% rename from src/ESPEasyWiFi_credentials.ino rename to src/ESPEasyWiFi_credentials.cpp index 3289fa2fb..aea8a2c5a 100644 --- a/src/ESPEasyWiFi_credentials.ino +++ b/src/ESPEasyWiFi_credentials.cpp @@ -1,3 +1,7 @@ +#include "ESPEasyWiFi_credentials.h" +#include "src/Globals/RTC.h" +#include "src/Globals/SecuritySettings.h" + // ******************************************************************************** // Manage WiFi credentials // ******************************************************************************** diff --git a/src/ESPEasyWiFi_credentials.h b/src/ESPEasyWiFi_credentials.h new file mode 100644 index 000000000..f608100d9 --- /dev/null +++ b/src/ESPEasyWiFi_credentials.h @@ -0,0 +1,11 @@ +#ifndef ESPEASYWIFI_CREDENTIALS_H +#define ESPEASYWIFI_CREDENTIALS_H + +const char* getLastWiFiSettingsSSID(); +const char* getLastWiFiSettingsPassphrase(); +bool selectNextWiFiSettings(); +bool selectValidWiFiSettings(); +bool wifiSettingsValid(const char *ssid, const char *pass); + + +#endif // ESPEASYWIFI_CREDENTIALS_H \ No newline at end of file diff --git a/src/ESPEasyWifi.ino b/src/ESPEasyWifi.cpp similarity index 98% rename from src/ESPEasyWifi.ino rename to src/ESPEasyWifi.cpp index 4d6f56538..3252cf756 100644 --- a/src/ESPEasyWifi.ino +++ b/src/ESPEasyWifi.cpp @@ -1,10 +1,11 @@ -#define WIFI_RECONNECT_WAIT 20000 // in milliSeconds -#define WIFI_AP_OFF_TIMER_DURATION 60000 // in milliSeconds -#define WIFI_CONNECTION_CONSIDERED_STABLE 300000 // in milliSeconds -#define WIFI_ALLOW_AP_AFTERBOOT_PERIOD 5 // in minutes - +#include "ESPEasyWifi.h" +#include "ESPEasyWifi_ProcessEvent.h" #include "src/Globals/ESPEasyWiFiEvent.h" #include "ESPEasy-Globals.h" +#include "ESPEasyWiFi_credentials.h" +#include "src/DataStructs/TimingStats.h" +#include "src/Globals/RTC.h" +#include "src/Globals/SecuritySettings.h" // ******************************************************************************** // WiFi state diff --git a/src/ESPEasyWifi.h b/src/ESPEasyWifi.h new file mode 100644 index 000000000..b34e978bf --- /dev/null +++ b/src/ESPEasyWifi.h @@ -0,0 +1,44 @@ +#ifndef ESPEASY_ETH_H +#define ESPEASY_ETH_H + +#include "ESPEasy_common.h" + +#if defined(ESP8266) + # include + # include +#endif // if defined(ESP8266) +#if defined(ESP32) + # include + # include +#endif // if defined(ESP32) + + +#define WIFI_RECONNECT_WAIT 20000 // in milliSeconds +#define WIFI_AP_OFF_TIMER_DURATION 60000 // in milliSeconds +#define WIFI_CONNECTION_CONSIDERED_STABLE 300000 // in milliSeconds +#define WIFI_ALLOW_AP_AFTERBOOT_PERIOD 5 // in minutes + +bool WiFiConnected(); +void WiFiConnectRelaxed(); +bool prepareWiFi(); +void resetWiFi(); +void WifiDisconnect(); +void WifiScan(bool async, bool quick); +void WifiScan(); +void setSTA(bool enable); +void setAP(bool enable); +String getWifiModeString(WiFiMode_t wifimode); +void setWifiMode(WiFiMode_t wifimode); +bool WifiIsAP(WiFiMode_t wifimode); +String WifiGetAPssid(); +bool useStaticIP(); +bool wifiConnectTimeoutReached(); +bool wifiAPmodeActivelyUsed(); +void setConnectionSpeed(); +void setupStaticIPconfig(); +String formatScanResult(int i, const String& separator); +String formatScanResult(int i, const String& separator, int32_t& rssi); +void logConnectionStatus(); +String getLastDisconnectReason(); + +#endif // ESPEASY_ETH_H \ No newline at end of file diff --git a/src/ESPEasyWifi_ProcessEvent.ino b/src/ESPEasyWifi_ProcessEvent.cpp similarity index 97% rename from src/ESPEasyWifi_ProcessEvent.ino rename to src/ESPEasyWifi_ProcessEvent.cpp index e24802ff3..4ca80207c 100644 --- a/src/ESPEasyWifi_ProcessEvent.ino +++ b/src/ESPEasyWifi_ProcessEvent.cpp @@ -1,4 +1,14 @@ +#include "ESPEasyWifi_ProcessEvent.h" +#include "ESPEasy-Globals.h" +#include "Network.h" +#include "ESPEasyWifi.h" +#include "ESPEasyWiFi_credentials.h" +#include "ESPEasy_fdwdecl.h" #include "src/Globals/ESPEasyWiFiEvent.h" +#include "src/Globals/RTC.h" +#include "src/Globals/MQTT.h" +#include "src/Helpers/ESPEasy_time_calc.h" +#include "src/DataStructs/SchedulerTimers.h" bool unprocessedWifiEvents() { if (processedConnect && processedDisconnect && processedGotIP && processedDHCPTimeout) diff --git a/src/ESPEasyWifi_ProcessEvent.h b/src/ESPEasyWifi_ProcessEvent.h new file mode 100644 index 000000000..21f70cc69 --- /dev/null +++ b/src/ESPEasyWifi_ProcessEvent.h @@ -0,0 +1,15 @@ +#ifndef ESPEASYWIFI_PROCESSEVENT_H +#define ESPEASYWIFI_PROCESSEVENT_H + +bool unprocessedWifiEvents(); +void handle_unprocessedWiFiEvents(); +void processDisconnect(); +void processConnect(); +void processGotIP(); +void processDisconnectAPmode(); +void processConnectAPmode(); +void processDisableAPmode(); +void processScanDone(); +void markWiFi_services_initialized(); + +#endif //ESPEASYWIFI_PROCESSEVENT_H \ No newline at end of file diff --git a/src/ESPEasy_fdwdecl.h b/src/ESPEasy_fdwdecl.h index 3eeb16ddf..7d9df47d8 100644 --- a/src/ESPEasy_fdwdecl.h +++ b/src/ESPEasy_fdwdecl.h @@ -72,8 +72,11 @@ bool useStaticIP(); bool hostReachable(const IPAddress& ip); bool hostReachable(const String& hostname); void formatMAC(const uint8_t * mac, char (& strMAC)[20]); +String formatMAC(const uint8_t *mac); String to_json_object_value(const String& object, const String& value); +void htmlEscape(String& html, char c); +void htmlEscape(String& html); bool I2C_read_bytes(uint8_t i2caddr, @@ -142,6 +145,7 @@ String formatToHex(unsigned long value, const String& prefix); String formatToHex(unsigned long value); String formatToHex_decimal(unsigned long value); String getNumerical(const String& tBuf, bool mustBeInteger); +String format_msec_duration(long duration); float getCPUload(); int getLoopCountPerSec(); @@ -150,6 +154,7 @@ void setLogLevelFor(byte destination, byte logLevel); uint16_t getPortFromKey(uint32_t key); void initRTC(); +boolean saveToRTC(); void deepSleepStart(int dsdelay); bool setControllerEnableStatus(controllerIndex_t controllerIndex, bool enabled); bool setTaskEnableStatus(taskIndex_t taskIndex, bool enabled); @@ -193,18 +198,11 @@ void setSTA(bool enable); // Used for Networking with Wifi or Ethernet #include "ESPEasyEthWifi.h" -void NetworkConnectRelaxed(); -bool NetworkConnected(); -IPAddress NetworkLocalIP(); -IPAddress NetworkSubnetMask(); -IPAddress NetworkGatewayIP(); -IPAddress NetworkDnsIP (uint8_t dns_no=0); -uint8_t * NetworkMacAddressAsBytes(uint8_t* mac); -String NetworkMacAddress(); +#include "Network.h" String WifiGetAPssid(); -String createRFCCompliantHostname(String oldString); void WiFiConnectRelaxed(); bool WiFiConnected(); +String createRFCCompliantHostname(String oldString); #include "src/Globals/ESPEasyWiFiEvent.h" @@ -217,13 +215,16 @@ unsigned long FreeMem(void); void ResetFactory(); void reboot(); void SendUDPCommand(byte destUnit, const char *data, byte dataLength); +bool hasIPaddr(); #include void printDirectory(File dir, int numTabs); void delayBackground(unsigned long dsdelay); -void setIntervalTimerOverride(unsigned long id, unsigned long msecFromNow); //implemented in Scheduler.ino +//implemented in Scheduler.ino +void setIntervalTimerOverride(unsigned long id, unsigned long msecFromNow); +void sendGratuitousARP_now(); byte PluginCall(byte Function, struct EventStruct *event, String& str); diff --git a/src/Network.cpp b/src/Network.cpp index 77ecf9ccc..c921e33ca 100644 --- a/src/Network.cpp +++ b/src/Network.cpp @@ -1,13 +1,8 @@ #include "Network.h" - #include "ESPEasy_fdwdecl.h" #include "ESPEasy-Globals.h" #include "ESPEasy_Log.h" #include "ESPEasyEth.h" -//#include "ESPEasy_common.h" -//#include "src/Globals/Settings.h" -//#include "src/DataStructs/TimingStats.h" - #include "ETH.h" /*********************************************************************************************\ diff --git a/src/StringProvider.ino b/src/StringProvider.ino index 4945a5b95..17381eb34 100644 --- a/src/StringProvider.ino +++ b/src/StringProvider.ino @@ -222,7 +222,7 @@ String getValue(LabelType::Enum label) { case LabelType::ETH_IP_SUBNET: return NetworkSubnetMask().toString(); case LabelType::ETH_IP_ADDRESS_SUBNET: return String(getValue(LabelType::ETH_IP_ADDRESS) + F(" / ") + getValue(LabelType::ETH_IP_SUBNET)); case LabelType::ETH_IP_GATEWAY: return NetworkGatewayIP().toString(); - case LabelType::ETH_IP_DNS: return NetworkDnsIP().toString(); + case LabelType::ETH_IP_DNS: return NetworkDnsIP(0).toString(); case LabelType::ETH_MAC: return NetworkMacAddress(); case LabelType::ETH_DUPLEX: return eth_connected ? (ETH.fullDuplex() ? F("Full Duplex") : F("Half Duplex")) : F("No Ethernet"); case LabelType::ETH_SPEED: return eth_connected ? getEthSpeed() : F("No Ethernet"); From e68e6eca3cc4d8e321e32597495f313f7abf095d Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Tue, 28 Apr 2020 20:13:49 +0200 Subject: [PATCH 22/39] Network.h/cpp --> ESPEasyNetwork.h/cpp --- src/{Network.cpp => ESPEasyNetwork.cpp} | 2 +- src/{Network.h => ESPEasyNetwork.h} | 0 src/ESPEasyWifi_ProcessEvent.cpp | 2 +- src/ESPEasy_fdwdecl.h | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename src/{Network.cpp => ESPEasyNetwork.cpp} (95%) rename src/{Network.h => ESPEasyNetwork.h} (100%) diff --git a/src/Network.cpp b/src/ESPEasyNetwork.cpp similarity index 95% rename from src/Network.cpp rename to src/ESPEasyNetwork.cpp index c921e33ca..9d351c853 100644 --- a/src/Network.cpp +++ b/src/ESPEasyNetwork.cpp @@ -1,4 +1,4 @@ -#include "Network.h" +#include "ESPEasyNetwork.h" #include "ESPEasy_fdwdecl.h" #include "ESPEasy-Globals.h" #include "ESPEasy_Log.h" diff --git a/src/Network.h b/src/ESPEasyNetwork.h similarity index 100% rename from src/Network.h rename to src/ESPEasyNetwork.h diff --git a/src/ESPEasyWifi_ProcessEvent.cpp b/src/ESPEasyWifi_ProcessEvent.cpp index 4ca80207c..06fd375ac 100644 --- a/src/ESPEasyWifi_ProcessEvent.cpp +++ b/src/ESPEasyWifi_ProcessEvent.cpp @@ -1,6 +1,6 @@ #include "ESPEasyWifi_ProcessEvent.h" #include "ESPEasy-Globals.h" -#include "Network.h" +#include "ESPEasyNetwork.h" #include "ESPEasyWifi.h" #include "ESPEasyWiFi_credentials.h" #include "ESPEasy_fdwdecl.h" diff --git a/src/ESPEasy_fdwdecl.h b/src/ESPEasy_fdwdecl.h index 7d9df47d8..a332fe750 100644 --- a/src/ESPEasy_fdwdecl.h +++ b/src/ESPEasy_fdwdecl.h @@ -198,7 +198,7 @@ void setSTA(bool enable); // Used for Networking with Wifi or Ethernet #include "ESPEasyEthWifi.h" -#include "Network.h" +#include "ESPEasyNetwork.h" String WifiGetAPssid(); void WiFiConnectRelaxed(); bool WiFiConnected(); From db94e1668c8c0e750198d5ebcd3a7b7f8c9920ce Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Tue, 28 Apr 2020 20:18:20 +0200 Subject: [PATCH 23/39] removed upload flags --- platformio_esp32_envs.ini | 2 -- 1 file changed, 2 deletions(-) diff --git a/platformio_esp32_envs.ini b/platformio_esp32_envs.ini index 52d3a24e8..1bfc0e7ec 100644 --- a/platformio_esp32_envs.ini +++ b/platformio_esp32_envs.ini @@ -22,8 +22,6 @@ build_flags = ${mqtt_flags.build_flags} -DCONFIG_FREERTOS_ASSERT_DISABLE -DCONFIG_LWIP_ESP_GRATUITOUS_ARP -DCONFIG_LWIP_GARP_TMR_INTERVAL=30 -upload_flags = - -b921600 ; Custom: 4096k version -------------------------- From 691824477f76bef1d78e5b0c6ea9551fccf22ecc Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Tue, 28 Apr 2020 21:18:59 +0200 Subject: [PATCH 24/39] - New events: ETHERNET#Connected and ETHERNET#Disconnected --- src/ESPEasyWiFiEvent.cpp | 4 ++++ src/ESPEasyWifi_ProcessEvent.cpp | 21 ++++++++++++++++++++- src/ESPEasyWifi_ProcessEvent.h | 5 +++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/ESPEasyWiFiEvent.cpp b/src/ESPEasyWiFiEvent.cpp index 39319c7ae..638ecea7a 100644 --- a/src/ESPEasyWiFiEvent.cpp +++ b/src/ESPEasyWiFiEvent.cpp @@ -1,5 +1,6 @@ #include "ETH.h" #include "ESPEasyWiFiEvent.h" +#include "ESPEasyWifi_ProcessEvent.h" #include "src/Globals/ESPEasyWiFiEvent.h" #include "src/Globals/RTC.h" #include "ESPEasyTimeTypes.h" @@ -120,6 +121,8 @@ void WiFiEvent(system_event_id_t event, system_event_info_t info) { break; case SYSTEM_EVENT_ETH_CONNECTED: addLog(LOG_LEVEL_INFO, F("ETH Connected")); + eth_connected = true; + processEthernetConnected(); break; case SYSTEM_EVENT_ETH_GOT_IP: { @@ -140,6 +143,7 @@ void WiFiEvent(system_event_id_t event, system_event_info_t info) { case SYSTEM_EVENT_ETH_DISCONNECTED: addLog(LOG_LEVEL_ERROR, F("ETH Disconnected")); eth_connected = false; + processEthernetDisconnected(); break; case SYSTEM_EVENT_ETH_STOP: addLog(LOG_LEVEL_INFO, F("ETH Stopped")); diff --git a/src/ESPEasyWifi_ProcessEvent.cpp b/src/ESPEasyWifi_ProcessEvent.cpp index 06fd375ac..01d7f86c2 100644 --- a/src/ESPEasyWifi_ProcessEvent.cpp +++ b/src/ESPEasyWifi_ProcessEvent.cpp @@ -452,4 +452,23 @@ void markWiFi_services_initialized() { wifiConnectInProgress = false; processedDHCPTimeout = true; // FIXME TD-er: Is this ever happening? -} \ No newline at end of file +} + +#ifdef HAS_ETHERNET + +void processEthernetConnected() { + if (Settings.UseRules) + { + eventQueue.add(F("ETHERNET#Connected")); + } + statusLED(true); +} + +void processEthernetDisconnected() { + if (Settings.UseRules) + { + eventQueue.add(F("ETHERNET#Disconnected")); + } +} + +#endif \ No newline at end of file diff --git a/src/ESPEasyWifi_ProcessEvent.h b/src/ESPEasyWifi_ProcessEvent.h index 21f70cc69..78c4a1161 100644 --- a/src/ESPEasyWifi_ProcessEvent.h +++ b/src/ESPEasyWifi_ProcessEvent.h @@ -12,4 +12,9 @@ void processDisableAPmode(); void processScanDone(); void markWiFi_services_initialized(); +#ifdef HAS_ETHERNET +void processEthernetConnected(); +void processEthernetDisconnected(); +#endif + #endif //ESPEASYWIFI_PROCESSEVENT_H \ No newline at end of file From b1a3d747c05078280db80eedd7fff082c5bea4c4 Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Tue, 28 Apr 2020 21:48:59 +0200 Subject: [PATCH 25/39] Fixed https://travis-ci.org/github/letscontrolit/ESPEasy/builds/680698472 ci build error --- src/ESPEasyNetwork.cpp | 3 +++ src/ESPEasyNetwork.h | 2 +- src/ESPEasyWiFiEvent.cpp | 2 ++ src/StringProvider.ino | 2 ++ src/src/Commands/Networks.cpp | 2 ++ 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ESPEasyNetwork.cpp b/src/ESPEasyNetwork.cpp index 9d351c853..828df3e16 100644 --- a/src/ESPEasyNetwork.cpp +++ b/src/ESPEasyNetwork.cpp @@ -3,7 +3,10 @@ #include "ESPEasy-Globals.h" #include "ESPEasy_Log.h" #include "ESPEasyEth.h" + +#ifdef HAS_ETHERNET #include "ETH.h" +#endif /*********************************************************************************************\ Ethernet or Wifi Support for ESP32 Build flag HAS_ETHERNET diff --git a/src/ESPEasyNetwork.h b/src/ESPEasyNetwork.h index 90f5c316b..4a9d91d99 100644 --- a/src/ESPEasyNetwork.h +++ b/src/ESPEasyNetwork.h @@ -1,7 +1,7 @@ #ifndef NETWORK_H #define NETWORK_H -#include "ESPEasy_common.h" +#include "ESPEasy-Globals.h" void NetworkConnectRelaxed(); bool NetworkConnected(); diff --git a/src/ESPEasyWiFiEvent.cpp b/src/ESPEasyWiFiEvent.cpp index 638ecea7a..bead31154 100644 --- a/src/ESPEasyWiFiEvent.cpp +++ b/src/ESPEasyWiFiEvent.cpp @@ -1,4 +1,6 @@ +#ifdef HAS_ETHERNET #include "ETH.h" +#endif #include "ESPEasyWiFiEvent.h" #include "ESPEasyWifi_ProcessEvent.h" #include "src/Globals/ESPEasyWiFiEvent.h" diff --git a/src/StringProvider.ino b/src/StringProvider.ino index 17381eb34..549729a8a 100644 --- a/src/StringProvider.ino +++ b/src/StringProvider.ino @@ -1,5 +1,7 @@ #include "StringProviderTypes.h" +#ifdef HAS_ETHERNET #include "ETH.h" +#endif String getInternalLabel(LabelType::Enum label, char replaceSpace) { return to_internal_string(getLabel(label), replaceSpace); diff --git a/src/src/Commands/Networks.cpp b/src/src/Commands/Networks.cpp index 24bf82613..737c756c6 100644 --- a/src/src/Commands/Networks.cpp +++ b/src/src/Commands/Networks.cpp @@ -5,7 +5,9 @@ #include "../Globals/Settings.h" #include "../../ESPEasy_fdwdecl.h" +#ifdef HAS_ETHERNET #include "ETH.h" +#endif String Command_AccessInfo_Ls(struct EventStruct *event, const char* Line) { From cde90522830b42bbdc3580888086e2d7e1efb9ca Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Tue, 28 Apr 2020 23:28:45 +0200 Subject: [PATCH 26/39] Fixed ci compile bug https://travis-ci.org/github/letscontrolit/ESPEasy/builds/680724129 --- src/ESPEasyNetwork.cpp | 21 +++++++++++++++++++++ src/ESPEasyNetwork.h | 3 +++ src/ESPEasyWiFiEvent.cpp | 2 +- src/ESPEasyWifi.cpp | 14 ++++---------- src/ESPEasyWifi.h | 1 - src/ESPEasyWifi_ProcessEvent.cpp | 2 +- src/ESPEasy_fdwdecl.h | 2 -- src/Networking.ino | 10 ---------- src/StringProvider.ino | 3 ++- src/WebServer.ino | 5 +++-- 10 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/ESPEasyNetwork.cpp b/src/ESPEasyNetwork.cpp index 828df3e16..d91921cad 100644 --- a/src/ESPEasyNetwork.cpp +++ b/src/ESPEasyNetwork.cpp @@ -138,4 +138,25 @@ String NetworkMacAddress() { formatMAC(macread, macaddress); return String(macaddress); +} + +// ******************************************************************************** +// Determine Wifi AP name to set. (also used for mDNS) +// ******************************************************************************** +String NetworkGetAPssid() +{ + return Settings.getHostname(); +} + +String NetworkGetHostname() { + return createRFCCompliantHostname(NetworkGetAPssid()); +} + +// Create hostname with - instead of spaces +String createRFCCompliantHostname(String oldString) { + String result(oldString); + + result.replace(" ", "-"); + result.replace("_", "-"); // See RFC952 + return result; } \ No newline at end of file diff --git a/src/ESPEasyNetwork.h b/src/ESPEasyNetwork.h index 4a9d91d99..c9d14ad14 100644 --- a/src/ESPEasyNetwork.h +++ b/src/ESPEasyNetwork.h @@ -11,6 +11,9 @@ IPAddress NetworkGatewayIP(); IPAddress NetworkDnsIP (uint8_t dns_no); uint8_t * NetworkMacAddressAsBytes(uint8_t* mac); String NetworkMacAddress(); +String NetworkGetAPssid(); +String NetworkGetHostname(); +String createRFCCompliantHostname(String oldString); #endif // NETWORK_H \ No newline at end of file diff --git a/src/ESPEasyWiFiEvent.cpp b/src/ESPEasyWiFiEvent.cpp index bead31154..67c8f5b57 100644 --- a/src/ESPEasyWiFiEvent.cpp +++ b/src/ESPEasyWiFiEvent.cpp @@ -113,7 +113,7 @@ void WiFiEvent(system_event_id_t event, system_event_info_t info) { case SYSTEM_EVENT_ETH_START: addLog(LOG_LEVEL_INFO, F("ETH Started")); char hostname[40]; - safe_strncpy(hostname, createRFCCompliantHostname(WifiGetAPssid()).c_str(), sizeof(hostname)); + safe_strncpy(hostname, NetworkGetHostname()).c_str(), sizeof(hostname)); ETH.setHostname(hostname); { String log = F("ETH Hostname: "); diff --git a/src/ESPEasyWifi.cpp b/src/ESPEasyWifi.cpp index 3252cf756..279fc6068 100644 --- a/src/ESPEasyWifi.cpp +++ b/src/ESPEasyWifi.cpp @@ -1,4 +1,5 @@ #include "ESPEasyWifi.h" +#include "ESPEasyNetwork.h" #include "ESPEasyWifi_ProcessEvent.h" #include "src/Globals/ESPEasyWiFiEvent.h" #include "ESPEasy-Globals.h" @@ -6,6 +7,7 @@ #include "src/DataStructs/TimingStats.h" #include "src/Globals/RTC.h" #include "src/Globals/SecuritySettings.h" +#include "src/Helpers/ESPEasy_time_calc.h" // ******************************************************************************** // WiFi state @@ -204,7 +206,7 @@ bool prepareWiFi() { } setSTA(true); char hostname[40]; - safe_strncpy(hostname, createRFCCompliantHostname(WifiGetAPssid()).c_str(), sizeof(hostname)); + safe_strncpy(hostname, NetworkGetHostname().c_str(), sizeof(hostname)); #if defined(ESP8266) wifi_station_set_hostname(hostname); @@ -382,7 +384,7 @@ void setAPinternal(bool enable) if (enable) { // create and store unique AP SSID/PW to prevent ESP from starting AP mode with default SSID and No password! // setup ssid for AP Mode when needed - String softAPSSID = WifiGetAPssid(); + String softAPSSID = NetworkGetAPssid(); String pwd = SecuritySettings.WifiAPKey; IPAddress subnet(DEFAULT_AP_SUBNET); @@ -507,14 +509,6 @@ bool WifiIsSTA(WiFiMode_t wifimode) #endif // if defined(ESP32) } -// ******************************************************************************** -// Determine Wifi AP name to set. (also used for mDNS) -// ******************************************************************************** -String WifiGetAPssid() -{ - return Settings.getHostname(); -} - bool useStaticIP() { return Settings.IP[0] != 0 && Settings.IP[0] != 255; } diff --git a/src/ESPEasyWifi.h b/src/ESPEasyWifi.h index b34e978bf..34c294237 100644 --- a/src/ESPEasyWifi.h +++ b/src/ESPEasyWifi.h @@ -30,7 +30,6 @@ void setAP(bool enable); String getWifiModeString(WiFiMode_t wifimode); void setWifiMode(WiFiMode_t wifimode); bool WifiIsAP(WiFiMode_t wifimode); -String WifiGetAPssid(); bool useStaticIP(); bool wifiConnectTimeoutReached(); bool wifiAPmodeActivelyUsed(); diff --git a/src/ESPEasyWifi_ProcessEvent.cpp b/src/ESPEasyWifi_ProcessEvent.cpp index 01d7f86c2..ef0b2b70a 100644 --- a/src/ESPEasyWifi_ProcessEvent.cpp +++ b/src/ESPEasyWifi_ProcessEvent.cpp @@ -256,7 +256,7 @@ void processGotIP() { } log += formatIP(ip); log += " ("; - log += createRFCCompliantHostname(WifiGetAPssid()); + log += NetworkGetHostname(); log += F(") GW: "); log += formatIP(gw); log += F(" SN: "); diff --git a/src/ESPEasy_fdwdecl.h b/src/ESPEasy_fdwdecl.h index a332fe750..414d8018b 100644 --- a/src/ESPEasy_fdwdecl.h +++ b/src/ESPEasy_fdwdecl.h @@ -199,10 +199,8 @@ void setSTA(bool enable); // Used for Networking with Wifi or Ethernet #include "ESPEasyEthWifi.h" #include "ESPEasyNetwork.h" -String WifiGetAPssid(); void WiFiConnectRelaxed(); bool WiFiConnected(); -String createRFCCompliantHostname(String oldString); #include "src/Globals/ESPEasyWiFiEvent.h" diff --git a/src/Networking.ino b/src/Networking.ino index 3463fc3ea..d6fcd992f 100644 --- a/src/Networking.ino +++ b/src/Networking.ino @@ -1005,16 +1005,6 @@ String splitURL(const String& fullURL, String& host, uint16_t& port, String& fil return fullURL.substring(endhost); } -// Create hostname with - instead of spaces -String createRFCCompliantHostname(String oldString) -{ - String result(oldString); - - result.replace(" ", "-"); - result.replace("_", "-"); // See RFC952 - return result; -} - #ifdef USE_SETTINGS_ARCHIVE // Download a file from a given URL and save to a local file named "file_save" diff --git a/src/StringProvider.ino b/src/StringProvider.ino index 549729a8a..a4d0d8319 100644 --- a/src/StringProvider.ino +++ b/src/StringProvider.ino @@ -1,4 +1,5 @@ #include "StringProviderTypes.h" +#include "ESPEasyNetwork.h" #ifdef HAS_ETHERNET #include "ETH.h" #endif @@ -164,7 +165,7 @@ String getValue(LabelType::Enum label) { case LabelType::CLIENT_IP: return formatIP(web_server.client().remoteIP()); #ifdef FEATURE_MDNS - case LabelType::M_DNS: return String(WifiGetHostname()) + F(".local"); + case LabelType::M_DNS: return String(NetworkGetHostname()) + F(".local"); #endif case LabelType::DNS: return String(getValue(LabelType::DNS_1) + F(" / ") + getValue(LabelType::DNS_2)); case LabelType::DNS_1: return NetworkDnsIP(0).toString(); diff --git a/src/WebServer.ino b/src/WebServer.ino index ac9f5aba7..7467c5ca6 100644 --- a/src/WebServer.ino +++ b/src/WebServer.ino @@ -4,6 +4,7 @@ #include +#include "ESPEasyNetwork.h" #include "src/Globals/CPlugins.h" #include "src/Globals/Device.h" #include "src/Globals/TXBuffer.h" @@ -314,8 +315,8 @@ void set_mDNS() { if (webserverRunning) { addLog(LOG_LEVEL_INFO, F("WIFI : Starting mDNS...")); - bool mdns_started = MDNS.begin(WifiGetHostname().c_str()); - MDNS.setInstanceName(WifiGetHostname()); // Needed for when the hostname has changed. + bool mdns_started = MDNS.begin(NetworkGetHostname().c_str()); + MDNS.setInstanceName(NetworkGetHostname()); // Needed for when the hostname has changed. if (loglevelActiveFor(LOG_LEVEL_INFO)) { String log = F("WIFI : "); From 250a345e33042418f429e3ce38bf2f66897debf5 Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Wed, 29 Apr 2020 12:21:20 +0200 Subject: [PATCH 27/39] Fixed bug reported by mobremski --- src/ESPEasyWiFiEvent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ESPEasyWiFiEvent.cpp b/src/ESPEasyWiFiEvent.cpp index 67c8f5b57..017afb8e5 100644 --- a/src/ESPEasyWiFiEvent.cpp +++ b/src/ESPEasyWiFiEvent.cpp @@ -113,7 +113,7 @@ void WiFiEvent(system_event_id_t event, system_event_info_t info) { case SYSTEM_EVENT_ETH_START: addLog(LOG_LEVEL_INFO, F("ETH Started")); char hostname[40]; - safe_strncpy(hostname, NetworkGetHostname()).c_str(), sizeof(hostname)); + safe_strncpy(hostname, NetworkGetHostname().c_str(), sizeof(hostname)); ETH.setHostname(hostname); { String log = F("ETH Hostname: "); From c0bdea0941bb40ec112cbbf1cfa1cbc09cea81fa Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Wed, 29 Apr 2020 12:21:20 +0200 Subject: [PATCH 28/39] - UDP / ESPEasyP2P now works for ETHERNET - Hostname Handling refactored for better overview: - String NetworkGetHostNameFromSettings() returns Settings.getHostname() - String NetworkCreateRFCCompliantHostname() creates a RFCcompliant Hostname from Settings.cpp - String NetworkGetHostname() returns the Hostname prevoiusly set in ETH or Wifi dependong on Mode - MacAddress Handling refactored - String NetworkMacAddress() returns the Mac addres of ETH or Wifi depending on Mode - String WifiSoftAPmacAddress() returns WiFi.softAPmacAddress(mac) as String --- src/ESPEasy.ino | 7 ++++- src/ESPEasyEth.cpp | 16 +++++++++-- src/ESPEasyNetwork.cpp | 53 +++++++++++++++++++++-------------- src/ESPEasyNetwork.h | 4 ++- src/ESPEasyWiFiEvent.cpp | 8 ------ src/ESPEasyWifi.cpp | 2 +- src/Networking.ino | 11 ++++---- src/StringProvider.ino | 10 ++----- src/WebServer_SysInfoPage.ino | 41 ++++++--------------------- src/_C014.ino | 2 +- src/src/Commands/Settings.cpp | 2 +- 11 files changed, 76 insertions(+), 80 deletions(-) diff --git a/src/ESPEasy.ino b/src/ESPEasy.ino index 8691172a5..28fcb2938 100644 --- a/src/ESPEasy.ino +++ b/src/ESPEasy.ino @@ -995,7 +995,12 @@ void backgroundtasks() if (webserverRunning) { web_server.handleClient(); } - if (WiFi.getMode() != WIFI_OFF) { + if (WiFi.getMode() != WIFI_OFF + // This makes UDP working for ETHERNET + #ifdef HAS_ETHERNET + || eth_connected + #endif + ) { checkUDP(); } } diff --git a/src/ESPEasyEth.cpp b/src/ESPEasyEth.cpp index e6b340911..feacd6c1a 100644 --- a/src/ESPEasyEth.cpp +++ b/src/ESPEasyEth.cpp @@ -1,9 +1,10 @@ -#include "ESPEasyEth.h" - #ifdef HAS_ETHERNET +#include "ESPEasyEth.h" +#include "ESPEasyNetwork.h" #include "ETH.h" #include "ESPEasy-Globals.h" +#include "eth_phy/phy.h" bool ethUseStaticIP() { return Settings.ETH_IP[0] != 0 && Settings.ETH_IP[3] != 255; @@ -53,6 +54,9 @@ bool ethPrepare() { addLog(LOG_LEVEL_ERROR, F("ETH: Settings not correct!!!")); return false; } + char hostname[40]; + safe_strncpy(hostname, NetworkCreateRFCCompliantHostname().c_str(), sizeof(hostname)); + ETH.setHostname(hostname); ETH.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); ethSetupStaticIPconfig(); return true; @@ -98,6 +102,14 @@ void ethPrintSettings() { addLog(LOG_LEVEL_INFO, settingsDebugLog); } +String ETHMacAddress() { + uint8_t mac[6]; + char macStr[18] = { 0 }; + esp_eth_get_mac(mac); + sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + return String(macStr); +} + void ETHConnectRelaxed() { ethPrintSettings(); ETH.begin(Settings.ETH_Phy_Addr, diff --git a/src/ESPEasyNetwork.cpp b/src/ESPEasyNetwork.cpp index d91921cad..9b6b2b861 100644 --- a/src/ESPEasyNetwork.cpp +++ b/src/ESPEasyNetwork.cpp @@ -105,29 +105,13 @@ IPAddress NetworkDnsIP (uint8_t dns_no) { #endif } -uint8_t * NetworkMacAddressAsBytes(uint8_t* mac) { - #ifdef HAS_ETHERNET - if(eth_wifi_mode == ETHERNET) { - if(eth_connected) { - return WiFi.macAddress(mac); - } else { - addLog(LOG_LEVEL_ERROR, F("Call NetworkMacAddressAsBytes(uint8_t* mac) only on connected Ethernet!")); - return mac; - } - } else { - return WiFi.macAddress(mac); - } - #else - return WiFi.macAddress(mac); - #endif - return WiFi.macAddress(mac); -} - String NetworkMacAddress() { #ifdef HAS_ETHERNET if(eth_wifi_mode == ETHERNET) { if(!eth_connected) { addLog(LOG_LEVEL_ERROR, F("Call NetworkMacAddress() only on connected Ethernet!")); + } else { + return ETH.macAddress(); } } #endif @@ -140,16 +124,35 @@ String NetworkMacAddress() { return String(macaddress); } +uint8_t * NetworkMacAddressAsBytes(uint8_t* mac) { + return WiFi.macAddress(mac); +} + +String NetworkGetHostname() { + #ifdef ESP32 + #ifdef HAS_ETHERNET + if(Settings.ETH_Wifi_Mode == ETHERNET) { + return String(ETH.getHostname()); + } + return String(WiFi.getHostname()); + #else + return String(WiFi.getHostname()); + #endif + #else + return String(WiFi.hostname()); + #endif +} + // ******************************************************************************** // Determine Wifi AP name to set. (also used for mDNS) // ******************************************************************************** -String NetworkGetAPssid() +String NetworkGetHostNameFromSettings() { return Settings.getHostname(); } -String NetworkGetHostname() { - return createRFCCompliantHostname(NetworkGetAPssid()); +String NetworkCreateRFCCompliantHostname() { + return createRFCCompliantHostname(NetworkGetHostNameFromSettings()); } // Create hostname with - instead of spaces @@ -159,4 +162,12 @@ String createRFCCompliantHostname(String oldString) { result.replace(" ", "-"); result.replace("_", "-"); // See RFC952 return result; +} + +String WifiSoftAPmacAddress() { + uint8_t mac[] = { 0, 0, 0, 0, 0, 0 }; + uint8_t *macread = WiFi.softAPmacAddress(mac); + char macaddress[20]; + formatMAC(macread, macaddress); + return String(macaddress); } \ No newline at end of file diff --git a/src/ESPEasyNetwork.h b/src/ESPEasyNetwork.h index c9d14ad14..cdb774e85 100644 --- a/src/ESPEasyNetwork.h +++ b/src/ESPEasyNetwork.h @@ -11,9 +11,11 @@ IPAddress NetworkGatewayIP(); IPAddress NetworkDnsIP (uint8_t dns_no); uint8_t * NetworkMacAddressAsBytes(uint8_t* mac); String NetworkMacAddress(); -String NetworkGetAPssid(); +String NetworkGetHostNameFromSettings(); String NetworkGetHostname(); +String NetworkCreateRFCCompliantHostname(); String createRFCCompliantHostname(String oldString); +String WifiSoftAPmacAddress(); #endif // NETWORK_H \ No newline at end of file diff --git a/src/ESPEasyWiFiEvent.cpp b/src/ESPEasyWiFiEvent.cpp index 67c8f5b57..2b9c17e86 100644 --- a/src/ESPEasyWiFiEvent.cpp +++ b/src/ESPEasyWiFiEvent.cpp @@ -112,14 +112,6 @@ void WiFiEvent(system_event_id_t event, system_event_info_t info) { #ifdef HAS_ETHERNET case SYSTEM_EVENT_ETH_START: addLog(LOG_LEVEL_INFO, F("ETH Started")); - char hostname[40]; - safe_strncpy(hostname, NetworkGetHostname()).c_str(), sizeof(hostname)); - ETH.setHostname(hostname); - { - String log = F("ETH Hostname: "); - log += String(hostname); - addLog(LOG_LEVEL_INFO, log); - } break; case SYSTEM_EVENT_ETH_CONNECTED: addLog(LOG_LEVEL_INFO, F("ETH Connected")); diff --git a/src/ESPEasyWifi.cpp b/src/ESPEasyWifi.cpp index 279fc6068..05dff9d98 100644 --- a/src/ESPEasyWifi.cpp +++ b/src/ESPEasyWifi.cpp @@ -384,7 +384,7 @@ void setAPinternal(bool enable) if (enable) { // create and store unique AP SSID/PW to prevent ESP from starting AP mode with default SSID and No password! // setup ssid for AP Mode when needed - String softAPSSID = NetworkGetAPssid(); + String softAPSSID = NetworkCreateRFCCompliantHostname(); String pwd = SecuritySettings.WifiAPKey; IPAddress subnet(DEFAULT_AP_SUBNET); diff --git a/src/Networking.ino b/src/Networking.ino index d6fcd992f..eeb0f83c6 100644 --- a/src/Networking.ino +++ b/src/Networking.ino @@ -346,7 +346,8 @@ void sendSysInfoUDP(byte repeats) for (byte counter = 0; counter < repeats; counter++) { uint8_t mac[] = { 0, 0, 0, 0, 0, 0 }; - uint8_t *macread = WiFi.macAddress(mac); + uint8_t *macread = NetworkMacAddressAsBytes(mac); + byte data[80]; data[0] = 255; data[1] = 1; @@ -406,7 +407,7 @@ void SSDP_schema(WiFiClient& client) { return; } - const IPAddress ip = WiFi.localIP(); + const IPAddress ip = NetworkLocalIP(); const uint32_t chipId = ESP.getChipId(); char uuid[64]; sprintf_P(uuid, PSTR("38323636-4558-4dda-9188-cda0e6%02x%02x%02x"), @@ -498,7 +499,7 @@ bool SSDP_begin() { _server->ref(); ip_addr_t ifaddr; - ifaddr.addr = WiFi.localIP(); + ifaddr.addr = NetworkLocalIP(); ip_addr_t multicast_addr; multicast_addr.addr = (uint32_t)SSDP_MULTICAST_ADDR; @@ -544,7 +545,7 @@ bool SSDP_begin() { Send SSDP messages (notify & responses) \*********************************************************************************************/ void SSDP_send(byte method) { - uint32_t ip = WiFi.localIP(); + uint32_t ip = NetworkLocalIP(); // FIXME TD-er: Why create String objects of these flashstrings? String _ssdp_response_template = F( @@ -563,7 +564,7 @@ void SSDP_send(byte method) { "CACHE-CONTROL: max-age=%u\r\n" // SSDP_INTERVAL "SERVER: Arduino/1.0 UPNP/1.1 ESPEasy/%u\r\n" // _modelNumber "USN: uuid:%s\r\n" // _uuid - "LOCATION: http://%u.%u.%u.%u:80/ssdp.xml\r\n" // WiFi.localIP(), + "LOCATION: http://%u.%u.%u.%u:80/ssdp.xml\r\n" // NetworkLocalIP(), "\r\n"); { char uuid[64] = { 0 }; diff --git a/src/StringProvider.ino b/src/StringProvider.ino index a4d0d8319..618e92824 100644 --- a/src/StringProvider.ino +++ b/src/StringProvider.ino @@ -127,12 +127,8 @@ String getValue(LabelType::Enum label) { { case LabelType::UNIT_NR: return String(Settings.Unit); case LabelType::UNIT_NAME: return String(Settings.Name); // Only return the set name, no appended unit. - case LabelType::HOST_NAME: - #ifdef ESP32 - return WiFi.getHostname(); - #else - return WiFi.hostname(); - #endif + case LabelType::HOST_NAME: return NetworkGetHostname(); + case LabelType::LOCAL_TIME: return node_time.getDateTimeString('-',':',' '); case LabelType::UPTIME: return String(wdcounter / 2); @@ -172,7 +168,7 @@ String getValue(LabelType::Enum label) { case LabelType::DNS_2: return NetworkDnsIP(1).toString(); case LabelType::ALLOWED_IP_RANGE: return describeAllowedIPrange(); case LabelType::STA_MAC: return NetworkMacAddress(); - case LabelType::AP_MAC: break; + case LabelType::AP_MAC: return WifiSoftAPmacAddress(); case LabelType::SSID: return WiFi.SSID(); case LabelType::BSSID: return WiFi.BSSIDstr(); case LabelType::CHANNEL: return String(WiFi.channel()); diff --git a/src/WebServer_SysInfoPage.ino b/src/WebServer_SysInfoPage.ino index ebc5b6a29..0e49534f6 100644 --- a/src/WebServer_SysInfoPage.ino +++ b/src/WebServer_SysInfoPage.ino @@ -66,24 +66,13 @@ void handle_sysinfo_json() { json_prop(F("dns1"), formatIP(NetworkDnsIP(0))); json_prop(F("dns2"), formatIP(NetworkDnsIP(1))); json_prop(F("allowed_range"), describeAllowedIPrange()); - - - uint8_t mac[] = { 0, 0, 0, 0, 0, 0 }; - uint8_t *macread = WiFi.macAddress(mac); - char macaddress[20]; - formatMAC(macread, macaddress); - - json_prop(F("sta_mac"), macaddress); - - macread = WiFi.softAPmacAddress(mac); - formatMAC(macread, macaddress); - - json_prop(F("ap_mac"), macaddress); - json_prop(F("ssid"), WiFi.SSID()); - json_prop(F("bssid"), WiFi.BSSIDstr()); - json_number(F("channel"), String(WiFi.channel())); - json_prop(F("connected"), format_msec_duration(timeDiff(lastConnectMoment, millis()))); - json_prop(F("ldr"), getLastDisconnectReason()); + json_prop(F("sta_mac"), NetworkMacAddress()); + json_prop(F("ap_mac"), WifiSoftAPmacAddress()); + json_prop(F("ssid"), WiFi.SSID()); + json_prop(F("bssid"), WiFi.BSSIDstr()); + json_number(F("channel"), String(WiFi.channel())); + json_prop(F("connected"), format_msec_duration(timeDiff(lastConnectMoment, millis()))); + json_prop(F("ldr"), getLastDisconnectReason()); json_number(F("reconnects"), String(wifi_reconnects)); json_close(); @@ -391,20 +380,8 @@ void handle_sysinfo_Network() { addRowLabelValue(LabelType::CLIENT_IP); addRowLabelValue(LabelType::DNS); addRowLabelValue(LabelType::ALLOWED_IP_RANGE); - addRowLabel(getLabel(LabelType::STA_MAC)); - - { - uint8_t mac[] = { 0, 0, 0, 0, 0, 0 }; - uint8_t *macread = WiFi.macAddress(mac); - char macaddress[20]; - formatMAC(macread, macaddress); - addHtml(macaddress); - - addRowLabel(getLabel(LabelType::AP_MAC)); - macread = WiFi.softAPmacAddress(mac); - formatMAC(macread, macaddress); - addHtml(macaddress); - } + addRowLabelValue(LabelType::STA_MAC); + addRowLabelValue(LabelType::AP_MAC); addRowLabel(getLabel(LabelType::SSID)); { diff --git a/src/_C014.ino b/src/_C014.ino index 1e668d252..d8588d232 100644 --- a/src/_C014.ino +++ b/src/_C014.ino @@ -246,7 +246,7 @@ bool CPlugin_014(CPlugin::Function function, struct EventStruct *event, String& CPlugin_014_sendMQTTdevice(pubname,"$localip",formatIP(NetworkLocalIP()).c_str(),errorCounter); // $mac Device → Controller Mac address of the device network interface. The format MUST be of the type A1:B2:C3:D4:E5:F6 Yes Yes - CPlugin_014_sendMQTTdevice(pubname,"$mac",WiFi.macAddress().c_str(),errorCounter); + CPlugin_014_sendMQTTdevice(pubname,"$mac",NetworkMacAddress().c_str(),errorCounter); // $implementation Device → Controller An identifier for the Homie implementation (example esp8266) Yes Yes #if defined(ESP8266) diff --git a/src/src/Commands/Settings.cpp b/src/src/Commands/Settings.cpp index 00637baab..23022d996 100644 --- a/src/src/Commands/Settings.cpp +++ b/src/src/Commands/Settings.cpp @@ -71,7 +71,7 @@ String Command_Settings_Print(struct EventStruct *event, const char* Line) serialPrintln(); serialPrintln(F("System Info")); - serialPrint(F(" IP Address : ")); serialPrintln(WiFi.localIP().toString()); + serialPrint(F(" IP Address : ")); serialPrintln(NetworkLocalIP().toString()); serialPrint(F(" Build : ")); serialPrintln(String((int)BUILD)); serialPrint(F(" Name : ")); serialPrintln(Settings.Name); serialPrint(F(" Unit : ")); serialPrintln(String((int)Settings.Unit)); From 0a2896a0f30716ab4b37b7f88708a37a00d63529 Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Wed, 29 Apr 2020 22:12:09 +0200 Subject: [PATCH 29/39] This String function is not needed, because there is a ETH.macAddress() which returns a String. I changed it to the byte version of the function and now uint8_t * NetworkMacAddressAsBytes(uint8_t* mac) returns either this in Ethernet mode or WiFi.macAddress(mac) in Wifi mode. --- src/ESPEasyEth.cpp | 7 ++----- src/ESPEasyEth.h | 5 ++++- src/ESPEasyNetwork.cpp | 8 ++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/ESPEasyEth.cpp b/src/ESPEasyEth.cpp index feacd6c1a..587040022 100644 --- a/src/ESPEasyEth.cpp +++ b/src/ESPEasyEth.cpp @@ -102,12 +102,9 @@ void ethPrintSettings() { addLog(LOG_LEVEL_INFO, settingsDebugLog); } -String ETHMacAddress() { - uint8_t mac[6]; - char macStr[18] = { 0 }; +uint8_t * ETHMacAddress(uint8_t* mac) { esp_eth_get_mac(mac); - sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - return String(macStr); + return mac; } void ETHConnectRelaxed() { diff --git a/src/ESPEasyEth.h b/src/ESPEasyEth.h index a0bf7c8b2..b130144e9 100644 --- a/src/ESPEasyEth.h +++ b/src/ESPEasyEth.h @@ -1,3 +1,4 @@ +#ifdef HAS_ETHERNET #ifndef ESPEASY_ETH_H #define ESPEASY_ETH_H @@ -12,5 +13,7 @@ String ethGetDebugEthWifiModeStr(); void ethPrintSettings(); void ETHConnectRelaxed(); bool ETHConnected(); +uint8_t * ETHMacAddress(uint8_t* mac); -#endif // ESPEASY_ETH_H \ No newline at end of file +#endif // ESPEASY_ETH_H +#endif \ No newline at end of file diff --git a/src/ESPEasyNetwork.cpp b/src/ESPEasyNetwork.cpp index 9b6b2b861..67e3e03c6 100644 --- a/src/ESPEasyNetwork.cpp +++ b/src/ESPEasyNetwork.cpp @@ -125,7 +125,15 @@ String NetworkMacAddress() { } uint8_t * NetworkMacAddressAsBytes(uint8_t* mac) { + #ifdef HAS_ETHERNET + if(eth_wifi_mode == ETHERNET) { + return ETHMacAddress(mac); + } else { + return WiFi.macAddress(mac); + } + #else return WiFi.macAddress(mac); + #endif } String NetworkGetHostname() { From d326264c370cd2b5fffb2c9a09ac222a6c91bd2f Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Thu, 30 Apr 2020 11:26:05 +0200 Subject: [PATCH 30/39] Check changed as requested by TD-er --- src/ESPEasyEth.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ESPEasyEth.cpp b/src/ESPEasyEth.cpp index 587040022..5d7ce21bd 100644 --- a/src/ESPEasyEth.cpp +++ b/src/ESPEasyEth.cpp @@ -7,7 +7,7 @@ #include "eth_phy/phy.h" bool ethUseStaticIP() { - return Settings.ETH_IP[0] != 0 && Settings.ETH_IP[3] != 255; + return Settings.ETH_IP[0] != 0 && Settings.ETH_IP[0] != 255; } void ethSetupStaticIPconfig() { From 7f1b359c316013cb7028069b363fbffd3c90d74a Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Thu, 30 Apr 2020 21:24:20 +0200 Subject: [PATCH 31/39] addFormNote(F("Be aware with ESPEasyP2P Network, since IP Address will change. There could be conflicts.")); not used anymore because P2P UDP works good --- platformio_esp32_envs.ini | 2 ++ src/ESPEasy.ino | 10 ++++++++++ src/StringProvider.ino | 2 +- src/WebServer_HardwarePage.ino | 1 - 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/platformio_esp32_envs.ini b/platformio_esp32_envs.ini index 1bfc0e7ec..3ba788261 100644 --- a/platformio_esp32_envs.ini +++ b/platformio_esp32_envs.ini @@ -22,6 +22,8 @@ build_flags = ${mqtt_flags.build_flags} -DCONFIG_FREERTOS_ASSERT_DISABLE -DCONFIG_LWIP_ESP_GRATUITOUS_ARP -DCONFIG_LWIP_GARP_TMR_INTERVAL=30 +upload_port = /dev/cu.wchusbserial14630 +upload_speed = 921600 ; Custom: 4096k version -------------------------- diff --git a/src/ESPEasy.ino b/src/ESPEasy.ino index 28fcb2938..62197a67a 100644 --- a/src/ESPEasy.ino +++ b/src/ESPEasy.ino @@ -916,8 +916,18 @@ void runEach30Seconds() log += connectionFailures; log += F(" FreeMem "); log += FreeMem(); + #ifdef HAS_ETHERNET + if(eth_wifi_mode == ETHERNET) { + log += F( " EthSpeedState "); + log += getValue(LabelType::ETH_SPEED_STATE); + } else { + log += F(" WiFiStatus "); + log += WiFi.status(); + } + #else log += F(" WiFiStatus "); log += WiFi.status(); + #endif // log += F(" ListenInterval "); // log += WiFi.getListenInterval(); addLog(LOG_LEVEL_INFO, log); diff --git a/src/StringProvider.ino b/src/StringProvider.ino index 618e92824..474d10263 100644 --- a/src/StringProvider.ino +++ b/src/StringProvider.ino @@ -228,7 +228,7 @@ String getValue(LabelType::Enum label) { case LabelType::ETH_STATE: return eth_connected ? (ETH.linkUp() ? F("Link Up") : F("Link Down")) : F("No Ethernet"); case LabelType::ETH_SPEED_STATE: return eth_connected ? getEthLinkSpeedState() : F("No Ethernet"); case LabelType::ETH_WIFI_MODE: return (eth_wifi_mode == WIFI ? F("WIFI") : F("ETHERNET")); - case LabelType::ETH_CONNECTED: return String(eth_connected); // 0=disconnected, 1=connected + case LabelType::ETH_CONNECTED: return (eth_connected ? F("CONNECTED") : F("DISCONNECTED")); // 0=disconnected, 1=connected #endif } diff --git a/src/WebServer_HardwarePage.ino b/src/WebServer_HardwarePage.ino index 71a5a2541..f143be84d 100644 --- a/src/WebServer_HardwarePage.ino +++ b/src/WebServer_HardwarePage.ino @@ -90,7 +90,6 @@ void handle_hardware() { String ethWifiOptions[2] = { F("WIFI"), F("ETHERNET") }; addSelector("ethwifi", 2, ethWifiOptions, NULL, NULL, Settings.ETH_Wifi_Mode, false, true); addFormNote(F("Change Switch between WIFI and ETHERNET requires reboot to activate")); - addFormNote(F("Be aware with ESPEasyP2P Network, since IP Address will change. There could be conflicts.")); addRowLabel_tr_id(F("Ethernet PHY type"), "ethtype"); String ethPhyTypes[2] = { F("LAN8710"), F("TLK110") }; addSelector("ethtype", 2, ethPhyTypes, NULL, NULL, Settings.ETH_Phy_Type, false, true); From efebcc8d0135e0c0a4f9e7661c810980695935d2 Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Thu, 30 Apr 2020 21:27:12 +0200 Subject: [PATCH 32/39] removede personal upload flags --- platformio_esp32_envs.ini | 2 -- 1 file changed, 2 deletions(-) diff --git a/platformio_esp32_envs.ini b/platformio_esp32_envs.ini index 3ba788261..1bfc0e7ec 100644 --- a/platformio_esp32_envs.ini +++ b/platformio_esp32_envs.ini @@ -22,8 +22,6 @@ build_flags = ${mqtt_flags.build_flags} -DCONFIG_FREERTOS_ASSERT_DISABLE -DCONFIG_LWIP_ESP_GRATUITOUS_ARP -DCONFIG_LWIP_GARP_TMR_INTERVAL=30 -upload_port = /dev/cu.wchusbserial14630 -upload_speed = 921600 ; Custom: 4096k version -------------------------- From b0577f3447b422d34afead804a3046c27e6e3d43 Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Fri, 1 May 2020 13:43:47 +0200 Subject: [PATCH 33/39] _P124_Atlas_EZO_pH.ino and _P222_Atlas_EZO_ORP.ino deleted since ther are not in ESPEasy but in Playground. There is another Issu, to put them in ESPEasy mega --- src/_P214_Atlas_EZO_pH.ino | 450 ------------------------------------ src/_P222_Atlas_EZO_ORP.ino | 365 ----------------------------- 2 files changed, 815 deletions(-) delete mode 100644 src/_P214_Atlas_EZO_pH.ino delete mode 100644 src/_P222_Atlas_EZO_ORP.ino diff --git a/src/_P214_Atlas_EZO_pH.ino b/src/_P214_Atlas_EZO_pH.ino deleted file mode 100644 index ca4896405..000000000 --- a/src/_P214_Atlas_EZO_pH.ino +++ /dev/null @@ -1,450 +0,0 @@ -//######################################################################## -//################## Plugin 214 : Atlas Scientific EZO Ph sensor ######## -//######################################################################## - -// datasheet at https://www.atlas-scientific.com/_files/_datasheets/_circuit/pH_EZO_datasheet.pdf -// works only in i2c mode - -#define PLUGIN_214 -#define PLUGIN_ID_214 214 -#define PLUGIN_NAME_214 "Environment - Atlas Scientific pH EZO [TESTING]" -#define PLUGIN_VALUENAME1_214 "pH" -#define PLUGIN_VALUENAME2_214 "Voltage" - -boolean Plugin_214_init = false; - -boolean Plugin_214(byte function, struct EventStruct *event, String& string) -{ - boolean success = false; - - switch (function) - { - case PLUGIN_DEVICE_ADD: - { - Device[++deviceCount].Number = PLUGIN_ID_214; - Device[deviceCount].Type = DEVICE_TYPE_I2C; - Device[deviceCount].VType = SENSOR_TYPE_SINGLE; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = true; - Device[deviceCount].ValueCount = 2; - Device[deviceCount].SendDataOption = true; - Device[deviceCount].TimerOption = true; - Device[deviceCount].GlobalSyncOption = true; - break; - } - - case PLUGIN_GET_DEVICENAME: - { - string = F(PLUGIN_NAME_214); - break; - } - - case PLUGIN_GET_DEVICEVALUENAMES: - { - strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_214)); - strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_214)); - break; - } - - case PLUGIN_WEBFORM_LOAD: - { - #define _P214_ATLASEZO_I2C_NB_OPTIONS 4 - byte I2Cchoice = Settings.TaskDevicePluginConfig[event->TaskIndex][0]; - int optionValues[_P214_ATLASEZO_I2C_NB_OPTIONS] = { 0x63, 0x64, 0x65, 0x66 }; - addFormSelectorI2C(F("plugin_214_i2c"), _P214_ATLASEZO_I2C_NB_OPTIONS, optionValues, I2Cchoice); - - addFormSubHeader(F("General")); - - char sensordata[32]; - bool info; - info = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"i",sensordata); - - if (info) { - String boardInfo(sensordata); - - addHtml(F("Board type : ")); - int pos1 = boardInfo.indexOf(','); - int pos2 = boardInfo.lastIndexOf(','); - addHtml(boardInfo.substring(pos1+1,pos2)); - if (boardInfo.substring(pos1+1,pos2) != "pH"){ - addHtml(F(" WARNING : Board type should be 'pH', check your i2c Address ? ")); - } - addHtml(F("Board version :")); - addHtml(boardInfo.substring(pos2+1)); - addHtml(F("")); - - addHtml(F("")); - - } else { - addHtml(F("Unable to send command to device")); - success = false; - break; - } - - addFormCheckBox(F("Status LED"),F("Plugin_214_status_led"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]); - - char statussensordata[32]; - bool status; - status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Status",statussensordata); - - if (status) { - String boardStatus(statussensordata); - - addHtml(F("Board restart code: ")); - int pos1 = boardStatus.indexOf(','); - int pos2 = boardStatus.lastIndexOf(','); - switch ((char)boardStatus.substring(pos1+1,pos2)[0]) - { - case 'P': - { - addHtml(F("powered off")); - break; - } - case 'S': - { - addHtml(F("software reset")); - break; - } - case 'B': - { - addHtml(F("brown out")); - break; - } - case 'W': - { - addHtml(F("watch dog")); - break; - } - case 'U': - default: - { - addHtml(F("unknown")); - break; - } - } - - addHtml(F("Board voltage :")); - addHtml(boardStatus.substring(pos2+1)); - addHtml(F(" V")); - - addHtml(F("")); - - } else { - addHtml(F("Unable to send status command to device")); - success = false; - break; - } - - addFormSubHeader(F("Calibration")); - - int nb_calibration_points = -1; - status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0], "Cal,?",sensordata); - - if (status){ - if (strncmp(sensordata,"?Cal,",5)){ - char tmp[2]; - tmp[0] = sensordata[5]; - tmp[1] = '\0', - nb_calibration_points = atoi(tmp); - } - } - - addRowLabel(F("Middle")); - addFormNumericBox(F("Ref Ph"),F("Plugin_214_ref_cal_M' step='0.01"),Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1],1,14); - if (nb_calibration_points > 0) { - addHtml(F(" OK")); - } else { - addHtml(F(" Not yet calibrated")); - } - addFormCheckBox(F("Enable"),F("Plugin_214_enable_cal_M"), false); - addHtml(F("\n\n")); - - addRowLabel(F("Low")); - addFormNumericBox(F("Ref Ph"),F("Plugin_214_ref_cal_L' step='0.01"), Settings.TaskDevicePluginConfigFloat[event->TaskIndex][2],1,14); - if (nb_calibration_points > 1) { - addHtml(F(" OK")); - } else { - addHtml(F(" Not yet calibrated")); - } - addFormCheckBox(F("Enable"),F("Plugin_214_enable_cal_L"), false); - addHtml(F("\n\n")); - - addHtml(F("High")); - addFormNumericBox(F("Ref Ph"),F("Plugin_214_ref_cal_H' step='0.01"), Settings.TaskDevicePluginConfigFloat[event->TaskIndex][3],1,14); - if (nb_calibration_points > 2) { - addHtml(F(" OK")); - } else { - addHtml(F(" Not yet calibrated")); - } - addFormCheckBox(F("Enable"),F("Plugin_214_enable_cal_H"), false); - addHtml(F("\n\n")); - - if (nb_calibration_points > 1){ - char sensordata[32]; - char cmd[8] = "Slope,?"; - bool status; - status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],cmd,sensordata); - - if (status){ - String slopeAnswer("Answer to 'Slope' command : "); - slopeAnswer += sensordata; - addFormNote(slopeAnswer); - } - } - - addFormSubHeader(F("Temperature compensation")); - char deviceTemperatureTemplate[40]; - LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate)); - addFormTextBox(F("Temperature "), F("Plugin_214_temperature_template"), deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate)); - addFormNote(F("You can use a formulae (and idealy refer to a temp sensor). ")); - float value; - char strValue[5]; - String deviceTemperatureTemplateString(deviceTemperatureTemplate); - String pooltempString(parseTemplate(deviceTemperatureTemplateString, 40)); - addHtml(F("
")); - if (Calculate(pooltempString.c_str(),&value) == CALCULATE_OK ){ - addHtml(F("Actual value : ")); - dtostrf(value,5,2,strValue); - addHtml(strValue); - } else { - addHtml(F("(It seems I can't parse your formulae)")); - } - - addHtml(F("
")); - - success = true; - break; - } - - case PLUGIN_WEBFORM_SAVE: - { - Settings.TaskDevicePluginConfig[event->TaskIndex][0] = getFormItemInt(F("plugin_214_i2c")); - - Settings.TaskDevicePluginConfigFloat[event->TaskIndex][0] = getFormItemFloat(F("plugin_214_sensorVersion")); - - char sensordata[32]; - if (isFormItemChecked(F("Plugin_214_status_led"))) { - _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"L,1",sensordata); - } else { - _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"L,0",sensordata); - } - Settings.TaskDevicePluginConfig[event->TaskIndex][1] = isFormItemChecked(F("Plugin_214_status_led")); - - - Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1] = getFormItemFloat(F("Plugin_214_ref_cal_M")); - Settings.TaskDevicePluginConfigFloat[event->TaskIndex][2] = getFormItemFloat(F("Plugin_214_ref_cal_L")); - Settings.TaskDevicePluginConfigFloat[event->TaskIndex][3] = getFormItemFloat(F("Plugin_214_ref_cal_H")); - - String cmd ("Cal,"); - bool triggerCalibrate = false; - if (isFormItemChecked("Plugin_214_enable_cal_M")) { - cmd += "mid,"; - cmd += Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1]; - triggerCalibrate = true; - } else if (isFormItemChecked("Plugin_214_enable_cal_L")){ - cmd += "low,"; - cmd += Settings.TaskDevicePluginConfigFloat[event->TaskIndex][2]; - triggerCalibrate = true; - } else if (isFormItemChecked("Plugin_214_enable_cal_H")){ - cmd += "high,"; - cmd += Settings.TaskDevicePluginConfigFloat[event->TaskIndex][3]; - triggerCalibrate = true; - } - if (triggerCalibrate){ - char sensordata[32]; - _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],cmd.c_str(),sensordata); - } - - char deviceTemperatureTemplate[40]; - String tmpString = web_server.arg(F("Plugin_214_temperature_template")); - strncpy(deviceTemperatureTemplate, tmpString.c_str(), sizeof(deviceTemperatureTemplate)-1); - deviceTemperatureTemplate[sizeof(deviceTemperatureTemplate)-1]=0; //be sure that our string ends with a \0 - - SaveCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate)); - - Plugin_214_init = false; - success = true; - break; - } - - case PLUGIN_INIT: - { - Plugin_214_init = true; - } - - case PLUGIN_READ: - { - char sensordata[32]; - bool status; - - //first set the temperature of reading - char deviceTemperatureTemplate[40]; - LoadCustomTaskSettings(event->TaskIndex, (byte*)&deviceTemperatureTemplate, sizeof(deviceTemperatureTemplate)); - - String deviceTemperatureTemplateString(deviceTemperatureTemplate); - String pooltempString(parseTemplate(deviceTemperatureTemplateString, 40)); - //String setTemperature("T,"); - String setTemperature("RT,"); - float temperatureReading; - if (Calculate(pooltempString.c_str(),&temperatureReading) == CALCULATE_OK ){ - setTemperature += temperatureReading; - } else { - success = false; - break; - } - - //ok, now we can read the pH value with Temperature compensation - status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],setTemperature.c_str(),sensordata); - - //ok, now we can read the pH value - //status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"r",sensordata); - - //we read the voltagedata char statussensordata[32]; - char voltagedata[32]; - status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Status",voltagedata); - - - if (status){ - String sensorString(sensordata); - String voltage(voltagedata); - int pos = voltage.lastIndexOf(','); - UserVar[event->BaseVarIndex] = sensorString.toFloat(); - UserVar[event->BaseVarIndex + 1] = voltage.substring(pos+1).toFloat(); - } - else { - UserVar[event->BaseVarIndex] = -1; - UserVar[event->BaseVarIndex + 1] = -1; - } - - //go to sleep - //status = _P214_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Sleep",sensordata); - - success = true; - break; - } - case PLUGIN_WRITE: - { - //TODO : do something more usefull ... - - String tmpString = string; - int argIndex = tmpString.indexOf(','); - if (argIndex) - tmpString = tmpString.substring(0, argIndex); - if (tmpString.equalsIgnoreCase(F("ATLASCMD"))) - { - success = true; - argIndex = string.lastIndexOf(','); - tmpString = string.substring(argIndex + 1); - if (tmpString.equalsIgnoreCase(F("CalMid"))){ - String log("Asking for Mid calibration "); - addLog(LOG_LEVEL_INFO, log); - } - else if (tmpString.equalsIgnoreCase(F("CalLow"))){ - String log("Asking for Low calibration "); - addLog(LOG_LEVEL_INFO, log); - } - else if (tmpString.equalsIgnoreCase(F("CalHigh"))){ - String log("Asking for High calibration "); - addLog(LOG_LEVEL_INFO, log); - } - } - break; - } - } - return success; -} - -// Call this function with two char arrays, one containing the command -// The other containing an allocatted char array for answer -// Returns true on success, false otherwise - -bool _P214_send_I2C_command(uint8_t I2Caddress,const char * cmd, char* sensordata) { - uint16_t sensor_bytes_received = 0; - - byte error; - byte i2c_response_code = 0; - byte in_char = 0; - - addLog(LOG_LEVEL_DEBUG, String(cmd)); - Wire.beginTransmission(I2Caddress); - Wire.write(cmd); - error = Wire.endTransmission(); - - if (error != 0) { - //addLog(LOG_LEVEL_ERROR, error); - addLog(LOG_LEVEL_ERROR, F("Wire.endTransmission() returns error: Check pH shield")); - return false; - } - - //don't read answer if we want to go to sleep - if (strncmp(cmd,"Sleep",5) == 0) { - return true; - } - - i2c_response_code = 254; - while (i2c_response_code == 254) { // in case the cammand takes longer to process, we keep looping here until we get a success or an error - - if ( - ( (cmd[0] == 'r' || cmd[0] == 'R') && cmd[1] == '\0' ) - || - ( ( strncmp(cmd,"cal",3) || strncmp(cmd,"Cal",3) ) && !strncmp(cmd,"Cal,?",5) ) - ) - { - delay(900); - } - else { - delay(300); - } - - Wire.requestFrom(I2Caddress, (uint8_t) 32); //call the circuit and request 32 bytes (this is more then we need). - i2c_response_code = Wire.read(); //read response code - - while (Wire.available()) { //read response - in_char = Wire.read(); - - if (in_char == 0) { //if we receive a null caracter, we're done - while (Wire.available()) { //purge the data line if needed - Wire.read(); - } - - break; //exit the while loop. - } - else { - sensordata[sensor_bytes_received] = in_char; //load this byte into our array. - sensor_bytes_received++; - } - } - sensordata[sensor_bytes_received] = '\0'; - - switch (i2c_response_code) { - case 1: - { - String log = F("< success, answer = "); - log += sensordata; - addLog(LOG_LEVEL_DEBUG, log); - } - break; - - case 2: - addLog(LOG_LEVEL_DEBUG, F("< command failed")); - return false; - - case 254: - addLog(LOG_LEVEL_DEBUG, F("< command pending")); - break; - - case 255: - addLog(LOG_LEVEL_DEBUG, F("< no data")); - return false; - } - } - - addLog(LOG_LEVEL_DEBUG, sensordata); - return true; -} diff --git a/src/_P222_Atlas_EZO_ORP.ino b/src/_P222_Atlas_EZO_ORP.ino deleted file mode 100644 index 9515283b7..000000000 --- a/src/_P222_Atlas_EZO_ORP.ino +++ /dev/null @@ -1,365 +0,0 @@ -//######################################################################## -//################## Plugin 222 : Atlas Scientific EZO ORP sensor ######## -//######################################################################## - -// datasheet at https://www.atlas-scientific.com/_files/_datasheets/_circuit/ORP_EZO_datasheet.pdf -// works only in i2c mode - -#define PLUGIN_222 -#define PLUGIN_ID_222 222 -#define PLUGIN_NAME_222 "Environment - Atlas Scientific ORP EZO" -#define PLUGIN_VALUENAME1_222 "ORP" -#define PLUGIN_VALUENAME2_222 "Voltage" - -boolean Plugin_222_init = false; - -boolean Plugin_222(byte function, struct EventStruct *event, String& string) -{ - boolean success = false; - - switch (function) - { - case PLUGIN_DEVICE_ADD: - { - Device[++deviceCount].Number = PLUGIN_ID_222; - Device[deviceCount].Type = DEVICE_TYPE_I2C; - Device[deviceCount].VType = SENSOR_TYPE_SINGLE; - Device[deviceCount].Ports = 0; - Device[deviceCount].PullUpOption = false; - Device[deviceCount].InverseLogicOption = false; - Device[deviceCount].FormulaOption = true; - Device[deviceCount].ValueCount = 2; - Device[deviceCount].SendDataOption = true; - Device[deviceCount].TimerOption = true; - Device[deviceCount].GlobalSyncOption = true; - break; - } - - case PLUGIN_GET_DEVICENAME: - { - string = F(PLUGIN_NAME_222); - break; - } - - case PLUGIN_GET_DEVICEVALUENAMES: - { - strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_222)); - strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_222)); - break; - } - - case PLUGIN_WEBFORM_LOAD: - { - #define _P222_ATLASEZO_I2C_NB_OPTIONS 4 - byte I2Cchoice = Settings.TaskDevicePluginConfig[event->TaskIndex][0]; - int optionValues[_P222_ATLASEZO_I2C_NB_OPTIONS] = { 0x62, 0x63, 0x64, 0x65 }; - addFormSelectorI2C(F("plugin_222_i2c"), _P222_ATLASEZO_I2C_NB_OPTIONS, optionValues, I2Cchoice); - - addFormSubHeader(F("General")); - - char sensordata[32]; - bool info; - info = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"i",sensordata); - - if (info) { - String boardInfo(sensordata); - - addHtml(F("Board type : ")); - int pos1 = boardInfo.indexOf(','); - int pos2 = boardInfo.lastIndexOf(','); - addHtml(boardInfo.substring(pos1+1,pos2)); - if (boardInfo.substring(pos1+1,pos2) != "ORP"){ - addHtml(F(" WARNING : Board type should be 'ORP', check your i2c Address ? ")); - } - addHtml(F("Board version :")); - addHtml(boardInfo.substring(pos2+1)); - addHtml(F("")); - - addHtml(F("")); - - } else { - addHtml(F("Unable to send command to device")); - success = false; - break; - } - - addFormCheckBox(F("Status LED"),F("Plugin_222_status_led"), Settings.TaskDevicePluginConfig[event->TaskIndex][1]); - - char statussensordata[32]; - bool status; - status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Status",statussensordata); - - if (status) { - String boardStatus(statussensordata); - - addHtml(F("Board restart code: ")); - int pos1 = boardStatus.indexOf(','); - int pos2 = boardStatus.lastIndexOf(','); - switch ((char)boardStatus.substring(pos1+1,pos2)[0]) - { - case 'P': - { - addHtml(F("powered off")); - break; - } - case 'S': - { - addHtml(F("software reset")); - break; - } - case 'B': - { - addHtml(F("brown out")); - break; - } - case 'W': - { - addHtml(F("watch dog")); - break; - } - case 'U': - default: - { - addHtml(F("unknown")); - break; - } - } - - addHtml(F("Board voltage :")); - addHtml(boardStatus.substring(pos2+1)); - addHtml(F(" V")); - - addHtml(F("")); - - } else { - addHtml(F("Unable to send status command to device")); - success = false; - break; - } - - addFormSubHeader(F("Calibration")); - - int nb_calibration_points = -1; - status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0], "Cal,?",sensordata); - - if (status){ - if (strncmp(sensordata,"?Cal,",5)){ - char tmp[2]; - tmp[0] = sensordata[5]; - tmp[1] = '\0', - nb_calibration_points = atoi(tmp); - } - } - - addRowLabel(F("ORP Calibration")); - addFormNumericBox(F("Ref ORP"),F("Plugin_222_ref_cal_M' step='1"),Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1],0,1500); - if (nb_calibration_points > 0) { - addHtml(F(" OK")); - } else { - addHtml(F(" Not yet calibrated")); - } - addFormCheckBox(F("Enable"),F("Plugin_222_enable_cal_M"), false); - - if (nb_calibration_points > 1){ - char sensordata[32]; - char cmd[8] = "Slope,?"; - bool status; - status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],cmd,sensordata); - - if (status){ - String slopeAnswer("Answer to 'Slope' command : "); - slopeAnswer += sensordata; - addFormNote(slopeAnswer); - } - } - - addHtml(F("")); - - success = true; - break; - } - - case PLUGIN_WEBFORM_SAVE: - { - Settings.TaskDevicePluginConfig[event->TaskIndex][0] = getFormItemInt(F("plugin_222_i2c")); - - Settings.TaskDevicePluginConfigFloat[event->TaskIndex][0] = getFormItemFloat(F("plugin_222_sensorVersion")); - - char sensordata[32]; - if (isFormItemChecked(F("Plugin_222_status_led"))) { - _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"L,1",sensordata); - } else { - _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"L,0",sensordata); - } - Settings.TaskDevicePluginConfig[event->TaskIndex][1] = isFormItemChecked(F("Plugin_222_status_led")); - - - Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1] = getFormItemFloat(F("Plugin_222_ref_cal_M")); - - String cmd ("Cal,"); - bool triggerCalibrate = false; - if (isFormItemChecked("Plugin_222_enable_cal_M")) { - cmd += Settings.TaskDevicePluginConfigFloat[event->TaskIndex][1]; - triggerCalibrate = true; - } - if (triggerCalibrate){ - char sensordata[32]; - _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],cmd.c_str(),sensordata); - } - - Plugin_222_init = false; - success = true; - break; - } - - case PLUGIN_INIT: - { - Plugin_222_init = true; - } - - case PLUGIN_READ: - { - char sensordata[32]; - bool status; - - //ok, now we can read the ORP value - status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"R",sensordata); - - //we read the voltagedata char statussensordata[32]; - char voltagedata[32]; - status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Status",voltagedata); - - if (status){ - String sensorString(sensordata); - String voltage(voltagedata); - int pos = voltage.lastIndexOf(','); - UserVar[event->BaseVarIndex] = sensorString.toFloat(); - UserVar[event->BaseVarIndex + 1] = voltage.substring(pos+1).toFloat(); - } - else { - UserVar[event->BaseVarIndex] = -1; - UserVar[event->BaseVarIndex + 1] = -1; - } - - //go to sleep - //status = _P222_send_I2C_command(Settings.TaskDevicePluginConfig[event->TaskIndex][0],"Sleep",sensordata); - - success = true; - break; - } - case PLUGIN_WRITE: - { - //TODO : do something more usefull ... - - String tmpString = string; - int argIndex = tmpString.indexOf(','); - if (argIndex) - tmpString = tmpString.substring(0, argIndex); - if (tmpString.equalsIgnoreCase(F("ATLASCMD"))) - { - success = true; - argIndex = string.lastIndexOf(','); - tmpString = string.substring(argIndex + 1); - if (tmpString.equalsIgnoreCase(F("CalMid"))){ - String log("Asking for calibration "); - addLog(LOG_LEVEL_INFO, log); - } - } - break; - } - } - return success; -} - -// Call this function with two char arrays, one containing the command -// The other containing an allocatted char array for answer -// Returns true on success, false otherwise - -bool _P222_send_I2C_command(uint8_t I2Caddress,const char * cmd, char* sensordata) { - uint16_t sensor_bytes_received = 0; - - byte error; - byte i2c_response_code = 0; - byte in_char = 0; - - addLog(LOG_LEVEL_DEBUG, String(cmd)); - Wire.beginTransmission(I2Caddress); - Wire.write(cmd); - error = Wire.endTransmission(); - - if (error != 0) { - //addLog(LOG_LEVEL_ERROR, error); - addLog(LOG_LEVEL_ERROR, F("Wire.endTransmission() returns error: Check ORP shield")); - return false; - } - - //don't read answer if we want to go to sleep - if (strncmp(cmd,"Sleep",5) == 0) { - return true; - } - - i2c_response_code = 254; - while (i2c_response_code == 254) { // in case the cammand takes longer to process, we keep looping here until we get a success or an error - - if ( - ( (cmd[0] == 'r' || cmd[0] == 'R') && cmd[1] == '\0' ) - || - ( ( strncmp(cmd,"cal",3) || strncmp(cmd,"Cal",3) ) && !strncmp(cmd,"Cal,?",5) ) - ) - { - delay(900); - } - else { - delay(300); - } - - Wire.requestFrom(I2Caddress, (uint8_t) 32); //call the circuit and request 32 bytes (this is more then we need). - i2c_response_code = Wire.read(); //read response code - - while (Wire.available()) { //read response - in_char = Wire.read(); - - if (in_char == 0) { //if we receive a null caracter, we're done - while (Wire.available()) { //purge the data line if needed - Wire.read(); - } - - break; //exit the while loop. - } - else { - sensordata[sensor_bytes_received] = in_char; //load this byte into our array. - sensor_bytes_received++; - } - } - sensordata[sensor_bytes_received] = '\0'; - - switch (i2c_response_code) { - case 1: - { - String log = F("< success, answer = "); - log += sensordata; - addLog(LOG_LEVEL_DEBUG, log); - } - break; - - case 2: - addLog(LOG_LEVEL_DEBUG, F("< command failed")); - return false; - - case 254: - addLog(LOG_LEVEL_DEBUG, F("< command pending")); - break; - - case 255: - addLog(LOG_LEVEL_DEBUG, F("< no data")); - return false; - } - } - - addLog(LOG_LEVEL_DEBUG, sensordata); - return true; -} From ca034db1ad4feda5f2e8c00a1883b68880de99bc Mon Sep 17 00:00:00 2001 From: Peter Kretz Date: Wed, 6 May 2020 21:27:22 +0200 Subject: [PATCH 34/39] - Error in Network Name fpr WiFi fixed - logging improvements --- src/ESPEasyWiFiEvent.cpp | 16 +++++++++++----- src/ESPEasyWifi.cpp | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/ESPEasyWiFiEvent.cpp b/src/ESPEasyWiFiEvent.cpp index 2b9c17e86..939b1e884 100644 --- a/src/ESPEasyWiFiEvent.cpp +++ b/src/ESPEasyWiFiEvent.cpp @@ -121,13 +121,19 @@ void WiFiEvent(system_event_id_t event, system_event_info_t info) { case SYSTEM_EVENT_ETH_GOT_IP: { String log = F("ETH MAC: "); - log += ETH.macAddress(); - log += F(", IPv4: "); - log += ETH.localIP().toString(); + log += NetworkMacAddress(); + log += F(" IPv4: "); + log += NetworkLocalIP().toString(); + log += " ("; + log += NetworkGetHostname(); + log += F(") GW: "); + log += NetworkGatewayIP().toString(); + log += F(" SN: "); + log += NetworkSubnetMask().toString(); if (ETH.fullDuplex()) { - log += F(", FULL_DUPLEX"); + log += F(" FULL_DUPLEX"); } - log += F(", "); + log += F(" "); log += ETH.linkSpeed(); log += F("Mbps"); addLog(LOG_LEVEL_INFO, log); diff --git a/src/ESPEasyWifi.cpp b/src/ESPEasyWifi.cpp index 05dff9d98..f4d55eb66 100644 --- a/src/ESPEasyWifi.cpp +++ b/src/ESPEasyWifi.cpp @@ -206,7 +206,7 @@ bool prepareWiFi() { } setSTA(true); char hostname[40]; - safe_strncpy(hostname, NetworkGetHostname().c_str(), sizeof(hostname)); + safe_strncpy(hostname, NetworkCreateRFCCompliantHostname().c_str(), sizeof(hostname)); #if defined(ESP8266) wifi_station_set_hostname(hostname); From dbb5522f30d62e690911f12a3741186aea9ec965 Mon Sep 17 00:00:00 2001 From: Florin Date: Fri, 22 May 2020 23:04:33 -0400 Subject: [PATCH 35/39] Disable Arduino OTA by default for ESP32 --- src/ESPEasyStorage.ino | 4 ++++ src/ESPEasy_common.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ESPEasyStorage.ino b/src/ESPEasyStorage.ino index 700e60898..61bd882e2 100644 --- a/src/ESPEasyStorage.ino +++ b/src/ESPEasyStorage.ino @@ -3,6 +3,10 @@ #include "src/Globals/ResetFactoryDefaultPref.h" #include "src/Globals/Plugins.h" +#ifdef ESP32 //MFD: These were missing when not using the ARDUINO_OTA lib + #include + #include +#endif /********************************************************************************************\ SPIFFS error handling Look here for error # reference: https://github.com/pellepl/spiffs/blob/master/src/spiffs.h diff --git a/src/ESPEasy_common.h b/src/ESPEasy_common.h index b69eebbc5..a9fcdbbf1 100644 --- a/src/ESPEasy_common.h +++ b/src/ESPEasy_common.h @@ -106,7 +106,7 @@ String getUnknownString(); // #define FEATURE_MDNS #endif #if defined(ESP32) - #define FEATURE_ARDUINO_OTA + //#define FEATURE_ARDUINO_OTA //#define FEATURE_MDNS #endif From 58413c219bb519801fb6702e1ef79359264f16af Mon Sep 17 00:00:00 2001 From: bccrew <8138958+bccrew@users.noreply.github.com> Date: Tue, 9 Jun 2020 20:41:21 +0200 Subject: [PATCH 36/39] Change FormSubHeader to clarify difference between IP settings of LAN or WiFi --- src/WebServer_ConfigPage.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/WebServer_ConfigPage.ino b/src/WebServer_ConfigPage.ino index 471ab92ff..aea5bfe9f 100644 --- a/src/WebServer_ConfigPage.ino +++ b/src/WebServer_ConfigPage.ino @@ -149,12 +149,12 @@ void handle_config() { addFormIPBox(F("Access IP upper range"), F("iprangehigh"), iphigh); } - addFormSubHeader(F("IP Settings")); + addFormSubHeader(F("WiFi IP Settings")); - addFormIPBox(F("ESP IP"), F("espip"), Settings.IP); - addFormIPBox(F("ESP GW"), F("espgateway"), Settings.Gateway); - addFormIPBox(F("ESP Subnetmask"), F("espsubnet"), Settings.Subnet); - addFormIPBox(F("ESP DNS"), F("espdns"), Settings.DNS); + addFormIPBox(F("ESP WiFi IP"), F("espip"), Settings.IP); + addFormIPBox(F("ESP WiFi GW"), F("espgateway"), Settings.Gateway); + addFormIPBox(F("ESP WiFi Subnetmask"), F("espsubnet"), Settings.Subnet); + addFormIPBox(F("ESP WiFi DNS"), F("espdns"), Settings.DNS); addFormNote(F("Leave empty for DHCP")); #ifdef HAS_ETHERNET From 9a17df2aebe4793f615f87c5239e2ada9013a1aa Mon Sep 17 00:00:00 2001 From: tonhuisman Date: Sun, 21 Jun 2020 18:42:06 +0200 Subject: [PATCH 37/39] [Transformation] Add P/p (Password display) --- docs/source/Rules/Rules.rst | 8 ++++++++ src/Misc.ino | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/docs/source/Rules/Rules.rst b/docs/source/Rules/Rules.rst index 50a74ee43..71a40dfc8 100644 --- a/docs/source/Rules/Rules.rst +++ b/docs/source/Rules/Rules.rst @@ -388,6 +388,7 @@ Transformation * A "binary" transformation can be "inverted" by adding a leading ``!``. * A "binary" value is considered 0 when its string value is "0" or empty, otherwise it is an 1. (float values are rounded) * A "binary" value can also be used to detect presence of a string, as it is 0 on an empty string or 1 otherwise. +* If the transformation contains ``R``, under certain circumstances, the value will be right-aligned. Binary transformations: @@ -417,9 +418,16 @@ Floating point transformations: * ``F``: Floor (round down) * ``E``: cEiling (round up) +Other transformations: + +* ``p``: Password display, replacing all value characters by asterisks ``*``. If the value is "0", nothing will be displayed. +* ``Pc``: Password display with custom character ``c``. For example P- will display value "123" as "---". If the value is "0", nothing will be displayed. + Justification ^^^^^^^^^^^^^ +To apply a justification, a transformation must also be used. If no transformation is needed, use the ``V`` (value) transformation. + * ``Pn``: Prefix Fill with n spaces. * ``Sn``: Suffix Fill with n spaces. * ``Ln``: Left part of the string, n characters. diff --git a/src/Misc.ino b/src/Misc.ino index b033c4f5b..cc26bab5d 100644 --- a/src/Misc.ino +++ b/src/Misc.ino @@ -1980,6 +1980,33 @@ void transformValue( { case 'V': //value = value without transformations break; + case 'P': // Password hide using a custom password character: Pc + if (tempValueFormatLength > 1) + { + if (value == F("0")) { + value = ""; + } else { + const int valueLength = value.length(); + for (int i = 0; i < valueLength; i++) { + value[i] = tempValueFormat[1]; + } + } + } else { + value = F("ERR"); + } + break; + case 'p': // Password hide using asterisks + { + if (value == F("0")) { + value = ""; + } else { + const int valueLength = value.length(); + for (int i = 0; i < valueLength; i++) { + value[i] = '*'; + } + } + } + break; case 'O': value = logicVal == 0 ? F("OFF") : F(" ON"); //(equivalent to XOR operator) break; From 1b55ddc84a6a5a598c4b4bc17860542b1e262b48 Mon Sep 17 00:00:00 2001 From: Gijs Noorlander Date: Mon, 22 Jun 2020 12:02:37 +0200 Subject: [PATCH 38/39] [ESP32] Only define FEATURE_ARDUINO_OTA in build config, not in .h files --- platformio_esp32_envs.ini | 8 ++++++-- tools/pio/pre_custom_esp32.py | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/platformio_esp32_envs.ini b/platformio_esp32_envs.ini index 0e1dc2ffe..f566fa1f6 100644 --- a/platformio_esp32_envs.ini +++ b/platformio_esp32_envs.ini @@ -40,7 +40,9 @@ extra_scripts = ${esp32_common.extra_scripts} [env:test_ESP32_4M316k] extends = esp32_common platform = ${esp32_common.platform} -build_flags = ${esp32_common.build_flags} -DPLUGIN_SET_TEST_ESP32 +build_flags = ${esp32_common.build_flags} + -DFEATURE_ARDUINO_OTA + -DPLUGIN_SET_TEST_ESP32 board = esp32dev extra_scripts = ${esp32_common.extra_scripts} @@ -48,7 +50,9 @@ extra_scripts = ${esp32_common.extra_scripts} [env:test_ESP32-wrover-kit_4M316k] extends = esp32_common platform = ${esp32_common.platform} -build_flags = ${esp32_common.build_flags} -DPLUGIN_SET_TEST_ESP32 +build_flags = ${esp32_common.build_flags} + -DFEATURE_ARDUINO_OTA + -DPLUGIN_SET_TEST_ESP32 board = esp-wrover-kit upload_protocol = ftdi debug_tool = ftdi diff --git a/tools/pio/pre_custom_esp32.py b/tools/pio/pre_custom_esp32.py index 72c301729..7f6b4ed02 100644 --- a/tools/pio/pre_custom_esp32.py +++ b/tools/pio/pre_custom_esp32.py @@ -38,7 +38,8 @@ else: "USES_P087", # Serial Proxy "USES_P097", # Touch (ESP32) - "USE_SETTINGS_ARCHIVE" + "USE_SETTINGS_ARCHIVE", + "FEATURE_ARDUINO_OTA" ]) print(env['CPPDEFINES']) From 70ffd6bb4a82620d3b79c809bbdf2674a42a71fb Mon Sep 17 00:00:00 2001 From: Gijs Noorlander Date: Mon, 22 Jun 2020 12:09:54 +0200 Subject: [PATCH 39/39] [Build] Disable test_beta_ESP8266_4M1M for now as it is too big --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 393fdeefd..c33d680d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -73,7 +73,7 @@ script: - PLATFORMIO_BUILD_FLAGS="-D CONTINUOUS_INTEGRATION" platformio run -e test_ESP8266_4M1M_VCC #- PLATFORMIO_BUILD_FLAGS="-D CONTINUOUS_INTEGRATION" platformio run -e test_ESP8266_4M1M_VCC_MDNS_SD #- PLATFORMIO_BUILD_FLAGS="-D CONTINUOUS_INTEGRATION" platformio run -e test_beta_ESP8266_16M_LittleFS - - PLATFORMIO_BUILD_FLAGS="-D CONTINUOUS_INTEGRATION" platformio run -e test_beta_ESP8266_4M1M + #- PLATFORMIO_BUILD_FLAGS="-D CONTINUOUS_INTEGRATION" platformio run -e test_beta_ESP8266_4M1M before_deploy: - ./before_deploy