Initializing argument 3 of 'void HardwareSerial::begin(long unsigned int, SerialConfig, SerialMode, uint8_t)' 87 | void begin(unsigned long bau

Hi i'm new to arduino programming, and i'm not sure what i've done wrong. Please, help me

#define DEBUG true

#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include "ApiHandler.h"

String serverIP = "";
String API_ENDPOINT = "/api/location/";

String lats;
String longi;

String msg;

const char* ssid = "";
const char* password = "";

const int TX_pin = ?;
const int RX_pin = ?;

WiFiClient client;
ApiHandler apiHandler(client);

uint16_t dataDelay = 60000; 

void setup() {
  connectToWiFi();

  Serial.begin(115200);
  Serial1.begin(115200, SERIAL_8N1, TX_pin, RX_pin);

  msg = "";
  msg = sendData("AT", 1000, DEBUG);
  while ( msg.indexOf("OK") == -1 ) {
    msg = sendData("AT", 1000, DEBUG);
    Serial.println("Trying");
  }

  msg = "";
  msg = sendData("AT", 1000, DEBUG);
  while ( msg.indexOf("OK") == -1 ) {
    msg = sendData("AT", 1000, DEBUG);
    Serial.println("Trying");
  }

  msg = "";
  msg = sendData("AT+GPSLP = 2", 2000, DEBUG);
  while ( msg.indexOf("OK") == -1 ) {
    msg = sendData("AT+GPSLP = 2", 1000, DEBUG);
    Serial.println("Trying");
  }

  msg = "";
  msg = sendData("AT+SLEEP = 1", 2000, DEBUG);
  while ( msg.indexOf("OK") == -1 ) {
    msg = sendData("AT+SLEEP = 1", 1000, DEBUG);
    Serial.println("Trying");
  }

}

void loop() {
  if (WiFi.status() == WL_CONNECTED) {
    
    readGPS();

    
  } else {
    Serial.println("WiFi Disconnected. Reconnecting...");
    connectToWiFi();
  }
  
  delay(dataDelay); 
}

void readGPS() {
  Serial1.println("AT+LOCATION=2\r\n");
  delay(2000);

  String response = "";
  while (Serial1.available()) {
    response += (char)Serial1.read();
    delay(1);
  }

  int index = response.indexOf("2");
  if (index != -1) {
    response = response.substring(index + 5);
    int commaIndex = response.indexOf(',');
    if (commaIndex != -1) {
      lats = response.substring(0, commaIndex);
      longi = response.substring(commaIndex + 1, commaIndex + 9);
      String response = apiHandler.sendPostRequest(serverIP + API_ENDPOINT, lats, longi);
      Serial.println(response);
    }
  }
}


void connectToWiFi() {
  WiFi.mode(WIFI_STA);
  Serial.println("Connecting to WiFi");
  WiFi.begin(ssid, password);
  int attempts = 0;
  while (WiFi.status() != WL_CONNECTED && attempts < 20) {
    delay(500);
    Serial.print(".");
    attempts++;
  }
  Serial.println("");
  if (WiFi.status() == WL_CONNECTED) {
    Serial.print("Connected to WiFi network with IP Address: ");
    Serial.println(WiFi.localIP());
  } else {
    Serial.println("Failed to connect to WiFi. Please check your credentials or restart the device.");
  }
}


String sendData(String command, const int timeout, boolean debug)
{
  String temp = "";
  Serial1.println(command);
  long int time = millis();
  while ( (time + timeout) > millis())
  {
    while (Serial1.available())
    {
      char c = Serial1.read();
      temp += c;
    }
  }
  if (debug)
  {
    Serial.print(temp);
  }
  return temp;
}
end this is error:
initializing argument 3 of 'void HardwareSerial::begin(long unsigned int, SerialConfig, SerialMode, uint8_t)'
   87 |     void begin(unsigned long baud, SerialConfig config, SerialMode mode, uint8_t tx_pin)
      |                                                         ~~~~~~~~~~~^~~~

exit status 1

Compilation error: invalid conversion from 'int' to 'SerialMode' [-fpermissive]

the statement

Serial1.begin(115200, SERIAL_8N1, TX_pin, RX_pin)

looks like code for setting up Serial1 on a ESP32

if you are using an ESP8266 and require a second serial port have a look at espsoftwareserial

also have a look at the section on serial in ESP8266 nodemcu-details-specifications

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