ESP8266 Arduino 连接OneNET–MQTT
用Arduino开发ESP8266非常方便
OneNET也是一个非常好用的物联网平台
以下代码就是ESP8266连接OneNET MQTT服务器
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <Wire.h>
#include <SimpleDHT.h>
#include <ArduinoJson.h>
#define wifi_ssid "RedmiNote8"
#define wifi_password "12345678"
#define mqtt_server "183.230.40.39"/*OneNet-MQTT IP*/
#define mqtt_port 6002/*OneNet-MQTT port*/
#define mqtt_devid "599241948"/*OneNet-MQTT DeviceID*/
#define mqtt_pubid "347588"/*OneNet-MQTT ProductID*/
#define mqtt_password "=IV37lz9mpmomHUX3meVbfCFOUk="/*OneNet-MQTT APIkey*/
int pinDHT11 = 5;//IO5
SimpleDHT11 dht11(pinDHT11);
WiFiClient espClient;
PubSubClient client(espClient);
long last_time = 0;
unsigned short json_len = 0;
char dataDHT11[] = "{\"temp\":%d, \"humi\&#