In this example, the device connects to a Wi-Fi network and to an Mqtt server with the following parameters:
const char *wifissid = "";
const char *WifiPassword = "";
const char *mqttServer = "";
const char *mqttUser = "";
const char *mqttPassword = "";
const char *publishTopic = "";
const char *subscribeTopic = "";
const int mqttPort = 1883;
If your Mqtt server doesn't ask for username or password, you can leave the spaces empty const char *mqttUser = ""
and const char *mqttPassword = ""
.
-
If the device exceeds the number of wifi connection attempts
wifiConnectionAttempts = 30
, it will continue to work and try to connect every 20 secondswifi Loop()
. -
If the device loses connection to the Mqtt server, it will try to connect every 30 seconds
unsigned int intervalMqtt = 30000
. -
When the
#define PUBLISH_BUTTON 0
button is pressed, it sends the server the network namewifiSSID
, the channelwifiChannel
, the received signal strength indicatorwifiDbm
, the connection quality percentagewifiPercent
and the internal temperature of the cputempCpu
. -
A través de un cliente Mqtt, encienda o apague el led
#define MQTT_LED 2
como se muestra en los ejemplos.
Subscribe example:
- To turn on the led
{
"command": "led",
"value": "on"
}
- To turn off the led
{
"command": "led",
"value": "off"
}
Publish example:
{
"wifiSSID": "The name of your Wi-Fi network",
"wifiChannel": 11,
"wifiDbm": "-72",
"wifiPercent": "56",
"tempCpu": 57
}