<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[RemoteXY community — How to restart Wifi]]></title>
		<link>https://forum.remotexy.com/viewtopic.php?id=765</link>
		<atom:link href="https://forum.remotexy.com/extern.php?action=feed&amp;tid=765&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in How to restart Wifi.]]></description>
		<lastBuildDate>Tue, 16 Jul 2019 16:11:19 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: How to restart Wifi]]></title>
			<link>https://forum.remotexy.com/viewtopic.php?pid=2296#p2296</link>
			<description><![CDATA[<p>Hello<br />Thank you for your reply.<br />I have already tried calling &quot;RemoteXY Init ()&quot; but it does not work.<br />I will try your method.<br />I&#039;ll tell you if it works<br />Beroy40</p>]]></description>
			<author><![CDATA[null@example.com (Beroy40)]]></author>
			<pubDate>Tue, 16 Jul 2019 16:11:19 +0000</pubDate>
			<guid>https://forum.remotexy.com/viewtopic.php?pid=2296#p2296</guid>
		</item>
		<item>
			<title><![CDATA[Re: How to restart Wifi]]></title>
			<link>https://forum.remotexy.com/viewtopic.php?pid=2293#p2293</link>
			<description><![CDATA[<p>Welcome,</p><br /><p>You can try to call RemoteXY_Init() again.</p><br /><p>Or do all the Wifi things yourself and make your own RemoteXY module so that it doesn&#039;t mess with Wifi, unlike the original modules.</p><p>Here is an example<br /></p><div class="codebox"><pre><code>#pragma once
#include &lt;WiFi.h&gt;
#include &quot;classes/RemoteXY_API.h&quot;

#define REMOTEXY_SEND_BUFFER_LENGTH 256

class CRemoteXY : public CRemoteXY_API
{

protected:

    uint16_t port;

    WiFiServer *server;
    WiFiClient client; 

    uint8_t wifiStatus;
    uint32_t serverTimeOut;

    uint8_t sendBuffer[REMOTEXY_SEND_BUFFER_LENGTH];
    uint16_t sendBufferCount; 
    uint16_t sendBytesAvailable;  

public:

    void begin( const void * _config, const void * _struct, const char * _password, const uint16_t _port )
    {
        port = _port;
        serverTimeOut = 0;
        init( _config, (void *)_struct, _password );
    }

    uint8_t initModule()
    {
        client.stop();

        if ( server == nullptr )
        {
            server = new WiFiServer( port );
        }

        server-&gt;begin();
        server-&gt;setNoDelay( true );

        #if defined REMOTEXY__DEBUGLOGS
            REMOTEXY__DEBUGLOGS.println( &quot;Server started&quot; );
        #endif

        return 1;
    }

    void handlerModule()
    {
        uint8_t status = WiFi.status();
        if ( status != wifiStatus )
        {
            wifiStatus = status;
            #if defined REMOTEXY__DEBUGLOGS
                if ( wifiStatus == WL_CONNECTED )
                {
                    DEBUGLOGS_write( &quot;Connected to access point&quot; );
                    DEBUGLOGS_write( &quot;IP: &quot; );
                    REMOTEXY__DEBUGLOGS.print( WiFi.localIP() );
                }
            #endif  
        }

        if ( !client )
        {
            client = server-&gt;available();

            if ( client )
            {
                resetServerTimeOut();
                #if defined REMOTEXY__DEBUGLOGS
                    DEBUGLOGS_write( &quot;Client connected.&quot; );
                #endif
            }
        }

        if ( client )
        {
            if ( client.connected() )
            {
                if ( millis() - serverTimeOut &gt; REMOTEXY_SERVER_TIMEOUT )
                {
                    client.stop();
                    #if defined REMOTEXY__DEBUGLOGS
                        DEBUGLOGS_write( &quot;Client timeout.&quot; );
                    #endif
                }
            }
            else
            {
                client.stop();
                #if defined REMOTEXY__DEBUGLOGS
                    DEBUGLOGS_write( &quot;Client disconnected.&quot; );
                #endif
            }
        }        
    }


    void sendStart( uint16_t len )
    {
        sendBytesAvailable = len;
        sendBufferCount = 0;
    }

    void sendByte( uint8_t b )
    {
        if ( client )
        {
            if ( client.connected() )
            {
                #if defined REMOTEXY__DEBUGLOGS
                    DEBUGLOGS_writeOutputHex( b );
                #endif
                sendBuffer[sendBufferCount++] = b;
                sendBytesAvailable--;       
                if ( sendBufferCount == REMOTEXY_SEND_BUFFER_LENGTH || sendBytesAvailable == 0 )
                {
                    uint8_t buf[sendBufferCount];
                    for ( uint16_t i = 0; i &lt; sendBufferCount; i++ )
                    {
                        buf[i] = sendBuffer[i];
                    }

                    client.write( buf, sendBufferCount );
                    sendBufferCount = 0;
                    resetServerTimeOut();
                } 
            }
        }
    }  

    uint8_t receiveByte()
    {
        uint8_t b;
        if ( client )
        {
            if ( client.connected() )
            {
                b = client.read();
                #if defined REMOTEXY__DEBUGLOGS
                    DEBUGLOGS_writeInputHex( b );
                #endif
                resetServerTimeOut();
                return b;
            }
        }

        return 0;
    }

    uint8_t availableByte()
    {   
        #if !defined REMOTEXY_WIFI__POINT
            if ( wifiStatus != WL_CONNECTED )
            {
                return 0;
            }
        #endif

        if ( client )
        {
            if ( client.connected() )
            {
                return client.available();
            }
        }
        return 0;
    }  

    void resetServerTimeOut()
    {
        serverTimeOut = millis();
    }

};</code></pre></div><p>It will require some changes in your code.</p><p>Add this at the begining of your code<br /></p><div class="codebox"><pre><code>CRemoteXY remotexy;</code></pre></div><p>Then when wifi is (re)started (for example inside the wifi event SYSTEM_EVENT_AP_START):<br /></p><div class="codebox"><pre><code>remotexy.begin( remotexyConfig, &amp;remotexyStruct, remotexyPassword, remotexyPort );</code></pre></div><p>And in loop()<br /></p><div class="codebox"><pre><code>remotexy.handler();</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Guillaume)]]></author>
			<pubDate>Sun, 14 Jul 2019 23:17:47 +0000</pubDate>
			<guid>https://forum.remotexy.com/viewtopic.php?pid=2293#p2293</guid>
		</item>
		<item>
			<title><![CDATA[How to restart Wifi]]></title>
			<link>https://forum.remotexy.com/viewtopic.php?pid=2292#p2292</link>
			<description><![CDATA[<p>Hello,<br />I use RemoteXY with ESP32 wifi access point. As a measure of energy saving, I cut the wifi after a while if there is no connection (WiFi.disconnect (); WiFi.mode (WIFI_OFF);)<br />My question: how to restart RemoteXY when pressing a BP for example?<br />Thank you in advance for your answers .<br />Beroy40</p>]]></description>
			<author><![CDATA[null@example.com (Beroy40)]]></author>
			<pubDate>Sun, 14 Jul 2019 12:56:29 +0000</pubDate>
			<guid>https://forum.remotexy.com/viewtopic.php?pid=2292#p2292</guid>
		</item>
	</channel>
</rss>
