/* ___ ___ ___ _ _ ___ ___ ____ ___ ____ * / _ \ /___)/ _ \| | | |/ _ \ / _ \ / ___) _ \| \ *| |_| |___ | |_| | |_| | |_| | |_| ( (__| |_| | | | | * \___/(___/ \___/ \__ |\___/ \___(_)____)___/|_|_|_| * (____/ * 接收MQTT Client发送的数据,并将数据在4位数码管上显示出来 * Tutorial URL * CopyRight John Yu */ #include #include #include // Update these with values suitable for your network. const char* ssid = "your-ssid"; const char* password = "your-passwd"; const char* mqtt_server = "broker.mqttdashboard.com"; //const char* mqtt_server = "iot.eclipse.org"; const int CLK = D6; //Set the CLK pin connection to the display const int DIO = D5; //Set the DIO pin connection to the display TM1637Display display(CLK, DIO); //set up the 4-Digit Display. WiFiClient espClient; PubSubClient client(espClient); long lastMsg = 0; char msg[50]; int value = 0; void setup_wifi() { delay(100); // We start by connecting to a WiFi network Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } randomSeed(micros()); Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); } void callback(char* topic, byte* payload, unsigned int length) { Serial.print("Command from MQTT broker is : ["); Serial.print(topic); Serial.println(); Serial.print(" publish data is:"); for(int i=0;i