Error compiling for Esp board

//#include <WiFiClientSecure.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
#include <Nextion.h>
Nextion nextion(4, 5);
#if CONFIG_FREERTOS_UNICORE
#define ARDUINO_RUNNING_CORE 0
#else
#define ARDUINO_RUNNING_CORE 1
#endif

#define PIN_Q01 2
#define PIN_Q02 4
#define PIN_Q03 12
#define PIN_Q04 13
#define PIN_Q05 33
#define PIN_Q06 25
#define PIN_Q07 26
#define PIN_Q08 27
#define PIN_I01 14
#define PIN_I02 16
#define PIN_I03 17
#define PIN_I04 18
#define PIN_I05 19
#define PIN_I06 21
#define PIN_I07 22
#define PIN_I08 23

const char* ssid = "Zeptogreens";
const char* password = "Zeptogreens@2023";

const char* broker_address = "192.168.0.192";
const uint16_t broker_port = 1883;
const char* device_id = "lRnGVKdgfNBhreVsJoqj";

const char* pub_topic = "plc/testcode/";
const char* sub_topic = "plc/testcode/";

const char* mqtt_username = "Zeptogreens";
const char* mqtt_password = "123456";

QueueHandle_t pubqueue;

typedef struct {
  char *data;
} PubMsg;

enum CONN_ST {
  CONN_ST_START,
  CONN_ST_WIFI_CONNECTING,
  CONN_ST_BROKER_CONNECTING,
  CONN_ST_BROKER_CONNECTED,
};

CONN_ST conn_st = CONN_ST_START;

void msgReceived(char* topic, byte* payload, unsigned int len);
void sendMsg(char *msg);

WiFiClient wiFiClient;

PubSubClient pubSubClient(broker_address, broker_port, msgReceived, wiFiClient);

// Timer struct
typedef struct {
  int32_t PRE;
  int32_t AC;
  int32_t B;
  int32_t DN;
  int32_t EN;
  uint64_t TT;
} LD_TIMER;

union {
  uint32_t p[2];
  uint64_t v;
} LD_TIME;

uint64_t telemetryTime;

uint64_t getTime() {
  return LD_TIME.v;
}

uint8_t LD_I1 = 0;
uint8_t LD_I4 = 0;
uint8_t LD_I2 = 0;
uint8_t LD_I3 = 0;
uint8_t LD_Q1 = 0;
uint8_t LD_I5 = 0;
uint8_t LD_I6 = 0;
uint8_t LD_Q2 = 0;
uint8_t LD_Q3 = 0;
uint8_t LD_I7 = 0;
uint8_t LD_Q4 = 0;
uint8_t LD_Q5 = 0;
uint8_t LD_I8 = 0;
uint8_t LD_Q6 = 0;

LD_TIMER LD_T1;
LD_TIMER LD_T2;

NexNumber nI1 = NexNumber(0, 1, "nI1");
NexNumber nI4 = NexNumber(0, 2, "nI4");
NexNumber nI2 = NexNumber(0, 3, "nI2");
NexNumber nI3 = NexNumber(0, 4, "nI3");
NexNumber nQ1 = NexNumber(0, 5, "nQ1");
NexNumber nI5 = NexNumber(0, 6, "nI5");
NexNumber nI6 = NexNumber(0, 7, "nI6");
NexNumber nQ2 = NexNumber(0, 8, "nQ2");
NexNumber nQ3 = NexNumber(0, 9, "nQ3");
NexNumber nI7 = NexNumber(0, 10, "nI7");
NexNumber nQ4 = NexNumber(0, 11, "nQ4");
NexNumber nQ5 = NexNumber(0, 12, "nQ5");
NexNumber nI8 = NexNumber(0, 13, "nI8");
NexNumber nQ6 = NexNumber(0, 14, "nQ6");

char buffer[200];

