การกำหนดค่า SSID และ PASSWORD สำหรับ accesspoint ที่เราจะต่อเข้าไปในตัวแปร
#define SSID "TP-LINK2"
#define PASS "1234567890"
#define IP "184.106.153.149" // thingspeak.com
String GET = "GET /update?key=xxxxxxxxxxxxxx&field1=";
xxxxxxx คือ apikey ที่จะต้องไปสมัครใช้งาน thingspeak ก่อนและได้รับมา
การใช้งานใน mode ของ TCP ไม่ว่าจะเป็น ESP8266 หรือ SIM900 module
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += IP;
cmd += "\",80";
sendDebug(cmd);
หลังจากนั้นทำการส่งข้อมูลใน field1 ของ graph
cmd = GET;
cmd += tenmpF;
cmd += "\r\n";
EPSsend.print("AT+CIPSEND=");
EPSsend.println(cmd.length());
if(EPSsend.find(">")){
Serial.print(">");
Serial.print(cmd);
EPSsend.print(cmd);
}else{
sendDebug("AT+CIPCLOSE");
}
โปรแกรมย่อยการส่งคำสั่ง
void sendDebug(String cmd){
Serial.print("SEND: ");
EPSsend.println(cmd);
Serial.println(cmd);
}
โปรแกรมย่อยส่วนการติดต่อกับ wifi (กรณีใช้งานกับ ESP8266)
boolean connectWiFi(){
EPSsend.println("AT+CWMODE=1");
delay(2000);
String cmd="AT+CWJAP=\"";
cmd+=SSID;
cmd+="\",\"";
cmd+=PASS;
cmd+="\"";
sendDebug(cmd);
delay(5000);
if(EPSsend.find("OK")){
Serial.println("RECEIVED: OK");
return true;
}else{
Serial.println("RECEIVED: Error");
return false;
}
}
#define SSID "TP-LINK2"
#define PASS "1234567890"
#define IP "184.106.153.149" // thingspeak.com
String GET = "GET /update?key=xxxxxxxxxxxxxx&field1=";
xxxxxxx คือ apikey ที่จะต้องไปสมัครใช้งาน thingspeak ก่อนและได้รับมา
การใช้งานใน mode ของ TCP ไม่ว่าจะเป็น ESP8266 หรือ SIM900 module
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += IP;
cmd += "\",80";
sendDebug(cmd);
หลังจากนั้นทำการส่งข้อมูลใน field1 ของ graph
cmd = GET;
cmd += tenmpF;
cmd += "\r\n";
EPSsend.print("AT+CIPSEND=");
EPSsend.println(cmd.length());
if(EPSsend.find(">")){
Serial.print(">");
Serial.print(cmd);
EPSsend.print(cmd);
}else{
sendDebug("AT+CIPCLOSE");
}
โปรแกรมย่อยการส่งคำสั่ง
void sendDebug(String cmd){
Serial.print("SEND: ");
EPSsend.println(cmd);
Serial.println(cmd);
}
โปรแกรมย่อยส่วนการติดต่อกับ wifi (กรณีใช้งานกับ ESP8266)
boolean connectWiFi(){
EPSsend.println("AT+CWMODE=1");
delay(2000);
String cmd="AT+CWJAP=\"";
cmd+=SSID;
cmd+="\",\"";
cmd+=PASS;
cmd+="\"";
sendDebug(cmd);
delay(5000);
if(EPSsend.find("OK")){
Serial.println("RECEIVED: OK");
return true;
}else{
Serial.println("RECEIVED: Error");
return false;
}
}
Comments