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

14

Re: can I change wifi credentials without flashing code?

Hello example works fine. If I am using my own RemotyXY simple project with only one switch for ESP8266 internal LED in GPIO02. It does't work. RemoteXY generates code for Arduino IDE. There is also #include <RemoteXY.h> . That makes big problem with remotexy_custom.h. How to combine normally generated code and remote_custom.h ?

15

Re: can I change wifi credentials without flashing code?

Use the example code but only replace array and struct with yours. Only what is between

#pragma pack(push, 1)
uint8_t remotexyConfig[] =
{

and

} remotexyStruct;
#pragma pack(pop)

16 (edited by Paavo 2020-08-14 11:26:59)

Re: can I change wifi credentials without flashing code?

Thanks for answer but I show what is problem, it is not so simple.

In first example is RemoteXY_button_led.ino. That is my RemoteXY program where is only button and LED.
RemoteXY generates mainly all. There is nothing for WiFiManager because normal program has hard cored SSID and PASSWORD which are my own, of course. That program works fine, of course. OK.

Second example is named RemoteXY_button_led_ssid_password_2.ino.
That try to use WiFimanager.h and your example code and includes library remotexy_custom.h.
Main fuction is exact as normal button-led-program. This doesn't work.
If SSID or PASSWORD was same than before in  ESP8266 mobile app will be open with the button and LED. OK.
If SSID or PASSWORD has been changed to unknown, WiFiManager makes ESP8266 to hotspot. OK.
Now I can see new hot spot SSID and I connect my mobile to it using correct password. OK.
After that system is connecting back to RemoteXT mobile app succeeds too. I can see button and LED.
Then there is my problem.
When pushing the button nothing happens. No see red LED on screen of mobile, no LED light on ESP8266.

I can see that it is impossble to work bercause normal RemoteXY needs library RemoteXY.h.
May be problem is in different struct RemoteXY and your remotexyStruct

Please, help me and other on the right path here in difficult RemoteXY / WiFiManager world.

// ******************************************************************************
// RemoteXY_button_led.ino

//////////////////////////////////////////////
//        RemoteXY include library          //
//////////////////////////////////////////////

// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__ESP8266WIFI_LIB_CLOUD
#include <ESP8266WiFi.h>
#include <RemoteXY.h>   // Must be here for RemoteXY

// RemoteXY connection settings
#define REMOTEXY_WIFI_SSID "YOUR_SSID"
#define REMOTEXY_WIFI_PASSWORD "YOUR_PASS"
#define REMOTEXY_CLOUD_SERVER "cloud.remotexy.com"
#define REMOTEXY_CLOUD_PORT 6376
#define REMOTEXY_CLOUD_TOKEN "ac5228930e1355372225655f4a9a46f6"

// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 255, 1, 0, 1, 0, 19, 0, 10, 13, 1,
  1, 0, 27, 26, 12, 12, 2, 31, 88, 0,
  65, 4, 30, 9, 9, 9
};

// this structure defines all the variables and events of your control interface
struct
{
  // input variables
  uint8_t button_1; // =1 if button pressed, else =0
  // output variables
  uint8_t led_1_r; // =0..255 LED Red brightness
  // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0
}
RemoteXY;

#pragma pack(pop)
/////////////////////////////////////////////
//           END RemoteXY include          //
/////////////////////////////////////////////
#define PIN_BUTTON_1 D4 // Sisäinen LED GPIO2
byte pushed = 0;
//======================================================================
void setup()
{
  Serial.begin(115200);
  RemoteXY_Init ();
  pinMode (PIN_BUTTON_1, OUTPUT); // Builtin LED
}
//======================================================================
void loop()
{
  RemoteXY_Handler ();
  digitalWrite(PIN_BUTTON_1, (RemoteXY.button_1 == 0) ? HIGH : LOW);

  if ((RemoteXY.button_1 == 1) && (pushed == 0))  // Push button of mobile screen
  {
    RemoteXY.led_1_r = 255;
    pushed = 1;
  }
  if (RemoteXY.button_1 == 0)   // Release button of mobile screen
  {
    pushed = 0;
    RemoteXY.led_1_r = 0;       // LED is dark on the screen and builtin LED
  }
}
// ******************************************************************************
//   RemoteXY_button_led_ssid_password_2.ino

