<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Looks good!<br>
    <br>
    I've switched wifi and modem on and off a couple times, it always
    correctly reconfigured, with priority for wifi, and ota flash was
    usable on all connections.<br>
    <br>
    I'll do some road tests later on.<br>
    <br>
    Regards,<br>
    Michael<br>
    <br>
    <br>
    <div class="moz-cite-prefix">Am 17.03.2018 um 16:49 schrieb Mark
      Webb-Johnson:<br>
    </div>
    <blockquote type="cite"
      cite="mid:C6B4BCBD-CEAE-416B-969E-849DEF62C928@webb-johnson.net">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <div class=""><br class="">
      </div>
      <div class="">I found and fixed an issue with wifi not attempting
        STA reconnections in APCLIENT mode. That may have been the cause
        of some of Greg’s issues.</div>
      <div class=""><br class="">
      </div>
      Regarding Wifi and Modem co-existing, I think this is a similar
      issue to what I saw with APCLIENT. Sometimes wifi doesn’t remove
      the interface. There is also a race condition where an interface
      is ‘up’, but has not yet been assigned an IP address (as is the
      case with the ‘pp’ interface you show below).
      <div class=""><br class="">
      </div>
      <div class="">I remain convinced that the correct way to deal with
        this is to bind our source address to the preferred interface,
        whenever we want to make an outgoing call. But, looking at the
        mongoose library code they simply don’t seem to offer that
        option. The standard socket API does, of course, have the bind
        option after socket creation but before connect.</div>
      <div class=""><br class="">
      </div>
      <div class="">LWIP does, however, seem to have an alternative: <span
          style="color: rgb(58, 58, 58); font-family: monospace;
          font-size: 16px; background-color: rgb(186, 205, 216);"
          class="">netif_set_default()</span>. That function supposedly
        sets the default interface to be used, unless one is specified
        manually (presumably by binding the socket). I think we can have
        net manager use that whenever modem/wifi comes up or goes down.</div>
      <div class=""><br class="">
      </div>
      <div class="">Going down that route, I added it, but then found
        some messy handling (in netmanager) of m_connected_wifi. That
        would be set if either a STA or AP wifi came up, but that
        doesn’t seem right. We don’t want to set default routes out an
        AP link. So, I refactored that, and added a separate m_wifi_ap
        flag in netmanager to track AP being up/down. Then, that
        introduced a problem into MDNS as it was listening on
        the network.wifi.up event (as it needs to come up both in AP and
        STA modes), so I fixed MDNS to work like the others. I may
        re-visit this tomorrow, as perhaps two new events ‘wifi.any.up’
        and ‘wifi.any.down’ may be a better way to do this (rather than
        the generic network manager messages we are using at the moment,
        with the client then checking the flags to see which one came up
        - wifi or modem).</div>
      <div class=""><br class="">
      </div>
      <div class="">There is a new Info level output from ‘netmanager’
        to show if it changes the default interface, and I extended
        ‘network status’ to show link status on interfaces, interface
        numbers, and default interface status. This should give us some
        more visibility as to what is going on.</div>
      <div class=""><br class="">
      </div>
      <div class="">I haven’t managed to find the issue with wifi AP not
        bringing down interfaces correctly.</div>
      <div class=""><br class="">
      </div>
      <div class="">Overall, this was a fairly large re-factor, and I am
        concerned about unintended consequences. I do, however, think
        that the approach is right. I haven’t got cellular coverage at
        home (almost midnight here) so can’t test modem connections.
        I’ll take it for a drive tomorrow and try then.</div>
      <div class=""><br class="">
      </div>
      <div class="">This is what it looks like for me, tonight:</div>
      <div class=""><br class="">
      </div>
      <blockquote style="margin: 0 0 0 40px; border: none; padding:
        0px;" class="">
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">OVMS > wifi mode
              apclient AP STA</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">Starting WIFI as Access
              Point and Client...</span></font></div>
        <div class=""><span style="font-size: 14px; font-family: 'Andale
            Mono';" class="">...</span></div>
        <div class=""><span style="font-size: 14px; font-family: 'Andale
            Mono';" class="">I (21957) wifi: mode : sta
            (re:da:ct:ed:da:ta) + softAP (al:so:re:da:ct:ed)</span></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">I (21967) events:
              Signal(system.wifi.sta.start)</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">I (21977) events:
              Signal(system.wifi.ap.start)</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">I (21987) esp32wifi: AP
              started with SSID: STA, MAC: al:so:re:da:ct:ed, IP:
              192.168.4.1</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">I (21987) events:
              Signal(network.mgr.init)</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">I (22027) ovms-mdns:
              Launching MDNS service</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class=""><br class="">
            </span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">OVMS > network</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">Interface#2: ap2 (ifup=1
              linkup=1)</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">  IPv4:
              192.168.4.1/255.255.255.0 gateway 192.168.4.1</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class=""><br class="">
            </span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">Interface#1: st1 (ifup=0
              linkup=1)</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">  IPv4: 0.0.0.0/0.0.0.0
              gateway 0.0.0.0</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class=""><br class="">
            </span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">Interface#0: lo0 (ifup=1
              linkup=1)</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">  IPv4:
              127.0.0.1/255.0.0.0 gateway 127.0.0.1</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class=""><br class="">
            </span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">DNS: None</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class=""><br class="">
            </span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">Default Interface: ap2
              (192.168.4.1/255.255.255.0 gateway 192.168.4.1)</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class=""><br class="">
            </span></font></div>
        <div class=""><span style="font-size: 14px; font-family: 'Andale
            Mono';" class="">...</span></div>
        <div class=""><span style="font-size: 14px; font-family: 'Andale
            Mono';" class="">I (24377) wifi: connected with STA, channel
            11</span></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">I (24387) events:
              Signal(system.wifi.sta.connected)</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">I (27737) event: sta ip:
              10.x.x.212, mask: 255.255.255.0, gw: 10.x.x.64</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">I (27747) events:
              Signal(network.interface.up)</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">I (27747) netmanager:
              Set DNS#0 8.8.8.8</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">I (27757) netmanager:
              Set DNS#1 8.8.4.4</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">I (27757) events:
              Signal(system.wifi.sta.gotip)</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">I (27767) netmanager:
              Interface priority is st1 (10.x.x.212/255.255.255.0
              gateway 10.x.x.64)</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">I (27767) events:
              Signal(network.wifi.up)</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">I (27777) events:
              Signal(network.up)</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">I (27787) time: Starting
              SNTP client</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">I (27787) esp32wifi:
              WiFi UP with SSID: STA, MAC: re:da:ct:ed:da:ta, IP:
              10.x.x.212, mask: 255.x.x.0, gw: 10.x.x.64</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">D (27827) time: ntp
              (stratum 1 trusted 1) provides time Sat Mar 17 15:30:37
              2018 (135125us) UTC</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class=""><br class="">
            </span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">OVMS > network</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">Interface#2: ap2 (ifup=1
              linkup=1)</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">  IPv4:
              192.168.4.1/255.255.255.0 gateway 192.168.4.1</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class=""><br class="">
            </span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">Interface#1: st1 (ifup=1
              linkup=1)</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">  IPv4:
              10.x.x.212/255.255.25.0 gateway 10.x.x.64</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class=""><br class="">
            </span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">Interface#0: lo0 (ifup=1
              linkup=1)</span></font></div>
        <div class=""><span style="font-size: 14px; font-family: 'Andale
            Mono';" class="">  IPv4: 127.0.0.1/255.0.0.0 gateway
            127.0.0.1</span></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class=""><br class="">
            </span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">DNS: 8.8.8.8 8.8.4.4</span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class=""><br class="">
            </span></font></div>
        <div class=""><font class="" face="Andale Mono"><span
              style="font-size: 14px;" class="">Default Interface: st1
              (10.x.x.212/255.255.255.0 gateway 10.x.x.64)</span></font></div>
      </blockquote>
      <div class=""><br class="">
      </div>
      <div class="">All the above is committed, and pushed.</div>
      <div class=""><br class="">
      </div>
      <div class="">Regards, Mark.<br class="">
        <div class=""><br class="">
          <div>
            <blockquote type="cite" class="">
              <div class="">On 17 Mar 2018, at 7:40 PM, Michael Balzer
                <<a href="mailto:dexter@expeedo.de" class=""
                  moz-do-not-send="true">dexter@expeedo.de</a>>
                wrote:</div>
              <br class="Apple-interchange-newline">
              <div class="">
                <meta http-equiv="Content-Type" content="text/html;
                  charset=utf-8" class="">
                <div text="#000000" bgcolor="#FFFFFF" class=""> New
                  issue, possibly also routing related: powering down
                  the modem to force using Wifi used to work before, I
                  now get:<br class="">
                  <br class="">
                  <tt class="">I (724597) gsm-ppp: status_cb: Connected</tt><tt
                    class=""><br class="">
                  </tt><tt class="">I (724597) gsm-ppp:    our_ipaddr  =
                    10.170.195.13</tt><tt class=""><br class="">
                  </tt><tt class="">I (724597) gsm-ppp:    his_ipaddr  =
                    10.64.64.64</tt><tt class=""><br class="">
                  </tt><tt class="">I (724597) gsm-ppp:    netmask     =
                    255.255.255.255</tt><tt class=""><br class="">
                  </tt><tt class="">I (724597) gsm-ppp:    our6_ipaddr =
                    ::</tt><tt class=""><br class="">
                  </tt><tt class="">I (724597) netmanager: Set DNS#0
                    8.8.8.8</tt><tt class=""><br class="">
                  </tt><tt class="">I (724597) netmanager: Set DNS#1
                    8.8.4.4</tt><tt class=""><br class="">
                  </tt><tt class="">I (724597) time: Starting SNTP
                    client</tt><tt class=""><br class="">
                  </tt><b class=""><tt class=""><br class="">
                      OVMS > network status </tt></b><tt class=""><br
                      class="">
                  </tt><tt class="">Interface#2: pp</tt><tt class=""><br
                      class="">
                  </tt><tt class="">  IPv4:
                    10.170.195.13/255.255.255.255 gateway 10.64.64.64</tt><tt
                    class=""><br class="">
                  </tt><tt class=""><br class="">
                  </tt><tt class="">Interface#1: st</tt><tt class=""><br
                      class="">
                  </tt><tt class="">  IPv4: 192.168.2.105/255.255.255.0
                    gateway 192.168.2.1</tt><tt class=""><br class="">
                  </tt><tt class=""><br class="">
                  </tt><tt class="">Interface#0: lo</tt><tt class=""><br
                      class="">
                  </tt><tt class="">  IPv4: 127.0.0.1/255.0.0.0 gateway
                    127.0.0.1</tt><tt class=""><br class="">
                  </tt><tt class=""><br class="">
                  </tt><tt class="">DNS: 8.8.8.8 8.8.4.4</tt><tt
                    class=""><br class="">
                  </tt><b class=""><tt class=""><br class="">
                      OVMS > ota flash http <a
                        href="http://ovms.dexters-web.de/g/spacer.gif"
                        class="" moz-do-not-send="true">ovms.dexters-web.de/g/spacer.gif</a></tt></b><tt
                    class=""><br class="">
                  </tt><tt class="">Current running partition is:
                    factory</tt><tt class=""><br class="">
                  </tt><tt class="">Target partition is: ota_0</tt><tt
                    class=""><br class="">
                  </tt><tt class="">Download firmware from <a
                      href="http://ovms.dexters-web.de/g/spacer.gif"
                      class="" moz-do-not-send="true">ovms.dexters-web.de/g/spacer.gif</a>
                    to ota_0</tt><tt class=""><br class="">
                  </tt><tt class="">Expected file size is 67</tt><tt
                    class=""><br class="">
                  </tt><tt class="">Preparing flash partition...</tt><tt
                    class=""><br class="">
                  </tt><tt class="">Error: ESP32 error #5379 when
                    writing to flash - state is inconsistent</tt><tt
                    class=""><br class="">
                  </tt><tt class="">E (763827) esp_ota_ops: OTA image
                    has invalid magic byte (expected 0xE9, saw 0x47</tt><tt
                    class=""><br class="">
                  </tt><b class=""><tt class=""><br class="">
                      OVMS > power simcom off</tt></b><tt class=""><br
                      class="">
                  </tt><tt class="">Power mode of simcom is now off</tt><tt
                    class=""><br class="">
                  </tt><tt class="">I (782817) simcom: State: Enter
                    PoweringOff state</tt><tt class=""><br class="">
                  </tt><tt class="">I (782817) gsm-ppp: Shutting down
                    (soft)...</tt><tt class=""><br class="">
                  </tt><tt class="">I (782817) time: Restarting SNTP
                    client</tt><tt class=""><br class="">
                  </tt><tt class="">I (782827) gsm-nmea: Shutdown
                    (direct)</tt><tt class=""><br class="">
                  </tt><tt class="">I (782837) simcom: Power Cycle</tt><tt
                    class=""><br class="">
                  </tt><b class=""><tt class=""><br class="">
                      OVMS > network status </tt></b><tt class=""><br
                      class="">
                  </tt><tt class="">Interface#2: pp</tt><tt class=""><br
                      class="">
                  </tt><tt class="">  IPv4: 0.0.0.0/255.255.255.255
                    gateway 0.0.0.0</tt><tt class=""><br class="">
                  </tt><tt class=""><br class="">
                  </tt><tt class="">Interface#1: st</tt><tt class=""><br
                      class="">
                  </tt><tt class="">  IPv4: 192.168.2.105/255.255.255.0
                    gateway 192.168.2.1</tt><tt class=""><br class="">
                  </tt><tt class=""><br class="">
                  </tt><tt class="">Interface#0: lo</tt><tt class=""><br
                      class="">
                  </tt><tt class="">  IPv4: 127.0.0.1/255.0.0.0 gateway
                    127.0.0.1</tt><tt class=""><br class="">
                  </tt><tt class=""><br class="">
                  </tt><tt class="">DNS: 8.8.8.8 8.8.4.4</tt><tt
                    class=""><br class="">
                  </tt><tt class="">I (793147) simcom: State timeout,
                    transition to 1</tt><tt class=""><br class="">
                  </tt><tt class="">I (793147) simcom: State: Enter
                    CheckPowerOff state</tt><tt class=""><br class="">
                  </tt><tt class="">I (794657) gsm-ppp: StatusCallBack:
                    User Interrupt</tt><tt class=""><br class="">
                  </tt><tt class="">I (794657) gsm-ppp: PPP connection
                    has been closed</tt><tt class=""><br class="">
                  </tt><tt class=""><br class="">
                    <b class="">OVMS > network status </b></tt><tt
                    class=""><br class="">
                  </tt><tt class="">Interface#2: pp</tt><tt class=""><br
                      class="">
                  </tt><tt class="">  IPv4: 0.0.0.0/255.255.255.255
                    gateway 0.0.0.0</tt><tt class=""><br class="">
                  </tt><tt class=""><br class="">
                  </tt><tt class="">Interface#1: st</tt><tt class=""><br
                      class="">
                  </tt><tt class="">  IPv4: 192.168.2.105/255.255.255.0
                    gateway 192.168.2.1</tt><tt class=""><br class="">
                  </tt><tt class=""><br class="">
                  </tt><tt class="">Interface#0: lo</tt><tt class=""><br
                      class="">
                  </tt><tt class="">  IPv4: 127.0.0.1/255.0.0.0 gateway
                    127.0.0.1</tt><tt class=""><br class="">
                  </tt><tt class=""><br class="">
                  </tt><tt class="">DNS: 8.8.8.8 8.8.4.4</tt><tt
                    class=""><br class="">
                  </tt><tt class=""><br class="">
                    <b class="">OVMS > ota flash http <a
                        href="http://ovms.dexters-web.de/g/spacer.gif"
                        class="" moz-do-not-send="true">ovms.dexters-web.de/g/spacer.gif</a></b></tt><tt
                    class=""><br class="">
                  </tt><tt class="">Current running partition is:
                    factory</tt><tt class=""><br class="">
                  </tt><tt class="">Target partition is: ota_0</tt><tt
                    class=""><br class="">
                  </tt><tt class="">Download firmware from <a
                      href="http://ovms.dexters-web.de/g/spacer.gif"
                      class="" moz-do-not-send="true">ovms.dexters-web.de/g/spacer.gif</a>
                    to ota_0</tt><tt class=""><br class="">
                  </tt><tt class="">Error: Request failed</tt><tt
                    class=""><br class="">
                  </tt><b class=""><tt class="">W (807247) net: Error:
                      Failed to connect server <a
                        href="http://ovms.dexters-web.de" class=""
                        moz-do-not-send="true">ovms.dexters-web.de</a>
                      (error: 118)</tt></b><tt class=""><br class="">
                  </tt><br class="">
                  <br class="">
                  Error 118 = Host is unreachable.<br class="">
                  <br class="">
                  Same with modem setstate. The problem occurs after the
                  first ppp init.<br class="">
                  <br class="">
                  Regards,<br class="">
                  Michael<br class="">
                  <br class="">
                  <pre class="moz-signature" cols="160">-- 
Michael Balzer * Helkenberger Weg 9 * D-58256 Ennepetal
Fon 02333 / 833 5735 * Handy 0176 / 206 989 26
</pre>
                </div>
                _______________________________________________<br
                  class="">
                OvmsDev mailing list<br class="">
                <a href="mailto:OvmsDev@lists.teslaclub.hk" class=""
                  moz-do-not-send="true">OvmsDev@lists.teslaclub.hk</a><br
                  class="">
                <a class="moz-txt-link-freetext" href="http://lists.teslaclub.hk/mailman/listinfo/ovmsdev">http://lists.teslaclub.hk/mailman/listinfo/ovmsdev</a><br
                  class="">
              </div>
            </blockquote>
          </div>
          <br class="">
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
OvmsDev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:OvmsDev@lists.teslaclub.hk">OvmsDev@lists.teslaclub.hk</a>
<a class="moz-txt-link-freetext" href="http://lists.teslaclub.hk/mailman/listinfo/ovmsdev">http://lists.teslaclub.hk/mailman/listinfo/ovmsdev</a>
</pre>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="160">-- 
Michael Balzer * Helkenberger Weg 9 * D-58256 Ennepetal
Fon 02333 / 833 5735 * Handy 0176 / 206 989 26
</pre>
  </body>
</html>