Merge branch 'wellenvogel:master' into master
This commit is contained in:
		
						commit
						98c8d44d2f
					
				| 
						 | 
				
			
			@ -493,6 +493,11 @@ double formatKnots(double cv)
 | 
			
		|||
    return cv * 3600.0 / 1852.0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
double formatKmh(double cv)
 | 
			
		||||
{
 | 
			
		||||
    return cv *3600.0 / 1000.0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t mtr2nm(uint32_t m)
 | 
			
		||||
{
 | 
			
		||||
    return m / 1852;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -129,6 +129,7 @@ double formatCourse(double cv);
 | 
			
		|||
double formatDegToRad(double deg);
 | 
			
		||||
double formatWind(double cv);
 | 
			
		||||
double formatKnots(double cv);
 | 
			
		||||
double formatKmh(double cv);
 | 
			
		||||
uint32_t mtr2nm(uint32_t m);
 | 
			
		||||
double mtr2nm(double m);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,18 +27,19 @@ class DummyConfig : public GwConfigInterface{
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
DummyConfig dummyConfig;
 | 
			
		||||
String GwConfigHandler::toString() const{
 | 
			
		||||
        String rt;
 | 
			
		||||
        rt+="Config: ";
 | 
			
		||||
        for (int i=0;i<getNumConfig();i++){
 | 
			
		||||
            rt+=configs[i]->getName();
 | 
			
		||||
            rt+="=";
 | 
			
		||||
            rt+=configs[i]->asString();
 | 
			
		||||
            rt+=", ";
 | 
			
		||||
        }
 | 
			
		||||
        return rt;   
 | 
			
		||||
void GwConfigHandler::logConfig(int level) const
 | 
			
		||||
{
 | 
			
		||||
    if (!logger->isActive(level))
 | 
			
		||||
        return;
 | 
			
		||||
    for (int i = 0; i < getNumConfig(); i++)
 | 
			
		||||
    {
 | 
			
		||||
        String v=configs[i]->asString();
 | 
			
		||||
        bool isChanged=v != configs[i]->getDefault();
 | 
			
		||||
        logger->logDebug(level, "Config[%s]%s='%s'", configs[i]->getName().c_str(),isChanged?"*":"", configs[i]->isSecret() ? "***" : configs[i]->asString().c_str());
 | 
			
		||||
        if ((i%20) == 19) logger->flush();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    logger->flush();
 | 
			
		||||
}
 | 
			
		||||
String GwConfigHandler::toJson() const{
 | 
			
		||||
    String rt;
 | 
			
		||||
    int num=getNumConfig();
 | 
			
		||||
| 
						 | 
				
			
			@ -80,6 +81,9 @@ GwConfigHandler::~GwConfigHandler(){
 | 
			
		|||
bool GwConfigHandler::loadConfig(){
 | 
			
		||||
    prefs->begin(PREF_NAME,true);
 | 
			
		||||
    for (int i=0;i<getNumConfig();i++){
 | 
			
		||||
        if (!prefs->isKey(configs[i]->getName().c_str())) {
 | 
			
		||||
             continue;
 | 
			
		||||
        }
 | 
			
		||||
        String v=prefs->getString(configs[i]->getName().c_str(),configs[i]->getDefault());
 | 
			
		||||
        configs[i]->value=v;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,7 +22,7 @@ class GwConfigHandler: public GwConfigDefinitions{
 | 
			
		|||
        void stopChanges();
 | 
			
		||||
        bool updateValue(String name, String value);
 | 
			
		||||
        bool reset();
 | 
			
		||||
        String toString() const;
 | 
			
		||||
        void logConfig(int level) const;
 | 
			
		||||
        String toJson() const;
 | 
			
		||||
        String getString(const String name,const String defaultv="") const;
 | 
			
		||||
        bool getBool(const String name,bool defaultv=false) const ;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -85,6 +85,7 @@ bool GwWifi::connectInternal(){
 | 
			
		|||
    if (wifiClient->asBoolean()){
 | 
			
		||||
        clientIsConnected=false;
 | 
			
		||||
        LOG_DEBUG(GwLog::LOG,"creating wifiClient ssid=%s",wifiSSID->asString().c_str());
 | 
			
		||||
        WiFi.setAutoReconnect(false); //#102
 | 
			
		||||
        wl_status_t rt=WiFi.begin(wifiSSID->asCString(),wifiPass->asCString());
 | 
			
		||||
        LOG_DEBUG(GwLog::LOG,"wifiClient connect returns %d",(int)rt);
 | 
			
		||||
        lastConnectStart=millis();
 | 
			
		||||
| 
						 | 
				
			
			@ -92,7 +93,8 @@ bool GwWifi::connectInternal(){
 | 
			
		|||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
#define RETRY_MILLIS 20000
 | 
			
		||||
//#102: we should have a wifi connect retry being > 30s - with some headroom
 | 
			
		||||
#define RETRY_MILLIS 40000
 | 
			
		||||
void GwWifi::loop(){
 | 
			
		||||
    if (wifiClient->asBoolean())
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -528,6 +528,31 @@ private:
 | 
			
		|||
                {
 | 
			
		||||
                    SendMessage(NMEA0183Msg);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (shouldSend && NMEA0183Reference == NMEA0183Wind_Apparent)
 | 
			
		||||
                {
 | 
			
		||||
                    double wa = formatCourse(WindAngle);
 | 
			
		||||
                    if (!NMEA0183Msg.Init("VWR", talkerId))
 | 
			
		||||
                      return;
 | 
			
		||||
                    if (!NMEA0183Msg.AddDoubleField(( wa > 180 ) ? 360-wa : wa))
 | 
			
		||||
                      return;
 | 
			
		||||
                    if (!NMEA0183Msg.AddStrField(( wa >= 0 && wa <= 180) ? 'R' : 'L'))
 | 
			
		||||
                      return;
 | 
			
		||||
                    if (!NMEA0183Msg.AddDoubleField(formatKnots(WindSpeed)))
 | 
			
		||||
                      return;
 | 
			
		||||
                    if (!NMEA0183Msg.AddStrField("N"))
 | 
			
		||||
                      return;
 | 
			
		||||
                    if (!NMEA0183Msg.AddDoubleField(WindSpeed))
 | 
			
		||||
                      return;
 | 
			
		||||
                    if (!NMEA0183Msg.AddStrField("M"))
 | 
			
		||||
                      return;
 | 
			
		||||
                    if (!NMEA0183Msg.AddDoubleField(formatKmh(WindSpeed)))
 | 
			
		||||
                      return;
 | 
			
		||||
                    if (!NMEA0183Msg.AddStrField("K"))
 | 
			
		||||
                      return;
 | 
			
		||||
 | 
			
		||||
                   SendMessage(NMEA0183Msg);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            /* if (WindReference == N2kWind_Apparent && boatData->SOG->isValid())
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -801,6 +801,7 @@ void setup() {
 | 
			
		|||
  MDNS.begin(config.getConfigItem(config.systemName)->asCString());
 | 
			
		||||
  channels.begin(fallbackSerial);
 | 
			
		||||
  logger.flush();
 | 
			
		||||
  config.logConfig(GwLog::DEBUG);
 | 
			
		||||
  webserver.registerMainHandler("/api/reset", [](AsyncWebServerRequest *request)->GwRequestMessage *{
 | 
			
		||||
    return new ResetRequest(request->arg("_hash"));
 | 
			
		||||
  });
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue