1 (edited by Paavo 2022-01-23 05:08:54)

Topic: Create new WiFi SSID and Password credential online for cloud project.

How to create new local wifi ssid  and password credential online for cloud project?

This same topic has been addressed in many different forums. It would probably already be good to somehow get the same thing on the same platform. I don't have the skills to do that.

Could any knowledgeable person finally advise coding a simple fully functional program for us for example? We have seen countless vague, difficult to understand and untested presentations. For example, one button and one LED will not be too complicated tunings.

Many of us have waited years good working example which is compatible newest RemoteXY library. Results are confused and not working.
WiFi manager apparently can't work at all with RemoteXY.  Though  it worked fine using added library remotexy_custom.h and if older library RemoteXy2.4.6. were installed. So no with newer RemoteXY3.1.7.

Even an example in library RemoteXY is not working   /RemoteXY/examples/Multi Connection/ESP_WiFiSetupUsingAP/ESP_WiFiSetupUsingAP.pde.

That makes access point and the man can edit new SSID and Password, that part of program  works.
But then, main program doesn't do anything.
Solution is only AP, not cloud, any way.

Question is: How to connect mobile application to to cloud ?

If only a great wifi manager could work, that would be the best.
https://github.com/tzapu/WiFiManager

On behalf of all our frustrated coders, I sincerely hope that our wish will come true, some day .....

2

Re: Create new WiFi SSID and Password credential online for cloud project.

Paavo wrote:

That makes access point and the man can edit new SSID and Password, that part of program  works.
But then, main program doesn't do anything.

What do you mean?

Paavo wrote:

Solution is only AP, not cloud, any way.

this example is easy to modify. A little later I will post a working example for WiFi+Cloud

3

Re: Create new WiFi SSID and Password credential online for cloud project.

/*
   Example to setup WiFi client and cloud server settings using open access point mode 
   for ESP32 or ESP8266
   
   This source code of graphical user interface 
   has been generated automatically by RemoteXY editor.
   To compile this code using RemoteXY library 3.1.1 or later version 
   download by link http://remotexy.com/en/library/
   To connect using RemoteXY mobile app by link http://remotexy.com/en/download/                   
     - for ANDROID 4.5.1 or later version;
     - for iOS 1.4.1 or later version;
    
   This source code is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.    
*/
//#define REMOTEXY__DEBUGLOG

#include <EEPROM.h>
#if defined (ESP8266)
  #include <ESP8266WiFi.h>
#elif defined (ESP32)
  #include <WiFi.h>  
#endif

#include <RemoteXY.h>

#define PIN_BUTTON_WIFISETUP 3   // pin of button for wifi settings, press this button when devise reset
#define REMOTEXY_SERVER_PORT 6377
#define DEVICE_NAME "RemoteXY"

#define REMOTEXY_CLOUD_SERVER "cloud.remotexy.com" // url of cloud server, does not change
#define REMOTEXY_CLOUD_PORT 6376 // port for cloud server, does not change

#pragma pack(push, 1)
////////////////////////////////////////
// WiFi+Cloud settings configuration
////////////////////////////////////////

#define ssidLength 21 // 20 chars max + zero
#define passLength 21  // 20 chars max + zero
#define tokenLength 33 // 32 chars max + zero
#define checkLength 1  // 1 byte
#define EPPROMLength ssidLength+passLength+tokenLength+checkLength

#define ssid_EPPROM 0x0000 
#define pass_EPPROM  ssid_EPPROM+ssidLength 
#define token_EPPROM ssid_EPPROM+ssidLength+passLength 
#define check_EPPROM ssid_EPPROM+ssidLength+passLength+tokenLength
#define checkValueForEPPROM 0x55

uint8_t const PROGMEM RemoteXY_CONF_WiFiSettings [] =
  { 255,76,0,0,0,149,0,15,172,2,
  7,4,28,9,47,6,9,15,46,6,
  24,31,2,21,7,4,28,21,47,6,
  9,30,46,6,24,31,2,21,129,0,
  28,5,34,4,9,10,35,4,31,87,
  105,70,105,32,110,97,109,101,32,40,
  83,83,73,68,41,58,0,129,0,28,
  17,35,4,9,25,35,4,31,87,105,
  70,105,32,112,97,115,115,119,111,114,
  100,58,0,129,0,28,32,30,4,9,
  42,25,4,31,67,108,111,117,100,32,
  116,111,107,101,110,58,0,7,4,28,
  36,47,6,9,47,46,6,24,31,2,
  33,1,2,28,51,47,8,8,83,48,
  8,190,31,82,69,83,69,84,32,68,
  69,86,73,67,69,0 };

