TTGO ESP32-WiFi ssid and password syntax

Hi

Card:
TTGO ESP32 - Paxcounter LoRa32 V2.1_1.6

I dont manage to find correct syntax to variable ssid and pasword

I run latest IDE

i use library wifi.h

Following code gives error

// Replace with your network credentials
const char* SSID = "redacted";
const char* password = "redacted";

error from line 4 under -> Serial.println(ssid);

void connectWiFi() {
  // Connect to Wi-Fi network with SSID and password
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);

compiler stops and gives error:

'ssid' was not declared in this scope

Any ideas to help me with the syntax?

M

Please show your code in full.

1 Like

All code

NB ALL OLED is disabled, this to save power.

/*********
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp32-lora-sensor-web-server/

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*********/

// Import Wi-Fi library
#include <WiFi.h>
#include "ESPAsyncWebServer.h"
#include <AsyncTCP.h>


#include <SPIFFS.h>

//Libraries for LoRa
#include <SPI.h>
#include <LoRa.h>

/*//Libraries for OLED Display
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
*/

// Libraries to get time from NTP Server
#include <NTPClient.h>
#include <WiFiUdp.h>

//define the pins used by the LoRa transceiver module
#define SCK 5
#define MISO 19
#define MOSI 27
#define SS 18
#define RST 14
#define DIO0 26

//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define BAND 433E6

/*
//OLED pins
#define OLED_SDA 4
#define OLED_SCL 15
#define OLED_RST 16
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
*/

// Replace with your network credentials
const char* SSID = "redacted";
const char* password = "redacted";

// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);

// Variables to save date and time
String formattedDate;
String day;
String hour;
String timestamp;


// Initialize variables to get and save LoRa data
int rssi;
String loRaMessage;
String temperature;
String humidity;
String pressure;
String readingID;

// Create AsyncWebServer object on port 80
AsyncWebServer server(80);

//Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RST);

// Replaces placeholder with DHT values
String processor(const String& var) {
  //Serial.println(var);
  if (var == "TEMPERATURE") {
    return temperature;
  }
  else if (var == "HUMIDITY") {
    return humidity;
  }
  else if (var == "PRESSURE") {
    return pressure;
  }
  else if (var == "TIMESTAMP") {
    return timestamp;
  }
  else if (var == "RRSI") {
    return String(rssi);
  }
  return String();
}

/*//Initialize OLED display
  void startOLED(){
  //reset OLED display via software
  pinMode(OLED_RST, OUTPUT);
  digitalWrite(OLED_RST, LOW);
  delay(20);
  digitalWrite(OLED_RST, HIGH);

  //initialize OLED
  Wire.begin(OLED_SDA, OLED_SCL);
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) { // Address 0x3C for 128x32
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
    */
  //}
  /*
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setCursor(0,0);
  display.print("LORA SENDER");
*/
//}

//Initialize LoRa module
void startLoRA() {
  int counter;
  //SPI LoRa pins
  SPI.begin(SCK, MISO, MOSI, SS);
  //setup LoRa transceiver module
  LoRa.setPins(SS, RST, DIO0);

  while (!LoRa.begin(BAND) && counter < 10) {
    Serial.print(".");
    counter++;
    delay(500);
  }
  if (counter == 10) {
    // Increment readingID on every new reading
    Serial.println("Starting LoRa failed!");
  }
  Serial.println("LoRa Initialization OK!");
  /*display.setCursor(0,10);
    display.clearDisplay();
    display.print("LoRa Initializing OK!");
    display.display();
  */
  delay(2000);
}

void connectWiFi() {
  // Connect to Wi-Fi network with SSID and password
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    yield();
  }
  // Print local IP address and start web server
  Serial.println("");
  Serial.println("WiFi connected.");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  /*
    /display.setCursor(0,20);
    display.print("Access web server at: ");
    display.setCursor(0,30);
    display.print(WiFi.localIP());
    display.display();
  */
}

// Read LoRa packet and get the sensor readings
void getLoRaData() {
  Serial.print("Lora packet received: ");
  // Read packet
  while (LoRa.available()) {
    String LoRaData = LoRa.readString();
    // LoRaData format: readingID/temperature&soilMoisture#batterylevel
    // String example: 1/27.43&654#95.34
    Serial.print(LoRaData);

    // Get readingID, temperature and soil moisture
    int pos1 = LoRaData.indexOf('/');
    int pos2 = LoRaData.indexOf('&');
    int pos3 = LoRaData.indexOf('#');
    readingID = LoRaData.substring(0, pos1);
    temperature = LoRaData.substring(pos1 + 1, pos2);
    humidity = LoRaData.substring(pos2 + 1, pos3);
    pressure = LoRaData.substring(pos3 + 1, LoRaData.length());
  }
  // Get RSSI
  rssi = LoRa.packetRssi();
  Serial.print(" with RSSI ");
  Serial.println(rssi);
}

// Function to get date and time from NTPClient
void getTimeStamp() {
  while (!timeClient.update()) {
    timeClient.forceUpdate();
  }
  // The formattedDate comes with the following format:
  // 2018-05-28T16:00:13Z
  // We need to extract date and time
  formattedDate = timeClient.getFormattedTime();
  Serial.println(formattedDate);

  // Extract date
  int splitT = formattedDate.indexOf("T");
  day = formattedDate.substring(0, splitT);
  Serial.println(day);
  // Extract time
  hour = formattedDate.substring(splitT + 1, formattedDate.length() - 1);
  Serial.println(hour);
  timestamp = day + " " + hour;
}

