Problem with reading Serial from Esp-01

i have an esp-01 receiving data from a website.. just a simple

Hello

using HTTPSClient example given in arduino library. while using the arduino as a dummy serial monitor to check if esp-01s recieves the data it takes time cause of domain being slow but it recieves data. but when using code in arduino to read Serial because i need to use that received data and make a qrcode of it. i have used

Serial.avaliable()

with it i can receive data but the complete string doesn't arrive and code moves on.
so used example 2(changed newline"/n" to ">") from here http://forum.arduino.cc/index.php?topic=396450.0 this link but now its stuck arduino can't receive anything, tried other various techinques in the forum but didn't work... been stuck here for a few days now. just need the received data to arrive in arduino completely and stored in char array then my setup will be complete. qr-code is already done. new to the forum if any problems do point out.sorry if my tone is kind of rude/demanding..

ESP-01s code:

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>

#ifndef STASSID
#define STASSID "XsDenied"
#define STAPSK  "Birdsflies704"
#endif

const char* ssid = STASSID;
const char* password = STAPSK;

const char* host = "asuiot12.000webhostapp.com";
const int httpsPort = 443;

// Use web browser to view and copy
// SHA1 fingerprint of the certificate
const char fingerprint[] PROGMEM = "5B FB D1 D4 49 D3 0F A9 C6 40 03 34 BA E0 24 05 AA D2 E2 01";

void setup() {
  delay(10000); // wait for arduino to start
  Serial.begin(9600);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  } 
}

void loop() {
  // Use WiFiClientSecure class to create TLS connection
  
  WiFiClientSecure client;
  client.setFingerprint(fingerprint);
  String url = "/esp8266test.txt";
  if (!client.connect(host, httpsPort)) {
    Serial.println("connection failed");
    return;
  }
   client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" + 
               "Connection: close\r\n\r\n");
               
  Serial.print("request sent");
  while (client.connected()) {
    String payload = client.readStringUntil('\n');
    if (payload == "\r") {
      Serial.print("headers received");
      break;
    }
  }
  String payload = client.readStringUntil('\r');
  Serial.print(payload);
}

Arduino Code

#include <SoftwareSerial.h>
SoftwareSerial ESP_Serial(10,11);
const byte numChars = 64;
char receivedChars[numChars];   // an array to store the received data

boolean newData = false;

void setup() {
    Serial.begin(115200);
    ESP_Serial.begin(115200);
    Serial.println("<Arduino is ready>");
}

void loop() {
    ESP_Serial.listen();
    recvWithEndMarker();
    showNewData();
}

void recvWithEndMarker() {
    static byte ndx = 0;
    char endMarker = '>';
    char rc;
    
    while (ESP_Serial.available() > 0 && newData == false) {
        rc = Serial.read();

        if (rc != endMarker) {
            receivedChars[ndx] = rc;
            ndx++;
            if (ndx >= numChars) {
                ndx = numChars - 1;
            }
        }
        else {
            receivedChars[ndx] = '\0'; // terminate the string
            ndx = 0;
            newData = true;
        }
    }
}

void showNewData() {
    if (newData == true) {
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        newData = false;
    }
}

Software serial doesn't work well at such speeds. Try something at or under 38400.

i had already tried it with 9600 speed but it didn't work first time, was making a silly mistake, wasn't reading data from ESP_serial. thanks still learned something new about softwareSerial

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.