WiFi is not connecting in ESP-WROOM-32

I was using this code..

#include <Wire.h>
#include <SSD1306Wire.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <PS2Keyboard.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

#define OLED_RESET    -1
#define OLED_ADDRESS  0x3C
SSD1306Wire display(OLED_ADDRESS, SDA, SCL);

const char* ssid = "DESKTOP-828D1JN 3582"; 
const char* password = "2Y04w<42"; 

const int PS2_DATA_PIN = 19;
const int PS2_IRQ_PIN = 18;
const int LED_PIN = 2;

PS2Keyboard keyboard;

String userQuery;

void setup() {
  Serial.begin(115200);
  pinMode(LED_PIN, OUTPUT);

  if (!display.init()) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);
  }

  display.flipScreenVertically();
  display.clear();
  display.setFont(ArialMT_Plain_16);
  display.drawString(0, 0, "Connecting to Wi-Fi...");
  display.display();

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    digitalWrite(LED_PIN, HIGH);
    delay(500);
    digitalWrite(LED_PIN, LOW);
    delay(500);
    Serial.print(".");
  }

  Serial.println("\nConnected to WiFi");
  display.clear();
  display.drawString(0, 0, "Connected to WiFi");
  display.display();

  display.clear();
  display.display();

  keyboard.begin(PS2_DATA_PIN, PS2_IRQ_PIN);
}

String getChatGPTResponse(String userQuery) {
  HTTPClient http;

  String apiUrl = "https://api.openai.com/v1/chat/completions";
  String apiKey = "*****************************";

  http.begin(apiUrl);
  http.addHeader("Content-Type", "application/json");
  http.addHeader("Authorization", "Bearer " + apiKey);

  String requestBody = "{\"messages\": [{\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},{\"role\": \"user\", \"content\": \"" + userQuery + "\"}]}";

  int httpResponseCode = http.POST(requestBody);
  String response = http.getString();

  http.end();

  return response;
}

void loop() {
  display.println();
  display.println();
  display.println("LearnMateAI...");
  display.display();

  while (keyboard.available()) {
    char c = keyboard.read();
    if (c == PS2_ENTER || c == 13) {
      display.clearDisplay();
      display.setCursor(0, 0);
      display.println("You asked:");
      display.println();
      display.print("-> ");
      display.print(userQuery);

      String chatGPTResponse = getChatGPTResponse(userQuery);

      display.println();
      display.println();
      display.println("LearnMateAI says:");
      display.println("-> " + chatGPTResponse);

      display.display();
      userQuery = "";
    } else if (c == PS2_BACKSPACE || c == 8) {
      if (userQuery.length() > 0) {
        userQuery.remove(userQuery.length() - 1);
      }
    } else {
      userQuery += c;
    }
  }
}

Successfully uploaded this code but not connecting in Wi-Fi..

suggest you try a File>Examples>WiFi>WiFiscan will display networks in the area

if it lists the network OK try connecting to the network in a separate program - no LCD, sensors, etc in case they are the problem

tried this previously ..
Wifi founded but not connecting..

ok let me try this..

I tried this but don't working..

if I attempt to compile your code of post 1 it gives an error

SSD1306wire.cpp:1:10: fatal error: avr/pgmspace.h: No such file or directory
 #include <avr/pgmspace.h>
          ^~~~~~~~~~~~~~~~
compilation terminated.

checking the ssd1306wire documentation it states

  • This library is compatible with the avr architecture*

not suitable for a ESP32????

is the code in post 1 what you are attempting to use on the ESP32?

But if I attempt to compile this it is successfully compiled..

what is the specific ESP32 module you are using? give a link?
what Tools>Board do you select ? I use "ESP32 Dev Module"
where did you download the SSD1306wire library from?

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