我正在研究安全警报系统,需要将通知推送到我的电话并根据 pushbullet api 文档编写代码,但我的代码不起作用:
我将“ https://api.pushbullet.com ”和“api.pushbullet.com”都用于 pushbullet_server,并使用 WiFiClientSecure 和 WiFiClient 发送数据
void PushBullet::sendNotification(const String title ,const String body){
String url = "/v2/pushes";
String msg = String("{\"body\":\"") + body + String("\",\"title\":\"")+ title + String("\",\"type\":\"note\"}");
Serial.println(msg);
String request = String("POST ") + url + "HTTP/1.1\r\n" +
"Host: " + pushbullet_server + "\r\n" +
"User-Agent: ESP8266/NodeMCU 0.9\r\n" +
"Accept: */*\r\n" +
"Content-Type: application/json\r\n" +
"Content-Length: "+ msg.length() +"\r\n" +
"Access-Token: "+ this->access_token +"\r\n\r\n" +
msg;
Serial.println(request);
Serial.println("- connecting to pushing server: " + String(pushbullet_server));
secure_client.setInsecure();
if (!secure_client.connect(pushbullet_server, 443)) {
Serial.println("faile to connect " + pushbullet_server);
Serial.println(secure_client.readStringUntil('\n'));
return;
}
secure_client.print(request);
secure_client.stop();
while(secure_client.connected() && !secure_client.available()) delay(1); //waits for data
Serial.println(secure_client.readStringUntil('\n'));
Serial.println("- stopping the client");
}
和
WiFiClientSecuresecure_client;
String pushbullet_server = "https://api.pushbullet.com";
我也改变
String("POST ") + url + "HTTP/1.1\r\n"
经过
String("GET ") + url + "HTTP/1.1\r\n"
网址是
String url = "/v2/pushes";