I am trying to resolve the error
src/EspSoftwareSerial-8.1.0/examples/circular_queue_mp_test/mp_queue_test.cpp:8:10: fatal error: circular_queue/circular_queue_mp.h: No such file or directory
The error appeared after changing the Hardware serial to the software serial even after adding the required libraries to platformio.ini (mentioned below)
lib_deps =
bblanchon/StreamUtils@^1.8.0
paulstoffregen/Time@^1.6.1
plerup/EspSoftwareSerial@^8.2.0
Basically, I am writing a code for HMI Device which is connected to esp32 over RS485 Communication Protocol. The esp32 has to receive the required data over a communication protocol (extract) and then process it. After Processing it has to generate a control signal which sent back to the HMI device to control the operation. For now I want to test the receiving end by sending hex string or log file (in hex format) with the help of CoolTerm and USB serial Port of MAX-485 to TTL converter by sending the text log file or Hex numbers . Also check my code and help me to resolve the software serial error and suggestions for testing?
#include <Arduino.h>
#include <SoftwareSerial.h>
#include "Receving_end" // Include the header file for the receiving end
const int RS485_DE = 33; // DE (Driver Enable) pin connected to GPIO4
const int RS485_RE = 32; // RE (Receiver Enable) pin connected to GPIO27
const int RS485_TX = 26; // TX pin connected to GPIO17
const int RS485_RX = 27; // RX pin connected to GPIO16
SoftwareSerial RS485(26, 27); // RX, TX
void configureRS485()
{
pinMode(RS485_DE, OUTPUT);
pinMode(RS485_RE, OUTPUT);
// Set baud rate
Serial2.begin(9600, SERIAL_8E1, RS485_TX, RS485_RX);
}
void enableRS485Receive() {
digitalWrite(RS485_RE, HIGH);
digitalWrite(RS485_DE, LOW);
}
void setup() {
Serial.begin(115200);
configureRS485();
// Initialize RS485 communication
//RS485.begin(9600, SERIAL_8E1, RS485_TX, RS485_RX); // 8 data bits, 9600 baud, even parity, 1 stop bit
extern void processReceiveData (uint8_t *han);
}
void loop() {
uint8_t receivedData[20];
enableRS485Receive();
unsigned long timeOut = millis() + 100;
while (millis() < timeOut && RS485.available() < 20) { }
int bytesRead = RS485.readBytes(receivedData, 20);
}
External File
#include <HardwareSerial.h>
#include <ESP32Time.h>
#include <ctime>
#include <Wire.h>
#include <SPI.h>
#include <string.h> // Added missing include directive for "string.h"
#define MAX_ROWS 10
#define MAX_COLUMNS 30
#define OnOffLedPin 25
// Sensor data variables
float ambient_temp;
float inner_temp;
float set_temp;
int op_status;
char strOutput[100];
bool bNoComm = false; // or true
//Timer Timer_UPL;
int UPL_value = 0;
char code[9];
char version[7];
// Assuming lb_OD_Main_Micom is a String
String lb_OD_Main_Micom;
char lb_OD_Inverter_Micom[50];
char lb_ID_Inverter_Micom[50];
int outdoor_infor_2[MAX_ROWS][MAX_COLUMNS]; // Assuming MAX_ROWS and MAX_COLUMNS are defined
int outdoor_infor_1[MAX_ROWS][MAX_COLUMNS]; // Assuming MAX_ROWS and MAX_COLUMNS are defined
int Indoor_infor[MAX_ROWS][MAX_COLUMNS];
int Outdoor_infor[MAX_ROWS][MAX_COLUMNS];
uint8_t han[64]; // han array is declared as an integer array, as it is used to store hexadecimal values
std::time_t getTime() {
return std::time(nullptr);
}
// Declare Me and file_name_txt variables
struct MeStruct {
struct SaveFileDialogStruct {
char FileName[256];
} SaveFileDialog2;
struct InforStruct {
char Value[256];
} Indoor_infor[MAX_ROWS][MAX_COLUMNS]; // Corrected member name
struct Outdoor_inforStruct {
char Value[256];
} Outdoor_infor[MAX_ROWS][MAX_COLUMNS];
struct Outdoor_infor_1Struct {
char Value[256];
} Outdoor_infor_1[MAX_ROWS][MAX_COLUMNS];
} Me;
const char* file_name_txt = "D:/Backups/Backup_separate_Rx/file_name.txt";
int hex2int(const char* hex) {
return (int)strtoul(hex, NULL, 16); // strtoul function from the C standard library to convert the string to an integer
}
HardwareSerial SerialPort_Outdoor(2); // Use the second hardware serial port (RX2=16, TX2=17)
// Define the check_sum_receive function
uint16_t check_sum_receive(uint8_t* han, int size) {
// Calculate the checksum
uint16_t checksum = 0;
for (int i = 0; i < size; i++) {
checksum += han[i];
}
// Return the checksum
return checksum;
}
void outdoorText() {
struct tm now;
getLocalTime(&now);
strftime(strOutput, sizeof(strOutput), "%Y/%m/%d %H:%M:%S", &now);
if (!SerialPort_Outdoor.available()) {
SerialPort_Outdoor.end(); // Close the serial port
digitalWrite(OnOffLedPin, LOW); // Turn off the LED
return;
}
if (han[1] != 0 || han[2] > 62 || han[2] < 17) {
return;
}
if (bNoComm) {
return;
}
String receive_data = "";
for (int i = 0; i < han[2] + 1; i++) {
receive_data += String(han[i], HEX);
if (han[i] == 0x34 && (han[i + 1] == 0xFD || han[i + 1] == 0xBD || han[i + 1] == 0x7D || han[i + 1] == 0x5D)) {
break;
}
}
Serial.println(receive_data);
// next chunk of code
FILE* jStream; //to write or read the file
int check_sum_receive_value_carc[2];
// 저장 부문 storage sector
if (han[0] == 0x32) {
if (Me.SaveFileDialog2.FileName[0] != '\0' || file_name_txt[0] == '\0') {
for (int i = 0; i < 3; i++) {
if (i == 0) {
fprintf(jStream, "%s\n", strOutput);
fprintf(jStream, "%c%x\n", 9, han[i]);
fflush(jStream);
} else if (i > 0) {
fprintf(jStream, "%c%x\n", 9, han[i]);
fflush(jStream);
}
}
}
}
// check sum 확인 후, 맞지 않을 경우 sub 탈출, 세트 현황 Display 하지 않음
if (check_sum_receive(han, han[2]) != 0) {
if (hex2int(receive_data.c_str()) != check_sum_receive_value_carc[0]) {
exit(0);
}
// hex2int function is a custom function that takes a hexadecimal string as input and returns its integer equivalent
if (hex2int(receive_data.substring(receive_data.length() - 2).c_str()) != check_sum_receive_value_carc[1]) {
exit(0);
}
}
fclose(jStream);
}
//EEPROM Contents to find out outdoor unit operation status
void ODU_OP_status() {
if (han[0] == 0x32 && han[3] == 0x10) {
for (int j = 0; j <= 0; j++) {
j = 0; // Initialize j outside the loop
for (int i = 13; i <= han[2] - 5; i++) {
if (han[i] == 0x6 && han[i + 1] == 0xC) {
sprintf(code, "DB%1X%1X-%1X%1X%1X%1X%1X%1X",
(han[i + 2] >> 4) & 0xF, han[i + 2] & 0xF,
(han[i + 3] >> 4) & 0xF, han[i + 3] & 0xF,
(han[i + 4] >> 4) & 0xF, han[i + 4] & 0xF,
(han[i + 5] >> 4) & 0xF, han[i + 5] & 0xF);
sprintf(version, "%1X%1X.%1X%1X.%1X%1X",
(han[i + 6] >> 4) & 0xF, han[i + 6] & 0xF,
(han[i + 7] >> 4) & 0xF, han[i + 7] & 0xF,
(han[i + 8] >> 4) & 0xF, han[i + 8] & 0xF);
// Assuming lb_OD_EEPROM_Code is a char array for demonstration purposes
char lb_OD_EEPROM_Code[50];
sprintf(lb_OD_EEPROM_Code, "%s , %s", code, version);
}
// Main-Micom Code 보기
if (han[i] == 0x6 && han[i + 1] == 0x8) {
sprintf(code, "DB%1X%1X-%1X%1X%1X%1X%1X%1X",
(han[i + 2] >> 4) & 0xF, han[i + 2] & 0xF,
(han[i + 3] >> 4) & 0xF, han[i + 3] & 0xF,
(han[i + 4] >> 4) & 0xF, han[i + 4] & 0xF,
(han[i + 5] >> 4) & 0xF, han[i + 5] & 0xF);
sprintf(version, "%1X%1X.%1X%1X.%1X%1X",
(han[i + 6] >> 4) & 0xF, han[i + 6] & 0xF,
(han[i + 7] >> 4) & 0xF, han[i + 7] & 0xF,
(han[i + 8] >> 4) & 0xF, han[i + 8] & 0xF);
lb_OD_Main_Micom = String(code) + " , " + String(version);
}
// inverter micom code
if (han[i] == 0x86 && han[i + 1] == 0x01) {
char code[9];
char version[7];
snprintf(code, sizeof(code), "DB%1X%1X-%1X%1X%1X%1X%1X%1X",
(han[i + 2] >> 4) & 0xF, han[i + 2] & 0xF,
(han[i + 3] >> 4) & 0xF, han[i + 3] & 0xF,
(han[i + 4] >> 4) & 0xF, han[i + 4] & 0xF,
(han[i + 5] >> 4) & 0xF, han[i + 5] & 0xF);
snprintf(version, sizeof(version), "%1X%1X.%1X%1X.%1X%1X",
(han[i + 10] >> 4) & 0xF, han[i + 10] & 0xF,
(han[i + 11] >> 4) & 0xF, han[i + 11] & 0xF,
(han[i + 12] >> 4) & 0xF, han[i + 12] & 0xF);
// Assuming lb_OD_Inverter_Micom is a character array
snprintf(lb_OD_Inverter_Micom, sizeof(lb_OD_Inverter_Micom), "%s , %s", code, version);
}
// 고/저압 high/low pressure
if (han[i] == 0x82 && han[i + 1] == 0x6 && han[i - 2] != 0x6) {
outdoor_infor_2[j + 1][0] = (han[i + 2] * 256 + han[i + 3]) / 10.0;
}
if (han[i] == 0x82 && han[i + 1] == 0x8) {
outdoor_infor_2[j + 1][1] = (han[i + 2] * 256 + han[i + 3]) / 10.0;
}
// 목표압력 Target pressure 23/1/19
if (han[i] == 0x82 && han[i + 1] == 0x34) {
outdoor_infor_2[j + 1][3] = (han[i + 2] * 256 + han[i + 3]) / 10.0;
}
// 순시전력 (unit, Sum) Instantaneous power
if (han[i] == 0x84 && han[i + 1] == 0x11) {
outdoor_infor_1[j + 1][25] = han[i + 2] * 16777216 + han[i + 3] * 65536 + han[i + 4] * 256 + han[i + 5];
}
if (han[i] == 0x84 && han[i + 1] == 0x13) {
outdoor_infor_1[j + 1][26] = han[i + 2] * 16777216 + han[i + 3] * 65536 + han[i + 4] * 256 + han[i + 5];
}
// 실외온도 //outdoor temperature
if (han[i] == 0x82 && han[i + 1] == 0x4) {
int temperatureValue = han[i + 2] * 256 + han[i + 3];
if (temperatureValue <= 32767) {
outdoor_infor_2[j + 1][34] = temperatureValue / 10.0;
ambient_temp = temperatureValue / 10.0;
} else {
outdoor_infor_2[j + 1][34] = (temperatureValue - 65536) / 10.0;
ambient_temp = (temperatureValue - 65536) / 10.0;
}
}
// 운전용량 합 //Total operating capacity
if (han[i] == 0x82 && han[i + 1] == 0x33) {
outdoor_infor_1[j + 1][3] = han[i + 2] * 256 + han[i + 3];
}
// 실외기 마력//Outdoor unit horsepower
if (han[i] == 0x82 && han[i + 1] == 0x87) {
outdoor_infor_1[j + 1][1] = han[i + 2] * 256 + han[i + 3];
}
// Cooling/heating mode
if (han[i] == 0x80 && han[i + 1] == 0x3) {
switch(han[i + 2]) {
case 0:
snprintf(Me.Outdoor_infor_1[j + 1][4].Value, sizeof(Me.Outdoor_infor_1[j + 1][0]), "Main Cool");
break;
case 1:
snprintf(Me.Outdoor_infor_1[j + 1][4].Value, sizeof(Me.Outdoor_infor_1[j + 1][0]), "Main Heat");
break;
}
}
}
}
}
}
// Operation mode of the outdoor unit
void OP_MODE() {
// 80 mode 1 byte
for (int i = 13; i <= han[2] - 4; i++) {
if (han[0] == 0x32 && han[3] == 0x10) {
for (int j = 0; j <= 0; j++) {
j = 0; // Initialize j outside the loop
// OD On/Off
if (han[i] == 0x80 && han[i + 1] == 0x01) {
if (han[i + 2] == 0 || han[i + 2] == 7 || han[i + 2] > 39) {
outdoor_infor_1[j + 1][0] = 1; // On
//op_status = outdoor_infor_1[j + 1][0];
} else {
outdoor_infor_1[j + 1][0] = 0; // Off
op_status = outdoor_infor_1[j + 1][0];
}
}
break;
}
}
}
}
// Indoor unit operation status (1 Byte)
void idu_op() {
for (int i = 13; i <= han[2] - 4; i++) {
if (han[0] == 0x32 && han[2] != 0x14 && han[3] == 0x20) {
for (int j = 0; j <= 6; j++) {
j = 0; // Initialize j outside the loop
// Main-Micom Code 보기
if (han[i] == 0x6 && han[i + 1] == 0x8) {
char code[9];
char version[7];
snprintf(code, sizeof(code), "DB%1X%1X-%1X%1X%1X%1X%1X%1X",
(han[i + 2] >> 4) & 0xF, han[i + 2] & 0xF,
(han[i + 3] >> 4) & 0xF, han[i + 3] & 0xF,
(han[i + 4] >> 4) & 0xF, han[i + 4] & 0xF,
(han[i + 5] >> 4) & 0xF, han[i + 5] & 0xF);
snprintf(version, sizeof(version), "%1X%1X.%1X%1X.%1X%1X",
(han[i + 6] >> 4) & 0xF, han[i + 6] & 0xF,
(han[i + 7] >> 4) & 0xF, han[i + 7] & 0xF,
(han[i + 8] >> 4) & 0xF, han[i + 8] & 0xF);
snprintf(lb_ID_Inverter_Micom, sizeof(lb_ID_Inverter_Micom), "%s , %s", code, version);
}
// 실내기 운전 on/off // Indoor unit operation
if (han[i] == 0x40 && han[i + 1] == 0x0) {
switch (han[i + 2]) {
case 0:
// Me.Indoor_infor(j + 1, 0).Value = "운전 Off";
snprintf(Me.Indoor_infor[j + 1][0].Value, sizeof(Me.Indoor_infor[j + 1][0].Value), "운전 Off");
break;
case 1:
// Me.Indoor_infor(j + 1, 0).Value = "운전 On";
snprintf(Me.Indoor_infor[j + 1][0].Value, sizeof(Me.Indoor_infor[j + 1][0].Value), "운전 On");
break;
}
}
if(han[0] == 0x40 && han[1] == 0x02)
{
// Me.Indoor_infor(j + 1, 1).Value = "Fan" fan speed
snprintf(Me.Indoor_infor[j + 1][1].Value, sizeof(Me.Indoor_infor[j + 1][1].Value), "Fan");
}
break;
}
}
}
}
//2byte indoor unit data
void IDU_temp_data() {
if (han[0] == 0x32 && han[2] != 0x14 && han[3] == 0x20) {
for (int i = 13; i <= han[2] - 5; i++) {
for (int j = 0; j <= 6; j++) {
if (han[5] == j) {
// Set Temp
if (han[i] == 0x42 && han[i + 1] == 0x01) {
int temperatureValue = han[i + 2] * 256 + han[i + 3];
if (temperatureValue <= 32767) {
Indoor_infor[j + 1][3] = static_cast<double>(temperatureValue) / 10.0;
set_temp = static_cast<double>(temperatureValue) / 10.0;
} else {
Indoor_infor[j + 1][3]= static_cast<double> (temperatureValue - 65536) / 10.0;
set_temp = static_cast<double> (temperatureValue - 65536) / 10.0;
}
}
// 실내(room) 온도 (indoor room temperature)
if (han[i] == 0x42 && han[i + 1] == 0x3) {
int temperatureValue = han[i + 2] * 256 + han[i + 3];
if (temperatureValue <= 32767) {
Indoor_infor[j + 1][6] = static_cast<double> (temperatureValue) / 10.0;
inner_temp = static_cast<double> (temperatureValue) / 10.0;
} else {
Indoor_infor[j + 1][6] = static_cast<double> (temperatureValue - 65536) / 10.0;
inner_temp = static_cast<double> (temperatureValue - 65536) / 10.0;
}
}
// ID 용량 (ID capacity) //Operating Capacity
if (han[i] == 0x42 && han[i + 1] == 0x12) {
Indoor_infor[j + 1][13] = han[i + 2] * 256 + han[i + 3];
}
}
}
}
}
}
Edited by @sivar2311 to make the code easier to read.
Please note How to post logs and code in PlatformIO Community Forum