Skip to content

Commit

Permalink
4.10.0
Browse files Browse the repository at this point in the history
- EID default feature (no new build)
- P1UM: option to support Ethernet + Wifi simultancly
- FIX RGB led issue
- AP_ONLY deleted; Almost never used
- fix blue led disconnnect ETH (P1EP)
  • Loading branch information
mhendriks committed Jan 26, 2025
1 parent 289dd6c commit a4e8c99
Show file tree
Hide file tree
Showing 58 changed files with 151 additions and 5,905 deletions.
23 changes: 4 additions & 19 deletions Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ uint32_t R_value = 0, B_value = 0, G_value = 0;
#ifdef __Az__
#include "hw_profile_p1_eth_az.h"
#else
#ifdef P1EP
#ifdef ETH_P1EP
#include "hw_profile_p1ep.h"
#else
#include "hw_profile_p1_eth.h"
Expand All @@ -50,14 +50,8 @@ uint32_t R_value = 0, B_value = 0, G_value = 0;
#endif

//FETAURES
#ifdef EID
bool bEID_enabled = true;
bool bEID_enabled = false;
enum E_eid_states : uint8_t { EID_IDLE, EID_CLAIMING, EID_ENROLLED };
#ifndef VICTRON_GRID
#undef MQTT_DISABLE
#define MQTT_DISABLE
#endif
#endif //EID

#ifdef DEBUG
#define OPT1 "[DEBUG]"
Expand All @@ -77,11 +71,7 @@ uint32_t R_value = 0, B_value = 0, G_value = 0;
#define OPT3
#endif

#ifdef EID
#define OPT4 "[EID]"
#else
#define OPT4
#endif
#define OPT4 "[EID]"

#ifdef POST_TELEGRAM
#define OPT5 "[POST]"
Expand Down Expand Up @@ -109,9 +99,4 @@ uint32_t R_value = 0, B_value = 0, G_value = 0;

#define ALL_OPTIONS PROFILE OPT1 OPT2 OPT3 OPT4 OPT5 OPT6 OPT7 OPT8
#define _DEFAULT_MQTT_TOPIC _DEFAULT_HOSTNAME "/"

#ifdef AP_ONLY
#define _DEFAULT_HOMEPAGE "/DSMRindexLOCAL.html"
#else
#define _DEFAULT_HOMEPAGE "/DSMRindexEDGE.html"
#endif
#define _DEFAULT_HOMEPAGE "/DSMRindexEDGE.html"
6 changes: 3 additions & 3 deletions DSMRloggerAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,7 @@ struct Status {
volatile uint16_t wtr_l;
uint16_t dev_type;
bool FirstUse;
#ifdef EID
E_eid_states eid_state;
#endif
} P1Status;

MyData DSMRdata;
Expand Down Expand Up @@ -297,7 +295,9 @@ float settingENBK = 29.62, settingGNBK = 17.30,settingWNBK = 55.05;
uint8_t settingSmHasFaseInfo = 1;
char settingHostname[30] = _DEFAULT_HOSTNAME;
char settingIndexPage[50] = _DEFAULT_HOMEPAGE;

enum tNetwState { NW_NONE, NW_WIFI, NW_ETH};
uint8_t netw_state = NW_NONE;
bool FSmounted = false;
//MQTT
#ifndef MQTTKB
uint32_t settingMQTTinterval = 0;
Expand Down
2 changes: 0 additions & 2 deletions FSexplorer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ void setupFSexplorer()
httpServer.on(UriBraces("/api/v2/sm/fields/{}"),[](){ auth(); handleSmApiField(); });
httpServer.on(UriBraces("/config/{}"), HTTP_POST, [](){auth(); ConfigApi(); });

#ifdef EID
httpServer.on("/eid/getclaim",[](){ auth(); EIDGetClaim(); });
#endif
#ifdef DEV_PAIRING
httpServer.on("/pair",[](){ HandlePairing(); });
#endif
Expand Down
16 changes: 12 additions & 4 deletions Helper.ino
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,18 @@ void ToggleLED(byte mode) {
else if ( LEDenabled ) digitalWrite(LED, !digitalRead(LED)); else digitalWrite(LED, LED_OFF);
}

