Monday, 11 January 2016

3D Printer Pushbullet Notification

I recently bought a 3D printer XYZ Dzvinci Jr.), mainly because it was £100 off at Ebuyer, and I've been printing loads of stuff from Thingiverse and designing some of my own stuff using

One of the things you soon notice is how long it takes to print a design, it can take hours for a large design and as the printer is upstairs and I was constantly going up and down stairs seeing if it had finished yet.

So I thought I'd use some electronics to send a notification when it had finished.  I decided to use an ESP8266 to connect to my network and send a Pushbullet notification which I will receive on my phone and also my PC, through a Chrome add-on.

I noticed that after the printer had finished the table moved right to the front of the printer and I thought to use a micro-switch that would be triggered by the table when it moved to the front.
As luck would have it I had the perfect switch in my box of bits and I was able to mount it using two screws and two Tee-Nuts into the existing aluminium profile frame of the printer.

Test setup running off batteries through the micro-switch
I found an Arduino sketch that sends a Pushbullet notification on the forum, this sketch makes an HTTPS connection to Pushbullet and sends a text note, the code is all in the setup section of the sketch and only runs once, this was actually just what I wanted as I was going to use the micro-switch to power up the ESP8266 rather that use it as a button input.

The hardware I used was a development ESP board from ALiExpress they are less than $3 each and come in two parts, one being the USB/serial interface and the other the actual ESP board.
I use the RGB LED on the board to show the progress of the connection
  • Red = Waiting to connect to your WiFi router.
  • Green indicates a successful connection.
  • Blue LED to show the Pushbullet notification was sent.

You can probably use this sketch with any of the ESP8266 variants and if you don't want the status LED then you could use a bare ESP-12 or even an ESP-01.

After the notification is sent I've tried to put the ESP to sleep to reduce the drain on the batteries but I'm getting some funny results so far, the current does reduce significantly but not as much as I would expect, more work required...
I expect to be home when a print finishes so the battery drain isn't too much of an issue and I think I'll look at taking power from the printer itself once I make the install more permanent.

I also thought that this could be used for all sorts of things like security monitoring etc. the message could be triggered from an input connected to a magnetic switch or a PIR possibly or connected into an existing security system to give you a notification on your mobile when triggered if I can get the power usage down it would make a good portable warning system.  Although I used Pushbullet because it's a convenient way to get in and out of your home network without exposing it, you could use other cloud solutions or just use it internally with Node-Red on a Raspberry Pi ?? 

#include esp8266wifi.h
#include wificlientsecure.h
 This Sketch posts a text message to you phone via Pushbullet indicating that my 3D Printer
 has finished printing, the message is triggered whenever the ESP8266 is powered up.
 The code runs in the setup not the loop so it will only run the once.
 The source for this code was found on forum under example sketches and was
 posted by DedeHai.
 The code uses an RGB LED on three outputs to indicate the status of the message:
 RED = Not connected to the WiFi
 Green = Connected to router
 Blue = Pushbullet note sent.
const char* ssid = "*******"; //Your WiFi SSID
const char* password = "**********"; //Your WiFi password
const char* host = "";
const int httpsPort = 443;
const char* PushBulletAPIKEY = "****************************"; //get it from your pushbullet account
const int REDLED = 15; //LED Pins
const int GREENLED = 12;
const int BLUELED = 13;
long t = 0; // timer count
// Use web browser to view and copy
// SHA1 fingerprint of the certificate
const char* fingerprint = "2C BC 06 10 0A E0 6E B0 9E 60 E5 96 BA 72 C5 63 93 23 54 B3"; //got it using
WiFiClientSecure client;
void setup() {
  pinMode(REDLED, OUTPUT);
  analogWrite(REDLED, 100);//No wifi connection
  analogWrite(GREENLED, 0);//No wifi connection
  analogWrite(BLUELED, 0);//No wifi connection
  Serial.print("connecting to ");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
  analogWrite(REDLED, 0);// wifi connection
  analogWrite(GREENLED, 50);//wifi connection

  Serial.println("WiFi connected");
  Serial.println("IP address: ");

  // Use WiFiClientSecure class to create TLS connection

  Serial.print("connecting to ");
  if (!client.connect(host, httpsPort)) {
    Serial.println("connection failed");
  if (client.verify(fingerprint, host)) {
    Serial.println("certificate matches");
  } else {
    Serial.println("certificate doesn't match");
  String url = "/v2/pushes";
  String messagebody = "{\"type\": \"note\", \"title\": \"3D Printer\", \"body\": \"3D Print Finished\"}\r\n";
  Serial.print("requesting URL: ");
  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.length()) + "\r\n\r\n");
  Serial.println("request sent");
  //print the response
  while (client.available() == 0);
  while (client.available()) {
    String line = client.readStringUntil('\n');
    analogWrite(GREENLED, 0);//Message answer recieved
    analogWrite(BLUELED, 100);//Message answer recieved
    t = millis();
    while (millis() <= t + 1000);
    analogWrite(BLUELED, 0);//Message answer recieved
void loop() {
More on the 3D printer later...


Mrbill said...

Very interesting. Did you post your completed sketch?

Gadjet said...

Thanks, No I didn't post the sketch, I'll do it tonight but you use the one from the link on the forum.

Mrbill said...

Check out WifiManager - it will let you 'productise' your ESP8266 so you don't have to hard-code ip addresses and SSID/passwords into your code.

Gadjet said...

Thanks for the link, interesting information.
I have added the sketch to the post.

Jure Korber said...

Hello Gadjet

Can I somehow get in contact with you? I need some info about your older post as I want to do something similar and instead of wasting my time discovering same things I rather ask for some hints and even give you something in return.

You can find me on FB: Jure Korber or mail jure _ zakon (at) hotmail . com

Best regards,

Hot water control using a Raspberry Pi Zero W

Following on from the first blog about the hot water heating control here's what I put together for the mounting. Whilst looking for a...

Popular Posts