#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
//#include <RemoteXY.h> // If this is used:
//                                      // #error RemoteXY mode does not defined or 
//                                      // defined error: REMOTEXY_MODE__XXXXXXX 

#include <remotexy_custom.h>  // tämä pitää olla lisättynä
CRemoteXY_Cloud remotexy;
const char * remotexyCloudToken = "ac5228930e1355372225655f4a9a46f6";

#pragma pack(push, 1)
uint8_t remotexyConfig[] =
{ 255, 1, 0, 1, 0, 19, 0, 10, 13, 1,
  1, 0, 27, 26, 12, 12, 2, 31, 88, 0,
  65, 4, 30, 9, 9, 9
};

struct
{
  uint8_t connect_flag;
  uint8_t button_1;     // =1 if button pressed, else =0
  uint8_t led_1_r;      // =0..255 LED Red brightness
} remotexyStruct;

#pragma pack(pop)

#define PIN_BUTTON_1 D4 // Builtin LED pin GPIO2 in ESP8266
byte pushed = 0;

//======================================================================
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 );
  // remotexy.begin( RemoteXY_CONF, &remotexyStruct, "", remotexyCloudToken );  // NORMAALI
  pinMode (PIN_BUTTON_1, OUTPUT); // Builtin LED
}
//======================================================================
void loop()
{
  remotexy.handler();
  digitalWrite(PIN_BUTTON_1, (remotexyStruct.button_1 == 0) ? HIGH : LOW);

  if ((remotexyStruct.button_1 == 1) && (pushed == 0))  // Push button of mobile screen
  {
    remotexyStruct.led_1_r = 255;   // LED is red on the screen and builtin LED
    pushed = 1;
  }

  if (remotexyStruct.button_1 == 0) // Release button of mobile screen
  {
    pushed = 0;
    remotexyStruct.led_1_r = 0;     // LED is dark on the screen and builtin LED
  }
}

17

Re: can I change wifi credentials without flashing code?

There is a problem in your struct. Elements order is important

This

struct
{
  uint8_t connect_flag;
  uint8_t button_1;     // =1 if button pressed, else =0
  uint8_t led_1_r;      // =0..255 LED Red brightness
} remotexyStruct;

should be

struct
{
  uint8_t button_1;     // =1 if button pressed, else =0
  uint8_t led_1_r;      // =0..255 LED Red brightness
  uint8_t connect_flag;
} remotexyStruct;

18 (edited by Paavo 2020-08-18 12:51:14)

Re: can I change wifi credentials without flashing code?

Thank you. All looks fine, really.
Now it seems that the problem of anyway users has indeed been solved.
So, original include file RemoteXY.h is useless and even forbidden in this solution where WiFimanager.h is used.
It have to be replaced to remotexy_custom.h.
The original RemoteXY commands may be replaced to these new ones like here in my application for example  RemoteXY.led_1_r = 255  have be changed to remotexyStruct.led_1_r = 255.
Hopefully others who work on this issue will also read your instructions and my own examples.

Now there was one more problem left if original library file RemoteXY.h is included to code.
That makes error: conflicting declaration 'CRemoteXY_Cloud remotexy' or something.
I want to use RemoteXY.h because function RemoteXY_sendInputVariables() is needed for feature Control "Edit field"
That function is needed to update Edit Field in application if the text in the box has been changed .
Solution is here, change this: RemoteXY.sendInputVariables()   to this   remotexy.sendInputVariables();

19

Re: can I change wifi credentials without flashing code?

Muhannad.Alaftarisi wrote:

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.


Hi Muhannad.Alaftarisi are you from egypt
if yes i need to call you in phone to ask you about code please
thanks