void sendMsg(char *msg) {
  PubMsg pubMsg;
  pubMsg.data = msg;

  if (xQueueSend(pubqueue, &pubMsg, (TickType_t)0) != pdPASS) {
    Serial.println("Publish queue full!");
  }
}

void setup() {
  Serial.begin(115200);

  pinMode(PIN_I01, INPUT);
  pinMode(PIN_I02, INPUT);
  pinMode(PIN_I03, INPUT);
  pinMode(PIN_I04, INPUT);
  pinMode(PIN_I05, INPUT);
  pinMode(PIN_I06, INPUT);
  pinMode(PIN_I07, INPUT);
  pinMode(PIN_I08, INPUT);

  pinMode(PIN_Q01, OUTPUT);
  pinMode(PIN_Q02, OUTPUT);
  pinMode(PIN_Q03, OUTPUT);
  pinMode(PIN_Q04, OUTPUT);
  pinMode(PIN_Q05, OUTPUT);
  pinMode(PIN_Q06, OUTPUT);
  pinMode(PIN_Q07, OUTPUT);
  pinMode(PIN_Q08, OUTPUT);

  Serial.println("Starting...");

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  pubqueue = xQueueCreate(10, sizeof(PubMsg));

  nextionInit();

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");

  conn_st = CONN_ST_WIFI_CONNECTING;

  pubSubClient.setServer(broker_address, broker_port);
  pubSubClient.setCallback(msgReceived);

  while (!pubSubClient.connected()) {
    Serial.println("Connecting to MQTT broker...");
    if (pubSubClient.connect(device_id, mqtt_username, mqtt_password)) {
      Serial.println("MQTT broker connected");
      conn_st = CONN_ST_BROKER_CONNECTED;
      pubSubClient.subscribe(sub_topic);
    }
    else {
      Serial.print("MQTT broker connection failed, rc=");
      Serial.print(pubSubClient.state());
      Serial.println(", retrying in 5 seconds...");
      delay(5000);
    }
  }
}

void loop() {
  if (!pubSubClient.connected()) {
    reconnect();
  }
  pubSubClient.loop();

  if (xQueueReceive(pubqueue, &pubMsg, (TickType_t)10)) {
    Serial.print("Publishing message: ");
    Serial.println(pubMsg.data);
    pubSubClient.publish(pub_topic, pubMsg.data);
    delay(100);
  }

  uint64_t currentTime = getTime();
  if (currentTime - telemetryTime >= 1000) {
    telemetryTime = currentTime;

    // Create a JSON document
    StaticJsonDocument<256> doc;

    // Add values to the JSON document
    doc["I1"] = LD_I1;
    doc["I4"] = LD_I4;
    doc["I2"] = LD_I2;
    doc["I3"] = LD_I3;
    doc["Q1"] = LD_Q1;
    doc["I5"] = LD_I5;
    doc["I6"] = LD_I6;
    doc["Q2"] = LD_Q2;
    doc["Q3"] = LD_Q3;
    doc["I7"] = LD_I7;
    doc["Q4"] = LD_Q4;
    doc["Q5"] = LD_Q5;
    doc["I8"] = LD_I8;
    doc["Q6"] = LD_Q6;

    // Serialize the JSON document to a string
    String jsonString;
    serializeJson(doc, jsonString);

    // Convert the string to a character array
    jsonString.toCharArray(buffer, 200);

    // Publish the JSON data to the MQTT broker
    sendMsg(buffer);

    // Update the values on the Nextion display
    nI1.setValue(LD_I1);
    nI4.setValue(LD_I4);
    nI2.setValue(LD_I2);
    nI3.setValue(LD_I3);
    nQ1.setValue(LD_Q1);
    nI5.setValue(LD_I5);
    nI6.setValue(LD_I6);
    nQ2.setValue(LD_Q2);
    nQ3.setValue(LD_Q3);
    nI7.setValue(LD_I7);
    nQ4.setValue(LD_Q4);
    nQ5.setValue(LD_Q5);
    nI8.setValue(LD_I8);
    nQ6.setValue(LD_Q6);
  }
}

