Browse Source

0.8.119

* untested combination of Ethernet and Wifi (Ethernet connection will cancel Wifi connection)
main
lumapu 9 months ago
parent
commit
34fbeea3bb
  1. 4
      manual/factory_firmware.md
  2. 4
      src/app.cpp
  3. 6
      src/app.h
  4. 2
      src/appInterface.h
  5. 5
      src/config/settings.h
  6. 64
      src/network/AhoyEthernet.h
  7. 6
      src/network/AhoyNetwork.h
  8. 10
      src/network/AhoyWifiEsp32.h

4
manual/factory_firmware.md

@ -60,9 +60,9 @@ For a 4MB flash size the upload should be finished within 22 seconds.
Reboot your ESP an check if all your settings are present. Reboot your ESP an check if all your settings are present.
## Keep updated with 'Mainline' ## Get updated with 'Mainline'
From time to time a new version of AhoyDTU will be published. To get this changes into your alread prepared factory binary generation environment you have to do only a few steps: From time to time a new version of AhoyDTU will be published. To get the changes into your already prepared factory binary generation environment you have to do only a few steps:
1. revert the changes of `platformio.ini` by executing from repository root: `git checkout src/platformio.ini` 1. revert the changes of `platformio.ini` by executing from repository root: `git checkout src/platformio.ini`
2. pull new changes from remote: `git pull` 2. pull new changes from remote: `git pull`

4
src/app.cpp