struct {

    // input variables
  char ssid[21];  // string UTF8 end zero  
  char pass[21];  // string UTF8 end zero  
  char token[33];  // string UTF8 end zero  
  uint8_t buttonReset; // =1 if button pressed, else =0 

    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0 

} RemoteXY_WiFiSettings;

////////////////////////////////////////
// Main configuration
////////////////////////////////////////
uint8_t RemoteXY_CONF[] =
  { 255,4,0,2,0,245,0,10,8,2,
  130,1,3,22,36,19,2,30,35,23,
  8,130,1,3,42,36,18,2,58,35,
  25,8,129,0,6,30,18,6,4,75,
  0,6,8,0,66,1,44,3,36,47,
  41,6,10,77,5,26,129,0,82,45,
  9,6,53,79,6,4,17,48,37,0,
  129,0,82,24,9,6,53,42,8,4,
  17,53,48,37,0,129,0,81,3,15,
  6,52,7,11,4,17,49,48,48,37,
  0,7,54,4,30,32,10,4,70,32,
  11,5,26,5,129,0,4,23,31,6,
  4,64,24,5,16,65,117,116,111,32,
  108,101,118,101,108,58,0,2,0,4,
  10,31,10,4,12,31,10,2,26,31,
  31,77,65,78,85,65,76,0,65,85,
  84,79,0,129,0,3,3,34,6,4,
  5,29,5,16,80,117,109,112,32,109,
  111,100,101,0,129,0,4,43,21,6,
  4,32,18,5,16,77,97,110,117,97,
  108,0,2,0,4,49,31,10,4,39,
  31,10,2,26,31,31,79,78,0,79,
  70,70,0,65,4,48,52,9,9,16,
  87,9,9,129,0,60,54,18,6,28,
  89,26,6,11,80,117,109,112,32,111,
  110,0 };
  
struct {

    // input variables
  int16_t edit_level;  // 32767.. +32767 
  uint8_t switch_manual; // =1 if switch ON and =0 if OFF 
  uint8_t switch_pump; // =1 if switch ON and =0 if OFF 

    // output variables
  int8_t level; // =0..100 level position 
  uint8_t led_on_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          //
/////////////////////////////////////////////


CRemoteXY *remotexy;
uint8_t wifiSettingMode = 0;

boolean readRemoteXYFromEEPROM () {
  if (EEPROM.read(check_EPPROM) == checkValueForEPPROM) {
    for (uint8_t i = 0; i<ssidLength; i++) RemoteXY_WiFiSettings.ssid[i] = EEPROM.read(ssid_EPPROM+i); 
    for (uint8_t i = 0; i<passLength; i++) RemoteXY_WiFiSettings.pass[i] = EEPROM.read(pass_EPPROM+i); 
    for (uint8_t i = 0; i<tokenLength; i++) RemoteXY_WiFiSettings.token[i] = EEPROM.read(token_EPPROM+i); 
    return true;
  }
  return false;  
}

void writeRemoteXYToEEPROM () {
  for (uint8_t i = 0; i<ssidLength; i++) EEPROM.write (ssid_EPPROM+i, RemoteXY_WiFiSettings.ssid[i]);  
  for (uint8_t i = 0; i<passLength; i++) EEPROM.write (pass_EPPROM+i, RemoteXY_WiFiSettings.pass[i]);
  for (uint8_t i = 0; i<tokenLength; i++) EEPROM.write (token_EPPROM+i, RemoteXY_WiFiSettings.token[i]);
  EEPROM.write (check_EPPROM, checkValueForEPPROM);    
  EEPROM.commit ();  
}

void setup() 
{
  EEPROM.begin(EPPROMLength);
  pinMode (PIN_BUTTON_WIFISETUP, INPUT);

  boolean EEPROMisValid = readRemoteXYFromEEPROM ();
  if (!digitalRead(PIN_BUTTON_WIFISETUP) || (!EEPROMisValid)) {
    // wifi setup mode
    wifiSettingMode = 1;
    remotexy = new CRemoteXY (RemoteXY_CONF_WiFiSettings, &RemoteXY_WiFiSettings, "", new CRemoteXYConnectionServer (new CRemoteXYComm_WiFiPoint (DEVICE_NAME, ""), REMOTEXY_SERVER_PORT)); 
  }
  else {
    remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, "", new CRemoteXYConnectionCloud (new CRemoteXYComm_WiFi (RemoteXY_WiFiSettings.ssid, RemoteXY_WiFiSettings.pass), REMOTEXY_CLOUD_SERVER, REMOTEXY_CLOUD_PORT, RemoteXY_WiFiSettings.token));      

    // TODO you setup code
    // example code
    RemoteXY.edit_level = 50; 
    // END example code
  } 
  
}

