Page 191 - MDP2022-2
P. 191
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void callback(char *topic, byte *payload, unsigned int length)
{
memset(to_arduino_msg, 0, MSG_BUFFER_SIZE);
for (int i = 0; i < length; i++)
{
to_arduino_msg[i] = (char)payload[i];
}
if (strcmp(topic, "iot/led") == 0)
{
if (strcmp(to_arduino_msg, "on") == 0)
{
Serial.println("a");
memset(to_arduino_msg, 0, MSG_BUFFER_SIZE);
}
else if (strcmp(to_arduino_msg, "off") == 0)
{
Serial.println("A");
memset(to_arduino_msg, 0, MSG_BUFFER_SIZE);
}
}
else if (strcmp(topic, "iot/curtain") == 0)
{
if (strcmp(to_arduino_msg, "on") == 0)
{
Serial.println("b");
memset(to_arduino_msg, 0, MSG_BUFFER_SIZE);
}
else if (strcmp(to_arduino_msg, "off") == 0)
{
Serial.println("B");
memset(to_arduino_msg, 0, MSG_BUFFER_SIZE);
}
}
else if (strcmp(topic, "iot/heating_pad") == 0)
{
if (strcmp(to_arduino_msg, "on") == 0)
{
Serial.println("c");
memset(to_arduino_msg, 0, MSG_BUFFER_SIZE);