@ -112,9 +112,7 @@ void app::setup() {
mPubSerial.setup(mConfig, &mSys, &mTimestamp); mPubSerial.setup(mConfig, &mSys, &mTimestamp);
#if !defined(ETHERNET)
//mImprov.setup(this, mConfig->sys.deviceName, mVersion); //mImprov.setup(this, mConfig->sys.deviceName, mVersion);
#endif
#if defined(ENABLE_SIMULATOR) #if defined(ENABLE_SIMULATOR)
mSimulator.setup(&mSys, &mTimestamp, 0); mSimulator.setup(&mSys, &mTimestamp, 0);
@ -174,9 +172,7 @@ void app::regularTickers(void) {
everySec(std::bind(&DisplayType::tickerSecond, &mDisplay), "disp"); everySec(std::bind(&DisplayType::tickerSecond, &mDisplay), "disp");
#endif #endif
every(std::bind(&PubSerialType::tick, &mPubSerial), 5, "uart"); every(std::bind(&PubSerialType::tick, &mPubSerial), 5, "uart");
#if !defined(ETHERNET)
//everySec([this]() { mImprov.tickSerial(); }, "impro"); //everySec([this]() { mImprov.tickSerial(); }, "impro");
#endif
#if defined(ENABLE_HISTORY) #if defined(ENABLE_HISTORY)
everySec(std::bind(&HistoryType::tickerSecond, &mHistory), "hist"); everySec(std::bind(&HistoryType::tickerSecond, &mHistory), "hist");

6
src/app.h

@ -45,8 +45,8 @@
#else #else
#include "network/AhoyWifiEsp8266.h" #include "network/AhoyWifiEsp8266.h"
#endif #endif
#include "utils/improv.h"
#endif /* defined(ETHERNET) */ #endif /* defined(ETHERNET) */
#include "utils/improv.h"
#if defined(ENABLE_SIMULATOR) #if defined(ENABLE_SIMULATOR)
#include "hm/simulator.h" #include "hm/simulator.h"
@ -167,7 +167,6 @@ class app : public IApp, public ah::Scheduler {
return mSaveReboot; return mSaveReboot;
} }
#if !defined(ETHERNET)
bool getAvailNetworks(JsonObject obj) override { bool getAvailNetworks(JsonObject obj) override {
return mNetwork->getAvailNetworks(obj, this); return mNetwork->getAvailNetworks(obj, this);
} }
@ -183,7 +182,6 @@ class app : public IApp, public ah::Scheduler {
return false; return false;
#endif #endif
} }
#endif /* !defined(ETHERNET) */
String getIp(void) override { String getIp(void) override {
return mNetwork->getIp(); return mNetwork->getIp();
@ -433,9 +431,7 @@ class app : public IApp, public ah::Scheduler {
#endif #endif
PubSerialType mPubSerial; PubSerialType mPubSerial;
#if !defined(ETHERNET)
//Improv mImprov; //Improv mImprov;
#endif
#ifdef ESP32 #ifdef ESP32
CmtRadio<> mCmtRadio; CmtRadio<> mCmtRadio;
#endif #endif

2
src/appInterface.h

@ -28,11 +28,9 @@ class IApp {
virtual void addOnce(ah::scdCb c, uint32_t timeout, const char *name) = 0; virtual void addOnce(ah::scdCb c, uint32_t timeout, const char *name) = 0;
#if !defined(ETHERNET)
virtual bool getAvailNetworks(JsonObject obj) = 0; virtual bool getAvailNetworks(JsonObject obj) = 0;
virtual void setupStation(void) = 0; virtual void setupStation(void) = 0;
virtual bool getWasInCh12to14(void) const = 0; virtual bool getWasInCh12to14(void) const = 0;
#endif /* defined(ETHERNET) */
virtual String getIp(void) = 0; virtual String getIp(void) = 0;
virtual bool isApActive(void) = 0; virtual bool isApActive(void) = 0;

5
src/config/settings.h

@ -99,14 +99,13 @@ typedef struct {
int8_t timezone; int8_t timezone;
char apPwd[PWD_LEN]; char apPwd[PWD_LEN];
#if !defined(ETHERNET)
// wifi // wifi
char stationSsid[SSID_LEN]; char stationSsid[SSID_LEN];
char stationPwd[PWD_LEN]; char stationPwd[PWD_LEN];
bool isHidden; bool isHidden;
#else #if defined(ETHERNET)
cfgEth_t eth; cfgEth_t eth;
#endif /* !defined(ETHERNET) */ #endif
cfgIp_t ip; cfgIp_t ip;
} cfgSys_t; } cfgSys_t;

64
src/network/AhoyEthernet.h

@ -12,10 +12,18 @@
#include <ETH.h> #include <ETH.h>
#include "AhoyEthernetSpi.h" #include "AhoyEthernetSpi.h"
#include "AhoyNetwork.h" #include "AhoyNetwork.h"
#include "AhoyWifiEsp32.h"
class AhoyEthernet : public AhoyWifi {
private:
enum class Mode {
WIRED,
WIRELESS
};
class AhoyEthernet : public AhoyNetwork {
public: public:
void begin() override { void begin() override {
mMode = Mode::WIRELESS;
mAp.enable(); mAp.enable();
if(!mConfig->sys.eth.enabled) if(!mConfig->sys.eth.enabled)
@ -25,8 +33,9 @@ class AhoyEthernet : public AhoyNetwork {
ETH.setHostname(mConfig->sys.deviceName); ETH.setHostname(mConfig->sys.deviceName);
} }
void OnEvent(WiFiEvent_t event) override { void OnEvent(WiFiEvent_t event) {
switch(event) { switch(event) {
case SYSTEM_EVENT_STA_CONNECTED:
case ARDUINO_EVENT_ETH_CONNECTED: case ARDUINO_EVENT_ETH_CONNECTED:
if(NetworkState::CONNECTED != mStatus) { if(NetworkState::CONNECTED != mStatus) {
mStatus = NetworkState::CONNECTED; mStatus = NetworkState::CONNECTED;
@ -35,14 +44,30 @@ class AhoyEthernet : public AhoyNetwork {
} }
break; break;
case SYSTEM_EVENT_STA_GOT_IP:
mStatus = NetworkState::GOT_IP;
if(mAp.isEnabled())
mAp.disable();
mMode = Mode::WIRELESS;
if(!mConnected) {
mConnected = true;
ah::welcome(WiFi.localIP().toString(), F("Station WiFi"));
MDNS.begin(mConfig->sys.deviceName);
mOnNetworkCB(true);
}
break;
case ARDUINO_EVENT_ETH_GOT_IP: case ARDUINO_EVENT_ETH_GOT_IP:
mStatus = NetworkState::GOT_IP; mStatus = NetworkState::GOT_IP;
mMode = Mode::WIRED;
if(!mConnected) { if(!mConnected) {
mAp.disable(); mAp.disable();
mConnected = true; mConnected = true;
ah::welcome(ETH.localIP().toString(), F("Station")); ah::welcome(ETH.localIP().toString(), F("Station Ethernet"));
MDNS.begin(mConfig->sys.deviceName); MDNS.begin(mConfig->sys.deviceName);
mOnNetworkCB(true); mOnNetworkCB(true);
WiFi.disconnect();
} }
break; break;
@ -51,9 +76,25 @@ class AhoyEthernet : public AhoyNetwork {
case ARDUINO_EVENT_ETH_DISCONNECTED: case ARDUINO_EVENT_ETH_DISCONNECTED:
mStatus = NetworkState::DISCONNECTED; mStatus = NetworkState::DISCONNECTED;
if(mConnected) { if(mConnected) {
mMode = Mode::WIRELESS;
mConnected = false; mConnected = false;
mOnNetworkCB(false); mOnNetworkCB(false);
mAp.enable(); MDNS.end();
AhoyWifi::begin();
}
break;
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
[[fallthrough]];
case ARDUINO_EVENT_WIFI_STA_STOP:
[[fallthrough]];
case SYSTEM_EVENT_STA_DISCONNECTED:
mStatus = NetworkState::DISCONNECTED;
if(mConnected && (Mode::WIRELESS == mMode)) {
mConnected = false;
mOnNetworkCB(false);
MDNS.end();
AhoyWifi::begin();
} }
break; break;
@ -62,24 +103,27 @@ class AhoyEthernet : public AhoyNetwork {
} }
} }
void tickNetworkLoop() override { String getIp(void) {
if(mAp.isEnabled()) if(Mode::WIRELESS == mMode)
mAp.tickLoop(); return AhoyWifi::getIp();
} else
String getIp(void) override {
return ETH.localIP().toString(); return ETH.localIP().toString();
} }
private: private:
void setStaticIp() override { void setStaticIp() override {
setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool { setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool {
if(Mode::WIRELESS == mMode)
return WiFi.config(ip, gateway, mask, dns1, dns2);
else
return ETH.config(ip, gateway, mask, dns1, dns2); return ETH.config(ip, gateway, mask, dns1, dns2);
}); });
} }
private: private:
AhoyEthernetSpi mEthSpi; AhoyEthernetSpi mEthSpi;
Mode mMode;
}; };
#endif /*ETHERNET*/ #endif /*ETHERNET*/

6
src/network/AhoyNetwork.h

@ -88,7 +88,6 @@ class AhoyNetwork {
return mAp.isEnabled(); return mAp.isEnabled();
} }
#if !defined(ETHERNET)
bool getAvailNetworks(JsonObject obj, IApp *app) { bool getAvailNetworks(JsonObject obj, IApp *app) {
if(!mScanActive) { if(!mScanActive) {
app->addOnce([this]() {scan();}, 1, "scan"); app->addOnce([this]() {scan();}, 1, "scan");
@ -122,7 +121,6 @@ class AhoyNetwork {
} }
WiFi.scanNetworks(true, true); WiFi.scanNetworks(true, true);
} }
#endif
protected: protected:
virtual void setStaticIp() = 0; virtual void setStaticIp() = 0;
@ -173,7 +171,6 @@ class AhoyNetwork {
} }
} }
#if !defined(ETHERNET)
void sortRSSI(int *sort, int n) { void sortRSSI(int *sort, int n) {
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
sort[i] = i; sort[i] = i;
@ -182,7 +179,6 @@ class AhoyNetwork {
if (WiFi.RSSI(sort[j]) > WiFi.RSSI(sort[i])) if (WiFi.RSSI(sort[j]) > WiFi.RSSI(sort[i]))
std::swap(sort[i], sort[j]); std::swap(sort[i], sort[j]);
} }
#endif
private: private:
void sendNTPpacket(void) { void sendNTPpacket(void) {
@ -234,9 +230,7 @@ class AhoyNetwork {
uint32_t *mUtcTimestamp = nullptr; uint32_t *mUtcTimestamp = nullptr;
bool mConnected = false; bool mConnected = false;
bool mScanActive = false; bool mScanActive = false;
#if !defined(ETHERNET)
bool mWifiConnecting = false; bool mWifiConnecting = false;
#endif
OnNetworkCB mOnNetworkCB; OnNetworkCB mOnNetworkCB;
OnTimeCB mOnTimeCB; OnTimeCB mOnTimeCB;

10
src/network/AhoyWifiEsp32.h

@ -6,7 +6,7 @@
#ifndef __AHOY_WIFI_ESP32_H__ #ifndef __AHOY_WIFI_ESP32_H__
#define __AHOY_WIFI_ESP32_H__ #define __AHOY_WIFI_ESP32_H__
#if defined(ESP32) && !defined(ETHERNET) #if defined(ESP32)
#include <functional> #include <functional>
#include <AsyncUDP.h> #include <AsyncUDP.h>
#include "AhoyNetwork.h" #include "AhoyNetwork.h"
@ -14,7 +14,7 @@
class AhoyWifi : public AhoyNetwork { class AhoyWifi : public AhoyNetwork {
public: public:
void begin() override { virtual void begin() override {
mAp.enable(); mAp.enable();
if(String(FB_WIFI_SSID) == mConfig->sys.stationSsid) if(String(FB_WIFI_SSID) == mConfig->sys.stationSsid)
@ -34,7 +34,7 @@ class AhoyWifi : public AhoyNetwork {
#endif #endif
} }
void OnEvent(WiFiEvent_t event) override { virtual void OnEvent(WiFiEvent_t event) override {
switch(event) { switch(event) {
case SYSTEM_EVENT_STA_CONNECTED: case SYSTEM_EVENT_STA_CONNECTED:
if(NetworkState::CONNECTED != mStatus) { if(NetworkState::CONNECTED != mStatus) {
@ -87,12 +87,12 @@ class AhoyWifi : public AhoyNetwork {
} }
private: private:
void setStaticIp() override { virtual void setStaticIp() override {
setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool { setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool {
return WiFi.config(ip, gateway, mask, dns1, dns2); return WiFi.config(ip, gateway, mask, dns1, dns2);
}); });
} }
}; };
#endif /*ESP32 & !ETHERNET*/ #endif /*ESP32*/
#endif /*__AHOY_WIFI_ESP32_H__*/ #endif /*__AHOY_WIFI_ESP32_H__*/

Loading…
Cancel
Save