1

Topic: can I change wifi credentials without flashing code?

Hello there, I've made a project using these configuration: Cloud server + NodeMCU V3 + WiFi on chip. Now I just want to use my project with different network without changing code. I've used WiFiManager but it doesn't work!  I've found this solution http://forum.remotexy.com/viewtopic.php?pid=2150#p2150 but also it doesn't work. please guys I NEED YOUR HELP! thanks in advance.

2

Re: can I change wifi credentials without flashing code?

Muhannad.Alaftarisi wrote:

I've found this solution http://forum.remotexy.com/viewtopic.php?pid=2150#p2150 but also it doesn't work.

I can assure you that it works. If it doesn't, then you are doing something wrong.

3 (edited by Muhannad.Alaftarisi 2020-01-24 21:01:42)

Re: can I change wifi credentials without flashing code?

first of all, thank you for your quick response. to be honest with you I'm new in this field. I've tried a lot with this problem in addition to your solution, unfortunately it doesn't work. I'm just wondering if you could help me with a mini project using wifimanager to change wifi credentials. Truly I will appropriate it so much. Thank you

4

Re: can I change wifi credentials without flashing code?

Forget about remotexy for now. Did you try wifimanager example code? Did it work?

5

Re: can I change wifi credentials without flashing code?

Yes of course. It works.

6

Re: can I change wifi credentials without flashing code?

Ok, so can you print a message when wifimanager finally connected to an AP ? I think there is a callback for this event.

Then, copy file esp8266wifi_cloud.h from remotexy/modules folder, rename it as you want, then modify it like I suggested in the link, removing almost all the wifi stuff, (of course, just copy/pasting my code won't work, because I used a different module).

Then, instead of printing a message when wifimanager connected to an AP, you can initialize remotexy here.

7

Re: can I change wifi credentials without flashing code?

Ok I will try it. Thanks a million.

8

Re: can I change wifi credentials without flashing code?

Hi Guillaume, I wanna tell you that I've modified "espcore_wifi_cloud.h" as you suggested  but when I put "CRemoteXY remotexy;" in my main code it goes wrong!!

9 (edited by Guillaume 2020-01-26 21:20:38)

Re: can I change wifi credentials without flashing code?

Ok ok... Here is an example

Put this in a new file "remotexy_custom.h"

#pragma once

#define REMOTEXY_CLOUD
#include <ESP8266WiFi.h>
#include "classes/RemoteXY_API.h"
#define REMOTEXY_SEND_BUFFER_LENGTH 256
#define REMOTEXY_CLOUD_SERVER "cloud.remotexy.com"
#define REMOTEXY_CLOUD_PORT 6376

class CRemoteXY_Cloud : public CRemoteXY_API
{

protected:

    WiFiClient client;
    uint8_t clientState;
    uint8_t wifiStatus;

    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 char * _cloudToken )
    {
        clientState = 0;
        init( _config, (void *)_struct, _password );
        initCloud( REMOTEXY_CLOUD_SERVER, REMOTEXY_CLOUD_PORT, _cloudToken );
    }

    uint8_t initModule ()
    {
        return 1;
    }

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

    int8_t connectServerCloud( char * _cloudServer, uint16_t _cloudPort )
    {
        if ( wifiStatus != WL_CONNECTED )
        {
            return -1;
        }
        if ( client.connect( _cloudServer, _cloudPort ) )
        {
            clientState = 1;
        }
        return clientState;
    }

    void closeConnection()
    {
        if ( clientState )
        {
            client.stop();
            clientState = 0;
        }
    }

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

    void sendByte( uint8_t b )
    {
        if ( clientState )
        {
            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 < sendBufferCount; i++ )
                    {
                        buf[i] = sendBuffer[i];
                    }
                    client.write( buf, sendBufferCount );
                    sendBufferCount = 0;
                }
            }
            else
            {
                stopCloud();
            }
        }
    }

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

    uint8_t availableByte()
    {
        if ( clientState )
        {
            if ( client.connected() )
            {
                return client.available();
            }
            else
            {
                stopCloud();
            }
        }
        return 0;
    }

};

Then try this example sketch:

#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>

#include <remotexy_custom.h>
CRemoteXY_Cloud remotexy;
const char * remotexyCloudToken = "72c17849a585035fcb1988891d19c5b6";

#pragma pack(push, 1)
uint8_t remotexyConfig[] =
{
  255,0,0,0,0,16,0,8,13,1, // Header
  129,0,25,47,15,6,17,72,101,108,108,111,0 // Label "Hello"
};

struct
{
  uint8_t connect_flag;
} remotexyStruct;

#pragma pack(pop)

void setup()
{
  Serial.begin(115200);
  WiFiManager wifiManager;
  wifiManager.autoConnect("AutoConnectAP");

  //if you get here you have connected to the WiFi
  Serial.println("connected...yeey :)");

  // Start remotexy now
  remotexy.begin( remotexyConfig, &remotexyStruct, "", remotexyCloudToken );
}

void loop()
{
  remotexy.handler();
}

10

Re: can I change wifi credentials without flashing code?

Also, with more modifications to remotexy modules, without need of wifimanager library, you could make so that if esp wifi fail to connect to the AP, then start wifi in AP mode and create a remotexy interface where you can enter wifi credentials (it's possible to have multiple remotexy interfaces in the same program), basically like wifimanager but with a remotexy interface instead of a web server. It's a little more complicated, but totally possible.

11

Re: can I change wifi credentials without flashing code?

It works!!
thaaaaaaaaanks a million Guillaume. I owe you one

12

Re: can I change wifi credentials without flashing code?

I'd like to do this but with ESP32 Wifi.

Anybody (Guillaume?) has ever done it by chance?

13

Re: can I change wifi credentials without flashing code?

Yes it works with esp32