http://3.114.197.59/test/line_notify.php?token=你的權杖&message=傳送的訊息
/* This sketch sends data via HTTP GET requests to esp8266-shop.com and returns the website in html format which is printed on the console */
#include <ESP8266WiFi.h>
const char* ssid = "jjwalk";
//replace with your own wifi ssid
const char* password = "jamesjian";
//replace with your own //wifi ssid password
const char* host = "3.114.197.59";
void setup() {
Serial.begin(115200);
delay(10); // We start by connecting to a WiFi network Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
/* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default, would try to act as both a client and an access-point and could cause network-issues with your other WiFi-devices on your WiFi-network. */
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
int value = 0;
void loop() {
delay(5000);
++value;
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request
//this url contains the informtation we want to send to the server
//if esp8266 only requests the website, the url is empty
String url = "/test/line_notify.php?token=RqFM12eMY4yNPP3PAh8xykKee5cHZXVGZDgMrdddF3Px&message=有人已通報消息,請立即查看!!";
/* url += "?param1=";
url += param1;
url += "?param2=";
url += param2;
*/
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000){
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
// Read all the lines of the reply from server and print them to Serial
while (client.available())
{ String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
delay(500000);
}
如此就能一開機就送一個Line 的訊息至你的手機
作業:
請將pin 12 設為輸入,連接一個開關
,當它被按下接地為0時, 即自動送出一個Line 訊息至手機
作業二:
請將pin 12 設為輸入,連接一個開關,當它被按下時,即送出一個訊息給mqtt伺服器。通知觸發了。
MQTT 使用url 之 api
http://ai.prof-jj.com/MQTT/publish.php?topic=jjofficepc2&value=/close_windows&MQTT=broker.mqtt-dashboard.com
再用python 程式寫一個 接收mqtt信息 自動關閉執行中的視窗