int prevSwitch_1 = 0;

void loop() 
{ 
  remotexy->handler ();
  
  if (wifiSettingMode) {

    if (RemoteXY_WiFiSettings.buttonReset) {
      writeRemoteXYToEEPROM ();  
      ESP.restart (); 
    }
  }  
  else myLoop();

}


float level = 50;
int pump = 0;
uint32_t prevMillis = 0;


void myLoop() {

  // TODO you loop code
  // example code
  uint32_t t = millis ();
  if (t>prevMillis) {
    float dt = float (t - prevMillis)/1000.0;
    prevMillis = t;

    //Serial.println (dt);
  
    if (RemoteXY.switch_manual == 1) {
      pump = RemoteXY.switch_pump;
    }
    else {
      if (pump==0) {
        if (level > RemoteXY.edit_level) pump = 1;
      }
      else {
         if (level < RemoteXY.edit_level-10) pump = 0;
      }
    }
  
    level = level + dt;
    if (pump != 0) level = level - dt*3;
    if (level<0) level = 0;
    if (level>100) level = 100;
  
    RemoteXY.level = level;
    RemoteXY.led_on_r = (pump==0)?0:255;
  }
  // END example code
}

4 (edited by Paavo 2022-01-24 09:17:44)

Re: Create new WiFi SSID and Password credential online for cloud project.

Great.
Finally, the example works as such. Now it is much easier to even try to understand the relatively difficult logins in the RemotXY environment.

The token can be what ever I have generated in my RemoteXY token list. That's completely new to me.
This example will replace all the many years of all sorts of different attempts to get a wifi-like login to work. If only many of us incompetent could find your example.

You could also make an excellent guide explaining why and how the code has evolved like this. Probably too much to ask.
Thank you a lot.

(By the way, in the previous one, I imagined that the example was being handled in AP mode all the time because the data for the graphical interface token was missing.)

5 (edited by Paavo 2024-01-07 13:41:35)

Re: Create new WiFi SSID and Password credential online for cloud project.

This excellent example has worked so far. I have already used it in many applications.
Now the unimaginable has happened because I get the following error message.
I use Arduino IDE 1.8.16.
What could be the cause of the error?

exit status 1
no matching function for call to 'CRemoteXY::CRemoteXY(const uint8_t [156], <unnamed struct>*, const char [1], CRemoteXYConnectionServer*)'

The error is located in the section void setup(), below:

remotexy = new CRemoteXY (RemoteXY_CONF_WiFiSettings, &RemoteXY_WiFiSettings, "", new CRemoteXYConnectionServer (new CRemoteXYComm_WiFiPoint (DEVICE_NAME, ""), REMOTEXY_SERVER_PORT));

****************************************************************

The good news here:
I just now found by chance the crucial change that happened thanks to the RemoteXy software updates, ie:

Apparently, there has been a change in RemoteXy's examples as well.
The quotation marks   ""   have been removed from the line where the error occurred.
Fixed line in void setup(); must be:

remotexy = new CRemoteXY (RemoteXY_CONF_WiFiSettings, &RemoteXY_WiFiSettings, new CRemoteXYConnectionServer (new CRemoteXYComm_WiFiPoint (DEVICE_NAME, ""), REMOTEXY_SERVER_PORT));

as well as the line later below:

remotexy = new CRemoteXY (RemoteXY_CONF_PROGMEM, &RemoteXY, new CRemoteXYConnectionCloud (new CRemoteXYComm_WiFi (RemoteXY_WiFiSettings.ssid, RemoteXY_WiFiSettings.pass), REMOTEXY_CLOUD_SERVER, REMOTEXY_CLOUD_PORT, RemoteXY_WiFiSettings.token));

}

6

Re: Create new WiFi SSID and Password credential online for cloud project.

Yes you are right. Some changes have been made to the library. All examples have also been updated.

7

Re: Create new WiFi SSID and Password credential online for cloud project.

Explore alternative libraries for better compatibility with RemoteXY. Hopefully, a reliable WiFi manager will come through.