這篇算是測試Linkit7697的極短文(也沒多短! 每次寫技術文廢話都一堆! XD)
主要是發現7697與MCS連線的時候,有時會連不上去,一直出現Reconnect
我原本用Mac Air,改為Windows,發現問題還是一樣!
結果是換了一個WiFi Router才好
Google後,發現有些使用者也有這種問題
嘿嘿! 那我想應該是碰到防火牆階層無法穿透的問題了
IoT在台灣要發光發熱前,應該是5年前了(遠目)
我跟一間台灣的軟體供應商聊過這個問題,他們叫作穿牆打洞的技術
先來用大家熟知的IP Camera來說明好了,當你的手機要看到你家的IP Camera
動作流程大致上像這樣
1、IP Camera要連上WiFi Router
2、WiFi Router與Cloud Server建立連線
3、Cloud Server找到你的手機
4、相親成功,IP Camera與手機自己來個P2P親密連線
但是啊! P2P不能打通所有的NAT,有些是非常難穿透的
這時會有一個Relay Server,當P2P穿不過,就把IPC的影像丟到Relay Server
手機再去Relay Server撈資料
如果上面你看的懂的話,那就會發現MCS應該是碰到穿不了牆洞打不開的事兒了
所以呢! 把Code改寫一下
Maker圈內,免費的Cloud一哥是誰?
ThingSpeak!
怎麼註冊就不寫了,網上一堆ESP8266的教學文
但我發現居然沒有Linkit7697連上ThingSpeak的教學文
這篇可能是頭香啊!
廢話不多說,馬上貼出修正的Code
#include <LWiFi.h>
char ssid[] = "你的WIFI帳號"; //
your network SSID (name)
char pass[] = "你的WIFI密碼"; // your network password (use for WPA, or use
as key for WEP)
int keyIndex = 0; // your network key Index number
(needed only for WEP)
#define HOST "api.thingspeak.com" //
ThingSpeak IP Address: 184.106.153.149
#define PORT 80
String GET = "GET /update?key=你的API KEY";
int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce
your sketch size)
// use the numeric IP instead of the name
for the server:
//IPAddress server(117,185,24,248);
char server[] =
"api.thingspeak.com";
// Initialize the Ethernet client library
// with the IP address and port of the
server
// that you want to connect to (port 80 is
default for HTTP):
WiFiClient client;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// attempt to connect to Wifi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to
SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP
network:
status = WiFi.begin(ssid, pass);
}
int h = 123; //自已隨便寫濕度
int t = 225; //自已隨便寫溫度
Serial.println("Connected to wifi");
printWifiStatus();
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected to server (GET)");
Serial.print( "Humidityh: " );
Serial.print( h );
Serial.print( ", Temperature: " );
Serial.println( t );
String getStr = GET + "&field1=" + String((int)t) +
"&field2=" +
String((int)h) +
"
HTTP/1.1\r\n";;
client.print( getStr );
client.print( "Host: api.thingspeak.com\n" );
client.print( "Connection: close\r\n\r\n" );
delay(1000);
// if there are incoming bytes available
// from the server, read them and print them:
while (client.available()) {
char c = client.read();
Serial.write(c);
}
}
}
void loop() {
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting from server.");
client.stop();
// do nothing forevermore:
while (true);
}
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
然後你可以看到HTTP Request的輸出(看到OK就對啦!)
然後去ThingSpeak看一下,果真有資料丟上來
當初做Simple Care從ESP8266轉去Linkit7697
居然從2017之後就沒在玩ThingSpeak了!
後來Simple Care的室內定位也完成了
(現在還有更先進的mmWave,ROS就有空再玩囉~)
回到正題,有沒有發現換個Cloud就沒問題了
MCS也是有穿牆打洞的問題,畢盡是免費的嘛!
看樣子要威脅到免費Cloud一哥還是需要一些時間
發哥如果當初買下那間專做穿牆打洞軟體商就沒事囉
有沒有發現我愈來愈少寫教學文,因為都做實驗影片啊!
註:我不是科學家,影片中的小朋友才是!