Hello. I am having a lot of troubles saving a string globally. I am using MQTT communications and my server ends a status message to remote devices. I need to read that status message and assign a current_status variable to that string.
I use raspberry PI as a server and I use python to publish message as following:
mqttc.publish("device1/status", "ACTIVE").
And on my serial monitor I can see that I receive that message.
I am checking whether the string received is "ACTIVE" and then use
to copy the string to my variable current_status
I have set the current_status as global variable and the initial state is "none"
However, my code immidaitely goes into an error state:
What is the problem with the way im saving string?
I use raspberry PI as a server and I use python to publish message as following:
mqttc.publish("device1/status", "ACTIVE").
And on my serial monitor I can see that I receive that message.
Code:
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
char message[length + 1];
strncpy (message, (char*)payload, length);
message[length] = '\0';
Serial.println(message);
}
if (strcmp(topic, status_topic) == 0){
if (strncmp(message, "GOOD_JOB", 8) == 0){
toggle_led_strip(blue,5);
}
else if (strncmp(message, "ACTIVE", 6) == 0){
strcpy (current_status,message);// RETURNS GURU MEDITATION ERROR
Serial.println(current_status);
}
}
if (strcmp(topic,number_to_pick_topic) == 0){ //if number_to_pick received, means the complecataion has been scanned and initiate the pick_to_light
clear_LED_strip(6);
number_to_pick = atoi(message);
//Serial.print("number to pick = ");
//Serial.println(number_to_pick);
OLED_display(item_inside.quantity,number_to_pick);
LED_strip_ON(green,number_to_pick);
}
}
Code:
strcpy (current_status,message);// RETURNS GURU MEDITATION ERROR
I have set the current_status as global variable and the initial state is "none"
Code:
char* current_status = "none"
What is the problem with the way im saving string?