void msgReceived(char* topic, byte* payload, unsigned int len) {
  Serial.print("Message received on topic: ");
  Serial.println(topic);

  // Deserialize the JSON payload
  StaticJsonDocument<256> doc;
  DeserializationError error = deserializeJson(doc, payload, len);

  // Check if deserialization succeeded
  if (error) {
    Serial.print("deserializeJson() failed: ");
    Serial.println(error.c_str());
    return;
  }

  // Get the values from the JSON document
  LD_I1 = doc["I1"];
  LD_I4 = doc["I4"];
  LD_I2 = doc["I2"];
  LD_I3 = doc["I3"];
  LD_Q1 = doc["Q1"];
  LD_I5 = doc["I5"];
  LD_I6 = doc["I6"];
  LD_Q2 = doc["Q2"];
  LD_Q3 = doc["Q3"];
  LD_I7 = doc["I7"];
  LD_Q4 = doc["Q4"];
  LD_Q5 = doc["Q5"];
  LD_I8 = doc["I8"];
  LD_Q6 = doc["Q6"];

  // Update the values on the Nextion display
  nI1.setValue(LD_I1);
  nI4.setValue(LD_I4);
  nI2.setValue(LD_I2);
  nI3.setValue(LD_I3);
  nQ1.setValue(LD_Q1);
  nI5.setValue(LD_I5);
  nI6.setValue(LD_I6);
  nQ2.setValue(LD_Q2);
  nQ3.setValue(LD_Q3);
  nI7.setValue(LD_I7);
  nQ4.setValue(LD_Q4);
  nQ5.setValue(LD_Q5);
  nI8.setValue(LD_I8);
  nQ6.setValue(LD_Q6);
}

void reconnect() {
  while (!pubSubClient.connected()) {
    Serial.println("Attempting MQTT connection...");
    if (pubSubClient.connect(device_id, mqtt_username, mqtt_password)) {
      Serial.println("MQTT broker connected");
      conn_st = CONN_ST_BROKER_CONNECTED;
      pubSubClient.subscribe(sub_topic);
    }
    else {
      Serial.print("MQTT broker connection failed, rc=");
      Serial.print(pubSubClient.state());
      Serial.println(", retrying in 5 seconds...");
      delay(5000);
    }
  }
}

Can you post the error messages in code tags please.

Arduino: 1.8.19 (Windows 10), Board: "ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, None"





















C:\Users\DELL\Documents\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp:41:27: fatal error: avr/interrupt.h: No such file or directory

compilation terminated.

exit status 1

Error compiling for board ESP32 Dev Module.



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

I am getting these errors could you help me?

Any update?

not going to find an avr file for the esp32.
not sure you can use SoftwareSerial on esp32

1 Like

What did you see after enabling "show verbose..." in preferences?

1 Like

I leave it to the experts with esp32.

Also please don't bump the thread.

Thought so myself, getting around to saying so. :smiley:

Seriously? Asking for updates 10 minutes after posting your question?

Yes I don't understand how to rectify the error, so I'm waiting for solution from experts

Then you need to patient. Ten minutes is way too short a time to wait before asking for updates. You're not paying anyone for this help.

Okay I will wait thankyou

Bottom line is that the Nextion library you're trying to use hard codes the use of SoftwareSerial. As already noted by others above, ESP32 doesn't support SoftwareSerial. It doesn't need to as it has two extra hardware UART ports in addition to the one that implements "Serial" and is used for download code.

Basically, your choices are to modify the Nextion library to use one of the ESP32's hardware UARTS (I'd actually have it accept an object whose class inherits from the Stream class) or find a more suitable library.

Can you suggest which library should I use

No, I've never used Nextion devices. What did your search of the Arduino Library Manager turn up? What did your internet searches turn up?

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