Sending data from one ESP to another

I have a project in which I have two ESP boards. One is an ESP8266-12e which is the “SENDER”. The other board is an ESP32-CAM, the “RECEIVER”.
I am using AutoConnect on the SENDER to input and store the SSID and PASSWORD for WiFi connection. This works fine.
I am having problems using AutoConnect on the RECEIVER because when I do the programing of capturing and sharing the streaming video does not work.
So I am attempting to send the stored SSID and PASS from the SENDER to the RECEIVER via the serial connections. I have accomplished this between an Arduino Pro Mini and an ESP8266-01 and trying to use the same method here.

I first set up the SENDER.

I first make sure I have the SSID and PASS retrieved on the SENDER and make them into strings ssidString and pskString.

Serial.printf("SSID: %s\n", WiFi.SSID().c_str());
Serial.printf("SSID: %s\n", WiFi.psk().c_str());
String ssidString = WiFi.SSID().c_str();
String pskString = WiFi.psk().c_str();

Then I create a string of these two strings.

 String f = String('<')+String("Hi")+String(',')+String(ssidString)+String(',')+String(pskString)+String('>');

I then send the f string to the RECEIVER using Serial.print.

 delay (1000);
 Serial.print(f);
delay(500);
Serial.print(f);
delay(500);
Serial.print(f);
delay(500);
Serial.print(f);
delay(500);
Serial.print(f);
delay(500);
Serial.print(f);
delay(500);
Serial.print(f);
delay(500);
Serial.print(f);
delay(500);
Serial.print(f);
delay(500);
Serial.print(f);
delay(500);
Serial.print(f);
delay(500);
Serial.print(f);
delay(500);
Serial.print(f);

On the RECEIVER
I create my variables

const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];        // temporary array for use when parsing
// variables to hold the parsed data
char messageFromPC[numChars] = {0};
float floatFromPC = 0;
char ssidString[] = "";
float floatFromPC2 = 0;
char pskString[] = "";
boolean newData = false;

I use these to get the sent string, parse it and print out what each part is.

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;
    while (Serial.available() > 0 && newData == false) {
        rc = Serial.read();
        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }
        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}
//============
void parseData() {      // split the data into its parts
    char * strtokIndx; // this is used by strtok() as an index
    strtokIndx = strtok(tempChars,",");      // get the first part - the string
    strcpy(messageFromPC, strtokIndx); // copy it to messageFromPC
 
    strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
    strcpy(ssidString,strtokIndx);
    floatFromPC = atoi(strtokIndx);     // convert this part to an integer
    strtokIndx = strtok(NULL, ",");
    strcpy(pskString,strtokIndx);
    floatFromPC2 = atoi(strtokIndx);     // convert this part to a float
  
}
//============
void showParsedData() {
    Serial.print("Message ");
    Serial.println(messageFromPC);
    Serial.print("SSID");
    Serial.println(floatFromPC);
    Serial.println(ssidString);
    Serial.print("PASS ");
    Serial.println(floatFromPC2);
    Serial.println(pskString);
  
}
//end new stuff string

And in my

void setup()
{
  Serial.begin(57600);
  //while (!Serial);            //wait for serial connection.
delay (12000);
recvWithStartEndMarkers();
    if (newData == true) {
        strcpy(tempChars, receivedChars);
            // this temporary copy is necessary to protect the original data
            //   because strtok() used in parseData() replaces the commas with \0
        parseData();
        showParsedData();
        newData = false;
    }
#define SSID1 ssidString
#define PWD1 pskString
WiFi.begin(ssidString, pskString);
}

I watched the Serial Monitor and it takes about 11 seconds for the SENDER to start printing out the f string so I have a delay of 12 seconds before I start trying to get the sent string on the RECEIVER.
I have both devices connected to the same power source but the SENDER 3.3v and the RECEIVER 5v so when I apply power they start at the same time. I have connected RX to TX and TX to RX as well as RX to RX and TX to TX. Something isn’t working because the RECEIVER doesn’t connect to the WiFi.
Is there any way to start receiving the data when it is being sent? That way I wouldn’t have to guess when to start receiving.
I have both set to Serial.begin(57600).
Does anyone have any ideas as to why this isn’t working?

“Does anyone have any ideas as to why this isn’t working?”

No, but why not simply use MQTT? It’s a WHOLE lot easier than working with serial data.

