Help, My Code Used to Compile, But Now It Won't

I recently moved all of my sketches and libraries to a different computer. This code used to compile, and now it won't, so I'm guessing I have a missing library or something, but I can't find it. The error message doesn't mention a missing library so??? Can anyone help?

Hardware is a SparkFun wifi IR blaster with an ESP8266 processor.

//#include <WiFi.h>
//extern "C" {
//  #include "freertos/FreeRTOS.h"
//  #include "freertos/timers.h"
//}

#include <ESP8266WiFi.h>
#include <Ticker.h>

#include <AsyncMqttClient.h>

// code from fujitsu ac control
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ir_Fujitsu.h>

#define WIFI_SSID "runningdog"
#define WIFI_PASSWORD "n,bUs692>Hq"
#define MQTT_HOST IPAddress(192, 168, 1, 72)
#define MQTT_PORT 1883

// Create objects to handle MQTT client
AsyncMqttClient mqttClient;
//TimerHandle_t mqttReconnectTimer;
//TimerHandle_t wifiReconnectTimer;

Ticker wifiReconnectTimer;

const int tempSet = 20;  //wall unit temperature setpoint
const int ac_mode = 1;  //wall unit mode, 1 = cool, 2 = heat

void connectToWifi() {
  Serial.println("Connecting to Wi-Fi...");
  WiFi.begin("ssid", "password");
}

void connectToMqtt() {
  Serial.println("Connecting to MQTT...");
  mqttClient.connect();
}

void WiFiEvent(WiFiEvent_t event) {
  Serial.printf("[WiFi-event] event: %d\n", event);
  switch (event) {
    case SYSTEM_EVENT_STA_GOT_IP:
      Serial.println("WiFi connected");
      Serial.println("IP address: ");
      Serial.println(WiFi.localIP());
      connectToMqtt();
      break;
    case SYSTEM_EVENT_STA_DISCONNECTED:
      Serial.println("WiFi lost connection");
      xTimerStop(mqttReconnectTimer, 0); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
      xTimerStart(wifiReconnectTimer, 0);
      break;
  }
}

// Add more topics that want your ESP32 to be subscribed to
void onMqttConnect(bool sessionPresent) {
  Serial.println("Connected to MQTT.");
  Serial.print("Session present: ");
  Serial.println(sessionPresent);
  // ESP32 subscribed to hvac/lr_AC_setpoint;
  uint16_t packetIdSub = mqttClient.subscribe("hvac/br_AC_setpoint", 0);
  uint16_t packetIdSub1 = mqttClient.subscribe("hvac/br_AC_mode", 0);
  Serial.print("Subscribing at QoS 0, packetId: ");
  Serial.println(packetIdSub);
  Serial.println(packetIdSub1);
}

void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
  Serial.println("Disconnected from MQTT.");
  if (WiFi.isConnected()) {
    xTimerStart(mqttReconnectTimer, 0);
  }
}

void onMqttSubscribe(uint16_t packetId, uint8_t qos) {
  Serial.println("Subscribe acknowledged.");
  Serial.print("  packetId: ");
  Serial.println(packetId);
  Serial.print("  qos: ");
  Serial.println(qos);
}

void onMqttUnsubscribe(uint16_t packetId) {
  Serial.println("Unsubscribe acknowledged.");
  Serial.print("  packetId: ");
  Serial.println(packetId);
}

// You can modify this function to handle what happens when you receive a certain message in a specific topic
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
  String messageTemp;
  for (int i = 0; i < len; i++) {
    //Serial.print((char)payload[i]);
    messageTemp += (char)payload[i];
  }
  if (topic == "hvac/br_AC_setpoint" ) {
    tempSet = stoi(messageTemp);
    ac.setTemp(tempSet);
  }
  if (topic == "hvac/br_AC_mode") {
    ac_mode = stoi(messageTemp);
    if (ac_mode = 1) {
      ac.setMode(kFujitsuAcModeCool);
    }
    if (ac_mode = 2) {
      ac.setMode(kFujitsuAcModeHeat);
    }
  }
}
// Now send the IR signal.
Serial.println("Sending IR command to A/C ...");
#if SEND_FUJITSU_AC
ac.send();
#else  // SEND_FUJITSU_AC
Serial.println("Can't send because SEND_FUJITSU_AC has been disabled.");
#endif  // SEND_FUJITSU_AC
printState();
}

