/* ___ ___ ___ _ _ ___ ___ ____ ___ ____ * / _ \ /___)/ _ \| | | |/ _ \ / _ \ / ___) _ \| \ *| |_| |___ | |_| | |_| | |_| | |_| ( (__| |_| | | | | * \___/(___/ \___/ \__ |\___/ \___(_)____)___/|_|_|_| * (____/ * 远程发送数据,并将数据在1602LCD上显示出来 * Tutorial URL * CopyRight John Yu */ #include #include #include // This library is already built in to the Arduino IDE #include //This library you can add via Include Library > Manage Library > LiquidCrystal_I2C lcd(0x3F, 20, 4);/*0x3F表示1602 I2C的地址,这个地址不是唯一的,如果LCD不显示, 请参考http://osoyoo.com/2014/12/07/16x2-i2c-liquidcrystal-displaylcd/获取I2C地址, 替换掉这里的0X3F*/ // Update these with values suitable for your network. const char* ssid = "your_wifi_hotspot"; const char* password = "your_wifi_password"; const char* mqtt_server = "broker.mqttdashboard.com"; //const char* mqtt_server = "iot.eclipse.org"; 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:"); lcd.clear(); { for(int i=0;i