GithubHelp home page GithubHelp logo

Comments (1)

larryn46 avatar larryn46 commented on August 14, 2024

I had to make some changes to example.ino to work. Sorry, the indentations don't show up in HTML


/*
* downloaded from https://www.hackster.io/Nouira/send-notifications-to-your-phone-or-pc-using-nodemcu-cf7c43
* https://github.com/ koenieee/ PushBullet-ESP8266/ issues/7
*/
#include "/home/fido/Arduino/credentials.h" // includes password and ssid
//need to change directory
#include < ESP8266WiFi.h > // import ESP8266 WiFi library
#include < WiFiClientSecure.h > //import client library
const char* programName = "pushbullet_note_link";
//const char* ssid = "crepe et gaufre";//SSID for your local wireless
//const char* password = "crepes@gaufres"; //Password

const char* host = "api.pushbullet.com";
const int httpsPort = 443; // the required port
const char* PushBulletAPIKEY = "o.xxxx...xxxx"; //get it from your pushbullet account
// api.pushbullet.com FA C0 BE 4E 64 B8 80 C7 B7 EC B6 D9 01 FF 61 0D AC 92 F5 A6
const char* fingerprint = "FA C0 BE 4E 64 B8 80 C7 B7 EC B6 D9 01 FF 61 0D AC 92 F5 A6";
void setup() {
Serial.begin(115200);
while(!Serial){} // delay
Serial.println();
Serial.println(programName);
Serial.print("connecting to ");
Serial.println(ssid);
//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());

// Use WiFiClientSecure class to create TLS connection
WiFiClientSecure client;
// bool setFingerprint(const char *fpStr);
client.setFingerprint(fingerprint);
Serial.print("setup() line "); Serial.print(__LINE__); Serial.print(" connecting to ");
Serial.println(host);
unsigned long connectTimeOut = 30000; // 30 seconds
unsigned long connectTimer = millis();
while(!client.connect(host, httpsPort))
{
Serial.print(".");
delay(1000);
if((millis() - connectTimer) > connectTimeOut){
Serial.print(" setup() line "); Serial.print(__LINE__); Serial.println(" connection timed out");
while(1); // halt
} // end if
} // end while
Serial.println();
Serial.print("setup() line "); Serial.print(__LINE__);Serial.println("connected");


String url = "/v2/pushes";

String messagebody_note = "{"type": "note", "title": "Hello !", "body": "My Name is Ahmed And You ?"}\r\n";

String messagebody_link = "{"type": "link", "title": "My Youtube", "body": "Best Channel^^!",
"url": "https://www.youtube.com/channel/UCZnkC2WQf-LcH9EOmHjlExA?
view_as=subscriber"}\r\n";

Serial.print("requesting URL: ");

Serial.println(url);

//send a simple note

client.print(String("POST ") + url + " HTTP/1.1\r\n" +

"Host: " + host + "\r\n" +

"Authorization: Bearer " + PushBulletAPIKEY + "\r\n" +

"Content-Type: application/json\r\n" +

"Content-Length: " +

String(messagebody_note.length()) + "\r\n\r\n");

client.print(messagebody_note);

delay(10000); // wait 10 s

//send a link

client.print(String("POST ") + url + " HTTP/1.1\r\n" +

"Host: " + host + "\r\n" +

"Authorization: Bearer " + PushBulletAPIKEY + "\r\n" +

"Content-Type: application/json\r\n" +

"Content-Length: " +

String(messagebody_link.length()) + "\r\n\r\n");

client.print(messagebody_link);



Serial.println("request sent");

//print the response



while (client.available() == 0);



while (client.available()) {

String line = client.readStringUntil('\n');

Serial.println(line);

} // end while loop



}// end setup

void loop() {

}// end loop()

from pushbullet-esp8266.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.