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 ESP8266.com 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 ??
Sketch
#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 www.esp8266.com 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 = "api.pushbullet.com"; 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 https://www.grc.com/fingerprints.htm WiFiClientSecure client; void setup() { pinMode(GREENLED, OUTPUT); pinMode(BLUELED, OUTPUT); pinMode(REDLED, OUTPUT); analogWrite(REDLED, 100);//No wifi connection analogWrite(GREENLED, 0);//No wifi connection analogWrite(BLUELED, 0);//No wifi connection Serial.begin(115200); Serial.println(); Serial.print("connecting to "); Serial.println(ssid); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } analogWrite(REDLED, 0);// wifi connection analogWrite(GREENLED, 50);//wifi connection Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); // Use WiFiClientSecure class to create TLS connection Serial.print("connecting to "); Serial.println(host); if (!client.connect(host, httpsPort)) { Serial.println("connection failed"); return; } 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: "); Serial.println(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"); client.print(messagebody); Serial.println("request sent"); //print the response while (client.available() == 0); while (client.available()) { String line = client.readStringUntil('\n'); Serial.println(line); analogWrite(GREENLED, 0);//Message answer recieved analogWrite(BLUELED, 100);//Message answer recieved t = millis(); while (millis() <= t + 1000); yield(); analogWrite(BLUELED, 0);//Message answer recieved } ESP.deepSleep(60000000); } void loop() { }More on the 3D printer later...
5 comments:
Very interesting. Did you post your completed sketch?
Thanks, No I didn't post the sketch, I'll do it tonight but you use the one from the link on the forum.
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.
http://tzapu.com/esp8266-wifi-connection-manager-library-arduino-ide/
Thanks for the link, interesting information.
I have added the sketch to the post.
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
Thanks!
Best regards,
Jure
Post a Comment