void setup() {
  // Initialize Serial Monitor
  Serial.begin(115200);
  //startOLED();
  startLoRA();
  connectWiFi();

  if (!SPIFFS.begin()) {
    Serial.println("An Error has occurred while mounting SPIFFS");
    return;
  }
  // Route for root / web page
  server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(SPIFFS, "/index.html", String(), false, processor);
  });
  server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send_P(200, "text/plain", temperature.c_str());
  });
  server.on("/humidity", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send_P(200, "text/plain", humidity.c_str());
  });
  server.on("/pressure", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send_P(200, "text/plain", pressure.c_str());
  });
  server.on("/timestamp", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send_P(200, "text/plain", timestamp.c_str());
  });
  server.on("/rssi", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send_P(200, "text/plain", String(rssi).c_str());
  });
  server.on("/winter", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(SPIFFS, "/winter.jpg", "image/jpg");
  });
  // Start server
  server.begin();

  // Initialize a NTPClient to get time
  timeClient.begin();
  // Set offset time in seconds to adjust for your timezone, for example:
  // GMT +1 = 3600
  // GMT +8 = 28800
  // GMT -1 = -3600
  // GMT 0 = 0
  timeClient.setTimeOffset(0);
}

void loop() {
  // Check if there are LoRa packets available
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    getLoRaData();
    getTimeStamp();
  }
}

ssid is not SSID - case does matter.

2 Likes

Hi, thanks for helping me

changed to ssid
New error

Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "TTGO LoRa32-OLED, TTGO LoRa32 V1 (No TFCard), 80MHz, 921600, None"

D:\Gdrive\Arduino\webserver-2022.08.15\LoRa_Receiver_Web_Server\LoRa_Receiver_Web_Server.ino: In function 'void connectWiFi()':

LoRa_Receiver_Web_Server:159:14: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]

   WiFi.begin(ssid, password);

              ^~~~

In file included from D:\Gdrive\Arduino\webserver-2022.08.15\LoRa_Receiver_Web_Server\LoRa_Receiver_Web_Server.ino:13:

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\libraries\WiFi\src/WiFi.h:79:21: note:   initializing argument 1 of 'int WiFiClass::begin(char*, const char*)'

     int begin(char* ssid, const char *passphrase);

               ~~~~~~^~~~

exit status 1

invalid conversion from 'const char*' to 'char*' [-fpermissive]



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

get rid the "const" from this line:

Hi

it did compile but don't connect to Helo wifi.

Error:
D:\Gdrive\Arduino\webserver-2022.08.15\LoRa_Receiver_Web_Server\LoRa_Receiver_Web_Server.ino:57:14: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
char* ssid = "redacted";
^~~~~~
D:\Gdrive\Arduino\webserver-2022.08.15\LoRa_Receiver_Web_Server\LoRa_Receiver_Web_Server.ino:58:18: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
char* password = "redacted";
^~~~~~~~~~~~~~
Sketch uses 397393 bytes (30%) of program storage space. Maximum is 1310720 bytes.
Global variables use 18420 bytes (6%) of dynamic memory, leaving 276492 bytes for local variables. Maximum is 294912 bytes.
esptool.py v3.3
Serial port COM8
Connecting....
Chip is ESP32-PICO-D4 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, Embedded Flash, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 98:cd:ac:f3:cf:70
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Flash will be erased from 0x00001000 to 0x00005fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x00071fff...
Compressed 17120 bytes to 11841...
Writing at 0x00001000... (100 %)
Wrote 17120 bytes (11841 compressed) at 0x00001000 in 0.4 seconds (effective 365.2 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 128...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (128 compressed) at 0x00008000 in 0.0 seconds (effective 534.2 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 727.4 kbit/s)...
Hash of data verified.
Compressed 397776 bytes to 226461...
Writing at 0x00010000... (7 %)
Writing at 0x0001b66a... (14 %)
Writing at 0x0002aeb6... (21 %)
Writing at 0x00030349... (28 %)
Writing at 0x00036747... (35 %)
Writing at 0x0003c499... (42 %)
Writing at 0x00041c24... (50 %)
Writing at 0x000471bc... (57 %)
Writing at 0x0004c4cb... (64 %)
Writing at 0x000514df... (71 %)
Writing at 0x000565d8... (78 %)
Writing at 0x0005bbe8... (85 %)
Writing at 0x00065139... (92 %)
Writing at 0x0006c72a... (100 %)
Wrote 397776 bytes (226461 compressed) at 0x00010000 in 3.6 seconds (effective 879.0 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

Serial output:
ets Jun 8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:12812
load:0x40080400,len:3032
entry 0x400805e4
LoRa Initialization OK!
Connecting to Helo

char ssid[] = "Helo";
const char password[] = "redacted";

Hi

thanks, I implemented it but stops at same place.

serial output:

LoRa Initialization OK!
Connecting to Helo

so the problem solved?

Hi

No, it is "connecting", not connected

maybe it's not a software issue now. Is it password correct?

Hi, its not a password problem. I have changed my nettwork name to a, and password aaaaaaaa, cheked and double checked.

It may have with new version of Arduino IDE.
also tried

WiFi.begin(ssid.c_str(), password.c_str());

gave error

invalid conversion from 'const char*' to 'char*' [-fpermissive]

however, there may be many reasons for this, not related to the code.

For example, may be these connections are prohibited on the router side. Or the power supply of the esp is not enough for the wifi to work ...

No, do not change ssid & password code, it seems correct. The problem somewhere else

I have an wemos d1 minu pro connected to my net, work as a charm.

This lora ttgo esp8266 may be the problem.

Maybe there is another wifi library i can test?

is it esp8266 or esp32 as you mentioned above?

Sorry for mixing.

this one TTGO ESP32-Paxcounter LoRa32 V2.1 1.6 Version 433/868/915MHZ LoRa ESP-32 OLED 0.96 Inch SD Card Bluetooth WIFI Module

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