You could possibly use Serial.available() on the receiver side to detect if data is there to process.
I’d have probably used a fixed length buffer, say 2 x 32 bytes to transfer the ssid and pass rather than attempting to embed special terminators in the data.

ESP-NOW is a pretty good deal.

From my understanding, and I could be wrong, both units have to be connected to WiFi to work so they both need the SSID and PASS know to work and I am trying to send the SSID and PASS from one to the other when using MQTT.
I would put things in the loop but I can't because I am using Blynk also and you are not supposed to put anything in (loop) except Blynk.run(); Thus I have to run my send and receive code at synchronized time. Unless I can run the send with delay and the receive with delay until I connect to WiFi or the char are not NULL. I have tried as I said timing everything to send and receive at the same time and I have checked my wiring. I think it should be Rx to Tx and Tx to Rx. I don't think a need a voltage shifter since ESP 12e outputs 3.3v and ESP32 Rx/Tx work on 3.3v. Would this make a difference? I just can't see why this doesn't work. I use it with other boards as I said but the Serial is set at 57600 baud rate instead of 115200. Would this make a difference? I think I am configuring my ssidString and pskString as char. Could someone check my code in (void) parseData() section of second to last code part in original post to make sure that is ok.

ESP-Now works pretty good and wireless to boot.

I’m sorry for the long absence. I don’t really want to use ESP-NOW. I put a condition of

if(Serial.available())[
digitalWrite(33,LOW);
}

and the led lights up when I am turning on the serial on the other device and sending information and I put

 if (newData == true) {
        strcpy(tempChars, receivedChars);
            // this temporary copy is necessary to protect the original data
            //   because strtok() used in parseData() replaces the commas with \0
        parseData();
        showParsedData();
        newData = false;
    }

inside the condition.
but still the ESP doesn’t connect with the address and pass sent. I am at my wits end. Any help with this would be much appreciated.

void parseData() {      // split the data into its parts
    char * strtokIndx; // this is used by strtok() as an index
    strtokIndx = strtok(tempChars,",");      // get the first part - the string
    strcpy(messageFromPC, strtokIndx); // copy it to messageFromPC
 
    strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
    strcpy(ssidString,strtokIndx);
    floatFromPC = atoi(strtokIndx);     // convert this part to an integer
    strtokIndx = strtok(NULL, ",");
    strcpy(pskString,strtokIndx);
    floatFromPC2 = atoi(strtokIndx);     // convert this part to a float
}

to be clear does this line

strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
    strcpy(ssidString,strtokIndx);

make ssidString a char so I can use it here

#define SSID1 ssidString

I just can’t figure out why this isn’t working

SteveMann:
"Does anyone have any ideas as to why this isn't working?"
No, but why not simply use MQTT? It's a WHOLE lot easier than working with serial data.

if it is so much simpler do you have a sourcecode source that offers a complete demo-system that sets up everything with a few mouseclicks?
If so I'm very interested. WHat I have found so far ist pretty complicated. Setting up a MQTT-Server
registering sensors etc. etc. etc.
best regards Stefan

StefanL38:
if it is so much simpler do you have a sourcecode source that offers a complete demo-system that sets up everything with a few mouseclicks?
If so I'm very interested. WHat I have found so far ist pretty complicated. Setting up a MQTT-Server
registering sensors etc. etc. etc.
best regards Stefan

Registering sensors? I have dozens of Arduino or ESP based devices all over my house and I've never heard of "registering sensors".

It is actually pretty simple. You get an old Raspberry Pi and install Mosquitto on it. That is your MQTT broker. Plug and play. Or you can use a public MQTT broker. Mosquitto.io has one.

In your Arduino sketch, you include PubSubClient.h. There's example sketches in the IDE.

MQTT works by publishing messages to a topic, and any processor can subscribe to that topic and receive the message. Most of my projects do both publish and subscribe. What you do with those messages is only limited by your imagination.

Back to the OP’s problem:
Is the issue that your method of transferring the WLAN credentials (ssid and password) between the sender and receiver is failing to deliver valid data ? Or is there some other problem?
For example, if instead of sending these credentials you, as a test, hard code these on the receiver side, does everything work as expected?

Edit

This construct looks odd:
#define SSID1 ssidString
#define PWD1 pskString
WiFi.begin(ssidString, pskString) ;

Are SSID1 and PWD1 used elsewhere in that sketch?
If you comment out the 2 #define statements, do you get errors?