void printState() {
  // Display the settings.
  Serial.println("Fujitsu A/C remote is in the following state:");
  Serial.printf("  %s\n", ac.toString().c_str());
  // Display the encoded IR sequence.
  unsigned char* ir_code = ac.getRaw();
  Serial.print("IR Code: 0x");
  for (uint8_t i = 0; i < ac.getStateLength(); i++)
    Serial.printf("%02X", ir_code[i]);
  Serial.println();
}

void setup() {
  ac.begin();
  Serial.begin(115200);
  delay(200);
  mqttReconnectTimer = xTimerCreate("mqttTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0, reinterpret_cast<TimerCallbackFunction_t>(connectToMqtt));
  wifiReconnectTimer = xTimerCreate("wifiTimer", pdMS_TO_TICKS(2000), pdFALSE, (void*)0, reinterpret_cast<TimerCallbackFunction_t>(connectToWifi));

  WiFi.onEvent(WiFiEvent);

  mqttClient.onConnect(onMqttConnect);
  mqttClient.onDisconnect(onMqttDisconnect);
  mqttClient.onSubscribe(onMqttSubscribe);
  mqttClient.onUnsubscribe(onMqttUnsubscribe);
  mqttClient.onMessage(onMqttMessage);
  mqttClient.setServer(MQTT_HOST, MQTT_PORT);

  connectToWifi();

  // Set up what we want to send. See ir_Fujitsu.cpp for all the options.
  Serial.println("Default state of the remote.");
  printState();
  Serial.println("Setting desired state for A/C.");
  // See `fujitsu_ac_remote_model_t` in `ir_Fujitsu.h` for a list of models.
  ac.setModel(ARRAH2E);
  ac.setSwing(kFujitsuAcSwingOff);
  ac.setMode(kFujitsuAcModeCool);
  ac.setFanSpeed(kFujitsuAcFanHigh);
  ac.setTemp(24);  // 24C
  ac.setCmd(kFujitsuAcCmdTurnOn);
}

void loop() {
  // Now send the IR signal.
  Serial.println("Sending IR command to A/C ...");
#if SEND_FUJITSU_AC
  ac.send();
#else  // SEND_FUJITSU_AC
  Serial.println("Can't send because SEND_FUJITSU_AC has been disabled.");
#endif  // SEND_FUJITSU_AC
  printState();
  delay(5000);

}

I attached the many error messages in an attachment.

Many thanks,
Dennis

error_messages.txt (3.06 KB)

I suggest you actually post the error msg (within </> code tags) because the line endings got lost in the txt, and i can't read it like that.
i don't think your sketch compiled before, and even if it did i doubt it was working as intended

const int ac_mode = 1;  //wall unit mode, 1 = cool, 2 = heat
{...}
if (ac_mode = 1) {
      ac.setMode(kFujitsuAcModeCool);
    }
    if (ac_mode = 2) {
      ac.setMode(kFujitsuAcModeHeat);
    }

Certainly a version of this code very close to this did compile and is currently running temperature control in my living room. But I may have inadvertently changed something in the code which is causing the problem.

Thanks,
Dennis

Here are the error messages:

Arduino: 1.8.13 (Mac OS X), Board: "Generic ESP8266 Module, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), dtr (aka nodemcu), 26 MHz, 40MHz, DOUT (compatible), 1MB (FS:64KB OTA:~470KB), 2, nonos-sdk 2.2.1+100 (190703), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

/Users/Kerry/Documents/Arduino/bedroom_AC_controller/bedroom_AC_controller.ino: In function 'void WiFiEvent(WiFiEvent_t)':
bedroom_AC_controller:47:10: error: 'SYSTEM_EVENT_STA_GOT_IP' was not declared in this scope
case SYSTEM_EVENT_STA_GOT_IP:
^
bedroom_AC_controller:53:10: error: 'SYSTEM_EVENT_STA_DISCONNECTED' was not declared in this scope
case SYSTEM_EVENT_STA_DISCONNECTED:
^
bedroom_AC_controller:55:18: error: 'mqttReconnectTimer' was not declared in this scope
xTimerStop(mqttReconnectTimer, 0); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
^
bedroom_AC_controller:55:39: error: 'xTimerStop' was not declared in this scope
xTimerStop(mqttReconnectTimer, 0); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
^
bedroom_AC_controller:56:40: error: 'xTimerStart' was not declared in this scope
xTimerStart(wifiReconnectTimer, 0);
^
/Users/Kerry/Documents/Arduino/bedroom_AC_controller/bedroom_AC_controller.ino: In function 'void onMqttDisconnect(AsyncMqttClientDisconnectReason)':
bedroom_AC_controller:77:17: error: 'mqttReconnectTimer' was not declared in this scope
xTimerStart(mqttReconnectTimer, 0);
^
bedroom_AC_controller:77:38: error: 'xTimerStart' was not declared in this scope
xTimerStart(mqttReconnectTimer, 0);
^
/Users/Kerry/Documents/Arduino/bedroom_AC_controller/bedroom_AC_controller.ino: In function 'void onMqttMessage(char*, char*, AsyncMqttClientMessageProperties, size_t, size_t, size_t)':
bedroom_AC_controller:103:31: error: 'stoi' was not declared in this scope
tempSet = stoi(messageTemp);
^
bedroom_AC_controller:104:5: error: 'ac' was not declared in this scope
ac.setTemp(tempSet);}
^
bedroom_AC_controller:106:31: error: 'stoi' was not declared in this scope
ac_mode = stoi(messageTemp);
^
bedroom_AC_controller:107:16: error: assignment of read-only variable 'ac_mode'
if(ac_mode = 1) {
^
bedroom_AC_controller:108:7: error: 'ac' was not declared in this scope
ac.setMode(kFujitsuAcModeCool);
^
bedroom_AC_controller:110:17: error: assignment of read-only variable 'ac_mode'
if(ac_mode = 2) {
^
bedroom_AC_controller:111:7: error: 'ac' was not declared in this scope
ac.setMode(kFujitsuAcModeHeat);
^
/Users/Kerry/Documents/Arduino/bedroom_AC_controller/bedroom_AC_controller.ino: At global scope:
bedroom_AC_controller:116:3: error: 'Serial' does not name a type
Serial.println("Sending IR command to A/C ...");
^
bedroom_AC_controller:118:3: error: 'ac' does not name a type
ac.send();
^
bedroom_AC_controller:122:15: error: expected constructor, destructor, or type conversion before ';' token
printState();
^
bedroom_AC_controller:123:1: error: expected declaration before '}' token
}
^
exit status 1
'SYSTEM_EVENT_STA_GOT_IP' was not declared in this scope

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

Did you install the ESP32 patch on the new computer?

I'm not familiar with the patch you're talking about. I installed the libraries for ESP32 and 8266. I've also installed libraries for wifi & MQTT, but I must be missing something. A brain perhaps :frowning:

Thanks,
Dennis

Each microcontroller has its own instruction set. The IDE needs access to that instruction set based on the board (Tools --> Boards) you select. This explains the process.

econjack:
Each microcontroller has its own instruction set. The IDE needs access to that instruction set based on the board (Tools --> Boards) you select. This explains the process.
Ok, I was unsure if that was what you were referring to. I did that. In fact that site is where I got a lot of the code I used from.

Thanks,
Dennis

Do you have a simple ESP32 program that will compile on the old PC and on the new PC? That will give you confidence that the ESP32 infrastructure has been properly installed on the new PC.

...R

denniscloutier:
Certainly a version of this code very close to this did compile

For some definition of "very close" :wink:
That gave me a good chuckle, thanks.