作者:peter | 更新时间:2017-04-23 | 浏览量:3303
在贝壳网站上申请了一片汇思锐的8266开发底板
首先下载乐鑫的固件然后按照下图烧写固件
打开汇思锐调试工具,按照上面一步一步设置
点击airkiss 按钮进入airkiss 配网模式。
进入乐鑫信息科技公众号,进行配置
链接后串口调试图,这样你的网络就链接到了WIFI上了,上电制动链接WIFI
Esptouch配置和Airkiss差不多,请自已摸索下。接下来就是下载程序了,
首先需要你自已搭建好ARDUINO的IDE编译环境(版本165以上可以编译ESP8266就可以),不会的请在贝壳网上看其他朋友的帖子,也可以百度。
下面是用贝壳的例程程序(开关),可以在贝壳网上下载,修改自已的KEY和设备号,烧写到ESP8266就OK了.
==========================================================
#include
#include
//宏定义 使用于nodemcu板
#ifdef NODEMCU
#define D0 16
#define D1 5
#define D2 4
#define D3 0
#define D4 2
#define D5 14
#define D6 12
#define D7 13
#endif
//============= 此处必须修该============
String DEVICEID="xxx"; // 你的设备编号 ==
String APIKEY = "xxxx"; // 设备密码==
//=======================================
unsigned long lastCheckInTime = 0; //记录上次报到时间
const unsigned long postingInterval = 40000; // 每隔60秒向服务器报到一次const char* host = "www.bigiot.net";
const int httpPort = 8181;
int pins[1]={D1};
//int pins[4] = {D5,D6,D7,D1};//LED引脚配置
int state[1] = {HIGH};//上电输出高电平
//int state[4] = {HIGH,HIGH,HIGH,HIGH};//上电输出高电平
int arr_len = sizeof(pins)/sizeof(pins[0]);
void setup() {
Serial.begin(115200);
delay(1000);
//默认输出关闭电频
for(int i=0;i pinMode(pins[i], OUTPUT);
digitalWrite(pins[i], state[i]);
}
}
WiFiClient client;
void loop() {
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
// Use WiFiClient class to create TCP connections
if (!client.connected()) {
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
delay(5000);
return;
}
}
if(millis() - lastCheckInTime > postingInterval || lastCheckInTime==0) {
checkIn();
}
// Read all the lines of the reply from server and print them to Serial
if (client.available()) {
String inputString = client.readStringUntil('\n');
inputString.trim();
Serial.println(inputString);
int len = inputString.length()+1;
if(inputString.startsWith("{") && inputString.endsWith("}")){
char jsonString[len];
inputString.toCharArray(jsonString,len);
aJsonObject *msg = aJson.parse(jsonString);
processMessage(msg);
aJson.deleteItem(msg);
}
}
}
void processMessage(aJsonObject *msg){
aJsonObject* method = aJson.getObjectItem(msg, "M");
aJsonObject* content = aJson.getObjectItem(msg, "C");
aJsonObject* client_id = aJson.getObjectItem(msg, "ID");
if (!method) {
return;
}
String M = method->valuestring;
if(M == "say"){
String C = content->valuestring;
String F_C_ID = client_id->valuestring;
if(C == "play"){
for(int i=0;i
state[i] = LOW;
digitalWrite(pins[i], state[i]);
}
sayToClient(F_C_ID,"LED All on!");
}else if(C == "stop"){
for(int i=0;i state[i] = HIGH;
digitalWrite(pins[i], state[i]);
}
sayToClient(F_C_ID,"LED All off!");
}
/* else{
int pin = C.toInt();
if(pin > 0 && pin <= arr_len){
pin--;
state[pin] = !state[pin];
digitalWrite(pins[pin], state[pin]);
}
sayToClient(F_C_ID,"LED pin:"+pin);
}*/
}
}
void checkIn() {
String msg = "{\"M\":\"checkin\",\"ID\":\"" + DEVICEID + "\",\"K\":\"" + APIKEY + "\"}\n";
client.print(msg);
lastCheckInTime = millis();
}
void sayToClient(String client_id, String content){
String msg = "{\"M\":\"say\",\"ID\":\"" + client_id + "\",\"C\":\"" + content + "\"}\n";
client.print(msg);
lastCheckInTime = millis();
}
==========================================================
最后说下,用贝壳的遥控命令是play(开),stop(关).没找到可以上传附件的按钮,第一次发贴,还不熟悉
需要附件和更多的资料可以加图片上的汇思锐QQ群,哪里都有,我只是把自已的一些不成熟的经验和大家分享下。