Closed yilmazyurdakul closed 1 week ago
Please first go through the steps of how to put your code in github so other people can read it. Your code here is unreadable and for me at least, I wont be able to help.
One question, is it possible you're trying to connect to the broker more than once?
I solved the issue. Thanks for your time. i will share the snippet.
// Initialize topicDoor static char topicDoorBuffer[34]; snprintf(topicDoorBuffer, sizeof(topicDoorBuffer), "FleetLink/devices/%s/door", internalId); topicDoor = topicDoorBuffer;
after resetting the board, code started to work. Also i realized that i was having some timing issue about reading spiffs. I am not sure about that problem but its just a theory.
The good thing is "problem solved!"
Thanks
Hi,
We are using this amazing library for post and get requests, MQTT connection and SMS. Works like a charm!
We only have one issue and we are struggling to solve it. We have MQTT topics like "const char* topicDoor = "FleetLink/devices/I2ROZBE3OT/door";" and these topics are hardcoded now. We need to assign deviceID (I2ROZBE3OT in this example) and generate topics in void setup.
we keep the internalID in SPIFFS and call it in void setup. we can assign deviceID and apiKey. apiKey is out of topic. There is no problem with that one. Here is the code for this action.
` if (!SPIFFS.exists(deviceIdFile)) { File f = SPIFFS.open(deviceIdFile, "w"); if (!f) { Serial.println("File open failed"); } else { f.println("AAAAAAAAAA"); // Default internalId f.println("00000000-0000-0000-0000-000000000000"); // Default apiKey f.close(); internalIdStr = "AAAAAAAAAA"; // Set default ID in the String apiKey = "00000000-0000-0000-0000-000000000000"; //default............... } } else { File f = SPIFFS.open(deviceIdFile, "r"); if (f) { Serial.println("Reading data from file:"); internalIdStr = f.readStringUntil('\n'); // Read internalId apiKey = f.readStringUntil('\n'); // Read apiKey internalIdStr.trim(); // Remove any newline or spaces apiKey.trim(); f.close();
}
internalId = internalIdStr.c_str(); Serial.println(internalId);`
We tried almost any converting method to assign these topics but no success. Then we realized something strange. If we add this code block only for one topic, it works. If i try to add another topic, it fails.
` char* topicDoorTemp = new char[50]; // Allocate enough memory snprintf(topicDoorTemp, 50, "FleetLink/devices/%s/door", internalId);
topicDoor = topicDoorTemp;`
Fail meaning the system keeps saying mqtt connected, and disconnected repeatedly.
I cant share all the code, there is 1500 lines of code. I will simplify the system for this issue and share it after doing it. I am just hoping to find a solution before doing that.
This is the serial handler works fine. I am sharing to show how i assign the internalID
`void serialHandler() { if (Serial.available()) { String inputData = Serial.readStringUntil('\n'); // Read the entire input line inputData.trim(); // Remove any trailing newlines or spaces
} }`
Also I am having the same problem by assigning SMS_TARGET from a variable dynamic.
[x ] I have read the Troubleshooting section of the ReadMe
What type of issues is this?
[x ] Question or request for help
Modem: Main processor board: TinyGSM version:
Thanks. I can provide additional info, debug or code block after preparing it, i need to make a simpler project to do it.