[心得] Arduino MQTT 控制、傳輸
#include #include const int led=2; //內建LED const char* ssid = "MISR"; const char* password = "WIFI密碼"; const char* mqttServer = "192.168.0.144"; const char* mqtt_server = "192.168.0.144"; const char* mqttUser = "bob01"; const char* mqttPassword = "123456"; const int mqttPort = 1883; WiFiClient espClient; PubSubClient client(espClient); long lastMsg = 0; char msg[50]; int value = 0; float temperature = 0; float humidity = 0; void setup() { Serial.begin(115200); setup_wifi(); client.setServer(mqtt_server, 1883); client.setCallback(callback); pinMode(led, OUTPUT); } void setup_wifi() { delay(10); // We start by connecting to a WiFi network Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println...