void ClearRGB(){
R_value = 0;
G_value = 0;
B_value = 0;
}

void SwitchLED( byte mode, uint32_t color) {
if ( UseRGB ) {
if ( LEDenabled ) {
uint32_t value = 0; //off mode
if ( mode == LED_ON ) value = color;

if ( mode == LED_ON ) value = color;
if ( color != LED_GREEN ) ClearRGB();
switch ( color ) {
case LED_RED: R_value = value; break;
case LED_GREEN: G_value = value; break;
Expand All @@ -99,7 +105,9 @@ if ( UseRGB ) {
}
rgb.setPixel(R_value+G_value+B_value);
// neopixelWrite(RGBLED_PIN,20,20,20); ///white
} else digitalWrite(LED, mode);
} else {
digitalWrite(LED, color==LED_RED?LED_OFF:mode);
}
}


Expand All @@ -125,7 +133,7 @@ void ShutDownHandler(){
//===========================================================================================

void P1Reboot(){
delay(1500);
delay(500);
ESP.restart();
delay(2000);
}
Expand Down
4 changes: 0 additions & 4 deletions JsonCalls.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ bool onlyIfPresent = false;
const static PROGMEM char infoArray[][25] = { "identification","p1_version","equipment_id" }; //waardes dient redelijk statisch zijn niet elke keer versturen
#ifndef SE_VERSION
const static PROGMEM char actualArray[][25] = { "timestamp","electricity_tariff","energy_delivered_tariff1","energy_delivered_tariff2","energy_returned_tariff1","energy_returned_tariff2","power_delivered","power_returned","voltage_l1","voltage_l2","voltage_l3","current_l1","current_l2","current_l3","power_delivered_l1","power_delivered_l2","power_delivered_l3","power_returned_l1","power_returned_l2","power_returned_l3","peak_pwr_last_q", "highest_peak_pwr"};

#else
const static PROGMEM char actualArray[][25] = { "timestamp","electricity_tariff","energy_delivered_total","energy_delivered_tariff2","energy_returned_total","energy_returned_tariff2","power_delivered","power_returned","voltage_l1","voltage_l2","voltage_l3","current_l1","current_l2","current_l3","power_delivered_l1","power_delivered_l2","power_delivered_l3","power_returned_l1","power_returned_l2","power_returned_l3" };
#endif
Expand Down Expand Up @@ -272,10 +271,7 @@ void sendDeviceSettings() {
doc["water_enabl"] = WtrMtr;
doc["led"] = LEDenabled;
doc["raw-port"] = bRawPort;

#ifdef EID
doc["eid-enabled"] = bEID_enabled;
#endif
#ifdef DEV_PAIRING
doc["dev-pairing"] = true;
#endif
Expand Down
123 changes: 102 additions & 21 deletions Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
WebServer httpServer(80);
NetServer ws_raw(82);

bool FSmounted = false;
//bool WifiConnected = false;
//time_t tWifiReconnect = 0;
time_t tWifiLost = 0;
byte WifiReconnect = 0;

void LogFile(const char*, bool);
void P1Reboot();
void SwitchLED( byte mode, uint32_t color);
void startETH();
void startWiFi(const char* hostname, int timeOut);

String MAC_Address();
String IP_Address();

Expand All @@ -40,6 +40,7 @@ void GetMacAddress(){
// USBSerial.print( "MacID: " );USBSerial.println( macID );
}


/***===========================================================================================
POST MAC + IP
https://www.allphptricks.com/create-and-consume-simple-rest-api-in-php/
Expand All @@ -50,11 +51,7 @@ void PostMacIP() {
http.begin(wifiClient, APIURL);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");

#ifndef AP_ONLY
String httpRequestData = "mac=" + String(macStr) + "&ip=" + IP_Address() + "&version=" + _VERSION_ONLY;
#else
String httpRequestData = "mac=" + String(macStr) + "&ip=" + IP_Address() + "&version=" + _VERSION_ONLY;
#endif

int httpResponseCode = http.POST(httpRequestData);

Expand All @@ -66,15 +63,43 @@ void PostMacIP() {
http.end();
}

#ifndef ETHERNET

//int WifiDisconnect = 0;
bool bNoNetworkConn = false;

static void onWifiEvent (WiFiEvent_t event) {
sprintf(cMsg,"WiFi-event : %d | rssi: %d | channel : %i",event, WiFi.RSSI(), WiFi.channel());
LogFile(cMsg, true);
switch (event) {
// Network event -> Ethernet is dominant
static void onNetworkEvent (WiFiEvent_t event) {
switch (event) {
//ETH
case ARDUINO_EVENT_ETH_START: //1
DebugTln("ETH Started");
// ETH.setHostname(_HOSTNAME); SDK 3.0 feature
break;
case ARDUINO_EVENT_ETH_CONNECTED: //3
DebugTln("\nETH Connected");
break;
case ARDUINO_EVENT_ETH_GOT_IP: //5
{
WiFiManager manageWiFi;
if ( WiFi.isConnected() ) WiFi.disconnect();
LogFile("ETH GOT IP", true);
netw_state = NW_ETH;
SwitchLED( LED_ON , LED_BLUE ); //Ethernet available = RGB LED Blue
// tLastConnect = 0;
break;
}
// case ARDUINO_EVENT_ETH_LOST_IP: //6 not available in SDK 2.x
// DebugTln("!!! ETH Lost IP");
// netw_connected = false;
// break;
case ARDUINO_EVENT_ETH_STOP: //2
DebugTln("!!! ETH Stopped");
case ARDUINO_EVENT_ETH_DISCONNECTED: //4
// if ( Update.isRunning() ) Update.abort();
if ( netw_state != NW_WIFI ) netw_state = NW_NONE;
SwitchLED( LED_ON , LED_RED );
LogFile("ETH Disconnected", true);
break;
//WIFI
case ARDUINO_EVENT_WIFI_STA_CONNECTED: //4
sprintf(cMsg,"Connected to %s. Asking for IP address", WiFi.BSSIDstr().c_str());
LogFile(cMsg, true);
Expand All @@ -86,15 +111,24 @@ static void onWifiEvent (WiFiEvent_t event) {
Debug (F("IP address: " )); Debug (WiFi.localIP());
Debug(" )\n\n");
WifiReconnect = 0;
if ( netw_state == NW_ETH ) WiFi.disconnect();
else netw_state = NW_WIFI;
bNoNetworkConn = false;
break;
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
tWifiLost = millis();
if ( netw_state != NW_ETH ) netw_state = NW_NONE;
break;
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: //5
#ifdef ULTRA
if ( netw_state != NW_ETH ) SwitchLED( LED_ON, LED_RED );
#else
SwitchLED( LED_OFF, LED_BLUE );
#endif
break;
default:
sprintf(cMsg,"WiFi-event : %d | rssi: %d | channel : %i",event, WiFi.RSSI(), WiFi.channel());
LogFile(cMsg, true);
break;
}
}
Expand All @@ -111,8 +145,9 @@ void configModeCallback (WiFiManager *myWiFiManager)

//===========================================================================================
void WifiWatchDog(){
#if not defined ETHERNET || defined ULTRA
//try to reconnect or reboot when wifi is down
if ( WiFi.status() != WL_CONNECTED ){
if ( WiFi.status() != WL_CONNECTED && WiFi.status() != WL_DISCONNECTED ){
if ( !bNoNetworkConn ) {
LogFile("Wifi connection lost",true); //log only once
tWifiLost = millis();
Expand All @@ -135,11 +170,21 @@ void WifiWatchDog(){
P1Reboot(); //after 3 x 20.000 millis
}
}
#endif
}

//===========================================================================================
void startWiFi(const char* hostname, int timeOut)
{
{
#if not defined ETHERNET || defined ULTRA
#ifdef ULTRA
//lets wait on ethernet first for 3.5sec and consume some time to charge the capacitors
uint8_t timeout = 0;
while ( (netw_state == NW_NONE) && (timeout++ < 35) ) {
delay(100);
}
#endif
if ( netw_state != NW_NONE ) return;
WiFi.setHostname(hostname);
// WiFi.setMinSecurity(WIFI_AUTH_WEP);
WiFi.setMinSecurity(WIFI_AUTH_WPA_PSK);
Expand All @@ -148,13 +193,12 @@ void startWiFi(const char* hostname, int timeOut)
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN); //to solve mesh issues
WiFiManager manageWiFi;
// uint32_t lTime = millis();

// DebugTln("start ...");
LogFile("Wifi Starting",true);
// digitalWrite(LED, LED_OFF);
SwitchLED( LED_OFF, LED_BLUE );

WiFi.onEvent(onWifiEvent);
manageWiFi.setConfigPortalBlocking(false);
manageWiFi.setDebugOutput(false);
manageWiFi.setShowStaticFields(true); // force show static ip fields
manageWiFi.setShowDnsFields(true); // force show dns field always
Expand All @@ -170,19 +214,56 @@ void startWiFi(const char* hostname, int timeOut)
manageWiFi.setAPCallback(configModeCallback);

manageWiFi.setTimeout(timeOut); // in seconden ...
manageWiFi.autoConnect(_HOTSPOT);
/*
if ( !manageWiFi.autoConnect(_HOTSPOT) )
{
LogFile("Wifi failed to connect and hit timeout",true);
// DebugTf(" took [%d] seconds ==> ERROR!\r\n", (millis() - lTime) / 1000);
P1Reboot();
return;
}
// phy_bbpll_en_usb(true);
// DebugTf("Took [%d] seconds => OK!\n", (millis() - lTime) / 1000);

*/
//handle wifi webinterface timeout and connection
//timeOut in sec
uint16_t i = 0;
while ( (i++ < timeOut*10) && (netw_state == NW_NONE) ){
Debug("*");
delay(100);
manageWiFi.process();
SwitchLED(i%4?LED_ON:LED_OFF,LED_BLUE); //fast blinking
}
Debugln();
if ( netw_state == NW_NONE ) {
P1Reboot(); //timeout hit
LogFile("Wifi failed to connect and hit timeout",true);
}
manageWiFi.stopWebPortal();
SwitchLED( LED_ON, LED_BLUE );
#else
Debugln(F("NO WIFI SUPPORT"));
#endif //ifndef ETHERNET
} // startWiFi()

#endif //ifndef ETHERNET
//===========================================================================================
void WaitOnNetwork()
{
while ( netw_state == NW_NONE ) { //endless wait for network connection
Debug(".");
delay(200);
}
Debugln("\nNetwork connected");
}
//===========================================================================================
void startNetwork()
{
WiFi.onEvent(onNetworkEvent);
startETH();
startWiFi(settingHostname, 240); // timeout 4 minuten
WaitOnNetwork();
GetMacAddress();
USBPrint("ip-adres: ");USBPrintln(IP_Address());
}

//===========================================================================================
void startTelnet()
Expand Down
8 changes: 1 addition & 7 deletions OtherFiles.ino
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ void writeSettings() {
docw["max-volt"] = MaxVoltage;
#endif

#ifdef EID
docw["eid-enabled"] = bEID_enabled;
#endif

#ifdef POST_TELEGRAM
docw["pt_port"] = pt_port;
Expand Down Expand Up @@ -216,9 +214,8 @@ void readSettings(bool show)
if (doc.containsKey("pre40")) bPre40 = doc["pre40"];
if (doc.containsKey("raw-port")) bRawPort = doc["raw-port"];
if (doc.containsKey("led-prt")) bLED_PRT = doc["led-prt"];
#ifdef EID

if (doc.containsKey("eid-enabled")) bEID_enabled = doc["eid-enabled"];
#endif
#ifdef VOLTAGE_MON
if (doc.containsKey("max-volt")) MaxVoltage = doc["max-volt"];
#endif
Expand Down Expand Up @@ -404,10 +401,7 @@ void updateSetting(const char *field, const char *newValue)
}
if (!stricmp(field, "raw-port")) bRawPort = (stricmp(newValue, "true") == 0?true:false);
if (!stricmp(field, "act-json-mqtt")) bActJsonMQTT = (stricmp(newValue, "true") == 0?true:false);

#ifdef EID
if (!stricmp(field, "eid-enabled")) bEID_enabled = (stricmp(newValue, "true") == 0?true:false);
#endif

writeSettings();

Expand Down
Loading

0 comments on commit a4e8c99

Please sign in to comment.