Retrieving my IP address Remotely

Retrieving my IP address Remotely

I posted a few years ago about using Twilio and Node-Red to send/receive SMS messages. Using that flow you gain the ability to text your server and have it read back values. Any values you want, as long as you have them stored as a global some where along the way. If you haven’t already done it toss $20 on an account at Twilio for a year and get to it, its so worth it! Here I am going to add a new reading to my setup.

There are occasions when I need to access my home network when I am, well, not home. Everyone screams use a VPN! Yeah, of course, I have one, and I use it. But my problem is I have a dynamic WAN IP and I am not paying for a static IP. It doesn’t change very often but it always seems to when I need to use it the most. Step in Node-Red and Twilio. With both of those at my disposal I can now send a text message to my home server and have it respond with my WAN IP address. I can then modify my VPN settings on my phone or whatever if needed. Fucking fantastic! I had been using Twilio/NR for sensor readings and alerts but I had never thought about using it to report my IP. Theres a few ways to do this.

Lets grab our IP (the flow)

(This flow grabs the WAN IP via an exec node)

First we use an inject node and set it to fire off once on start, this grabs the IP first thing and makes sure we have some data to work with. Then we move off to an execute node. We are gonna execute some command line code and echo it back, then we’ll save it in a file and as a global. This goes in the exec node:

wget -qO- http://bot.whatismyipaddress.com/ ; echo

This goes out to whatismyipaddress.com and echoes back our IP, simple and very fast. There are a few other sites that can be used also. Ifconfig.io and ipinfo.io both are alternative sites (you just have to change the truncation from 5 to 6 characters to drop the return sign in the following function node).

Alternatively, and preferably we can use an HTTP node instead of an exec node. What? Yeah I just found this out.

(This flow grabs the IP via an HTTP node)

That will get you your WAN IP quickly via an HTTP node formats it then saves it to a file. We have to comment out the substring trimming command if we use the HTTP node over the exec node. Ok no problem. Don’t forget.

After we grab the IP we need to format it and save it as a global for Twilio (and Alexa!).

This will trim the returned output from the website to 6 characters, dropping off anything extra. It also saves our trimmed value as a global. Then we slap on a debug node and a file node to save the IP to a file for later use. You don’t have to save the IP to a file, I just like to in the even the server is restarted/power loss.

Thats it! Once the IP has been picked up and set as a global you are good to go (as long as you followed the other flow for Twilio I posted previously).

 

It figures…

After typing this up and saving the draft I decided to update NPM/nodejs/Node-Red. Upon updating I came across a Node-Red node, node-red-contrib-ip.

A simple install via Palette Manager (which doesn’t work for me) or manually installed via npm install node-red-contrib-ip and you’re good. The node works simply, nothing to configure. Add an inject node to trigger it and it spits out your machines IPv4 and IPv6 address and well as your WAN IP address. Just have to format the data the way you want and boom. I did notice it is slow, painfully slow. It doesn’t need to be lightning quick but it is noticeable compared to the wget option above. Choose your weapon, either method works. Heres the flow for using the IP node.

(This flow grabs the WAN IP via the node red IP node)

After the IP node put a function node and fill it with this code

This drops all the other node info and just gives us the WAN IP. Easy as pie.

 

Lets get notified

So far we check our IP every 12hrs and write it to a file and a global for use. Thats great, we can take it one step further. Want to get a notification when the IP does change? Lets go.

(This flow grabs the IP via an HTTP node and checks if it has been updated, then sends a notification if it has)

  • Inject and repeat every 24hrs at a set time
  • Read the stored IP address by reading the file
  • Get the current IP address and set it as a global
  • Cross check to see if the new IP matches the old IP and save it to a file if it is newer.
  • Format the message payload and send a notification (however you like, pushbullet, email, Twilio etc)

 

Check out this site, its where I got the notifications from https://steve.zazeski.com/get-a-notification-when-your-wan-ip-changes/.

Custom Alexa Node-Red Skill (revisited)

alexa-nodered

Finally! I am surprised it didn’t even take as long as it usually does for me to figure shit out. Took a few weeks. As usual, I did not come up with the solution on my own but found it out on the web and slapped it all together. I wanted a custom Alexa Node-Red skill, to be able to take a command given to Alexa and have it read back data from one of my sensors. Things like temperature sensors, water level, etc. I wanted to be able to ask Alexa what the values are. What I got: exactly what I wanted. It all works. There is two parts to this: the Node-Red flow and the Alexa skill.

Alexa Node-Red flow
Alexa Node-Red flow

First off, to get any of this working you must have your Node-Red server accessible from the outside world. That means port-forwarding, DNS, domains, SSL, all that. It’s fun getting it all working. Not. Just like my previous post, I happened to have it already setup. Once your Node-Red install is available from the web you are good to go. Now you don’t need the entire NR setup opened up either. I just allowed a few NR served pages to be available. Not the entire NR itself.

Update: I made a new post about Node-Red behind a reverse-proxy/SSL

Let’s Begin

It starts with a regular HTTP node to a switch node. That switch node splits up Alexa’s requests to NR; LaunchRequest, IntentRequest, SessionEndedRequest. LaunchRequest gets invoked when the skill starts. You could have Alexa say “Hello what do you want?” for example. IntentRequest is the goods. Then theres SessionEndedRequest, I’m assuming this gets called at the end. Haven’t toyed with it. Then you pass those requests off to do other stuff, like the DoCommand where it grabs your intent. Then a function node to extract the commands, which gets passed off to another switch node to split up the possible commands you can give Alexa. Give her as many commands as you want, then there is a “device doesn’t exist” at the bottom. This is used if she didn’t hear you right or the device doesn’t exist. All that data gets passed to a template to format what Alexa will say and sticks the data in JSON. Bam! That wasn’t so hard right?

Here’s the whole flow (all standard nodes used):

That’s the Node-Red half. You are not done yet. On to the Alexa skills half. This part is easy don’t worry. Login to your Amazon Dashboard and click Alexa. Choose “Get Started” with the Alexa Skills Kit, click add a new skill. Under Skill Information give it a name and choose the invocation word, what you will say to Alexa to start your skill. I chose “Node Red”, so I have to say “Alexa, ask Node Red….”. These can be changed at any time it seems. You won’t be publishing this skill, it stays beta for only you to use. For the Global Fields section, no you will not be using an audio player. Well, maybe you will but I didn’t, and it will probably change things for you.

Note about the flow: The NR flow works (for me) just fine however I noticed it throws an error in the debug tab whenever a command is called. If it is an unrecognized command response it doesn’t throw the error though. It complains about headers already being sent. I will update the flow if I find a fix for it.

Interaction Model

Intent Schema

Intent Schema

This is the part of the Alexa skill where you tell it what to do. It is pretty straight forward. Just copy this to your “Intent Schema”. There are no custom slot types and no values to enter.

Sample Utterances

Sample Utterances

This is where you list the invocation phrases that will activate Alexa. Normally (and in other online tutorials for Alexa skills) this is where you add a ton of different phrases. But we are not. Node-Red is going to handle that side for us. This box just gets one line of text.

Configuration

Global Fields/Endpoint

For a service endpoint you are going to pick “HTTPS”. In a lot of other tutorials you will usually choose AWS Lambda but we are doing all of our own heavy lifting with NR. We don’t need no stinking Lambda. Choose your closest location and enter the URL that your Node-Red is accessible from (via the web remember). Say no to account linking and you can also leave Permissions alone.

SSL Certificate

Certificate for Endpoint

Choose the option that bests describes you. Most likely it will be the first option. For me I am using a subdomain that is already SSL’d with Let’s Encrypt so I choose the second option.

Test

Basically just leave the toggle flipped to enable the skill for you to use. you don’t need to do anything else on this page.

Publishing Information

Nothing to do here, you won’t be publishing this skill. Why? Because it requires too much setup on the users behalf. I don’t think Amazon would approve a half functioning skill that requires advanced user setup to get working. You could always try. Good luck.

Privacy & Compliance

Three no’s and one box to check, I mean as long as it all applies to you right 😉

Done

That should be it. With Node-Red available to the web and the flow implemented the new Alexa skill you just made you should be good to go. I hope you found this useful, I sure wish I had found a blog post like this. Now go test it out with your Amazon Echo/Dot!

At the time of this writing a beta product appeared in the Amazon Dashboard for a the “Skill Builder”, looks to be a new UI for building Alexa skills. If this gets implemented for everyone in the future things may be different than they are described in this blog post.

 

Revisited

Originally posted April 26, 2017 @ 17:56

I decided to come back to this post. I was adding and modifying some things on my flow and I was using this post as a reference and decided it was not cutting the mustard, it felt unfinished. So here we are.

The above section contains the main flow you will need and it steps you through the Amazon Developer side of things that needs to be setup. Once that is all finished you should have a working flow with Alexa responding accordingly. What I feel I left out was how to configure the flow itself. Many of you may already have figured it out or can see whats going on and thats cool. Heres for the ones that need the help (myself included).

The flow

Voice requests
Request (your questions)
Question function
Question function (global request)
Alexas response
Alexas verbal response

HTTP node

The first node in the flow is the HTTP request. This is the page you will use to point your reverse proxy to. This is the page that Node-Red will server, that Amazon/Alexa will look for. This page needs to be accessible from outside your network.

Request Type

This contains the types of requests we can send to Alexa. We are only worried about IntentRequest  right now. Play with the other later.

Intents & Extract Commands

There is no need to modify these nodes. They contain the code needed to send requests.

Request

Add your verbal question here. Add it how Alexa hears it. This may take a little trial and error depending on how you talk and how she hears you. Sometimes you can simply put exactly what you are going to say in there, like “garage temperature” works fine for me but if I ask Alexa what the outside temperature is she doesn’t know and I get the unrecognized question response. But this is ok, pay attention to the output of the unrecognized responses. It will spit out what Alexa heard and how she heard it. So when I ask what the outside temperature is she hears “i outside temperature” for some unknown reason. So if I modify my request to be the same, and it works.

Function node

This function is very simple. It just grabs the global variable name you put in it. So when I ask for the “garage temperature” it looks for the global I have specified, in this case contex.global.garagetemperature. Add whatever global you want. Just make sure it is initialized first (has some data to report).

Formatting Alexas response

This template node contains the information for Alexas verbal reply. Once the basic structure is there all you do is edit the “text” to the response you want to receive, in plain english. She will respond with “exactly” what you type in there.

JSON & HTTP Response

Move along, noting to see here. The data gets formatted as JSON and the HTTP node completes the whole flow.

Done.

 

There you go. I feel better now. I at least explained WTF is going on here rather than dumping the flow on you and walking away. Sorry about that. Now you can run off and play with Alexa and Node-Red to your hearts content. The only thing I have noticed with the whole flow is that after Alexa responds Node-Red throws an error in the debug log. It all works 100% and works well but it always sends this error, and I haven’t figured it out. But I also haven’t been looking for it. Just a little FYI.

"Error: Can't set headers after they are sent."

 

This is where I found the goodness, buried deep in comments on a (awesome) blog.

Wanhao Maker Select v2.1 Firmware Upgrade

Wanhao Maker Select v2.1 Firmware Upgrade

It has been a while since my last post, I have not been fiddling with “blinking lights” for a little while now. I got a dog and life just happens. But I have felt the itch lately and decided to jump into some shit tonight – upgrading the firmware on my Wanhao Maker Select v2.1! There are no actual guides that I have found to be able to follow to flash the firmware (for this particular make/model). All of the information is out there but it seems to be mostly on Reddit and it is scattered across a few posts. Most of what I have found links to two guides; a YouTube video of how to flash the bootloader to the Melzi board, and an Instructables on how to do the same thing. That is basically all you really need but it came off as confusing to me so I am sure it will to someone else as well.

Basically what you need to do is a 2-step process. 1) Flash a bootloader to the Melzi board, and then 2) Flash the actual firmware to the Melzi board. You WILL NEED an Arduino of some sorts, any Arduino should do. I used a Duemilanove and it worked, and that thing is old. You will also need six (6) jumper wires (male to female most likely). You need to connect the wires from the Melzi board to the Arduino so you will also need to take the control box apart. You only need access to the Melzi board to flash the bootloader. Once the bootloader is flashed you can pack it all back up. The firmware is flashed via the Melzi’s USB port. So lets get to it!

Your Arduino IDE should be up to date and you will need the Sanguino board installed as well as the U8glib library (There is a different/older version linked to in the YouTube video, 1.14).

  1. Take the control box apart, I left the Melzi board in the can, you don’t need to fully remove it, less you want to. You just need access to the pins and the LCD.
  2. Put the auto-reset jumper on if you have it removed.
  3. Change the board power selector from VREG (AC) to USB, this lets us power the Melzi from the Arduino.
  4. Unplug the LCD (it will mess up the bootloader flashing process I have read, no harm in removing it temporarily. I also had issues until I unplugged the heatbed MOSFET also).
  5. Connect the wires from the Arduino to the Melzi.
  6. Connect the Arduino to the PC/Mac.
  7. Flash the Arduino to be used as an ISP.Open the example: ArduinoISP
    I had to add a line to get the flashing process to work, this may be due to the old Duemilanove I am using.
    I had to add #define USE_OLD_STYLE_WIRINGBoard: Your Arduino type Port: Your correct Arduino port Then click upload
  8. Now flash the bootloader (after you change the board settings).Board: Sanguino Port: Your same Arduino port Programmer: Arduino as ISP Then click Tools > Burn Bootloader
  9. Remove the Arduino from the PC/Mac, and remove the wiring from the Arduino to the Melzi. The Arduino is no longer needed.
  10. Place the jumper back on VREG not USB.
  11. Plug the LCD back in.
  12. Put all your crap back together (or leave it apart to make sure it all works!).
  13. Plug AC power back in.
  14. Plug the Melzi into the PC/Mac (change the board settings again).Board: Sanguino Port: the port of the Melzi board Programmer: AVRISP mkII Flash/upload the new firmware
  15. Print something!

Thats the whole process. The part everyone leaves out is how to flash the firmware, even though it is dead simple as plugging in a USB cord it is never mentioned. Something also never mentioned is how to configure Marlin to work on the Maker Select. The default Marlin is too large to fit, some things must be removed. I have not found a guide on how to configure it and or what to configure. But I did find a pre-set Marlin configured already for the Maker Select. This is what I am using. You have a few choices as far as I know; Marlin, Repetier and TH3Ds Marlin.

Update: Something I feel I didn’t make clear was flashing/updating the firmware. Step 14 above is the flashing part. Flashing the firmware the first time (after your bootloader is installed) is the same as flashing the firmware with future updates to your printer. With the printer in normal running condition, turn on the AC power. Connect your printer with the Arduino IDE open to your printer. Maker sure the board selected is Sanguino and the port is the port of the Melzi board that appears with the programmer: AVRISP mkII. Then with Marlin.ino open (or whatever firmware you’re using) select upload (or verify first to make sure it will compile). The firmware should upload and you should be good.

I chose the Marlin firmware preconfigured for the Maker Select v2. But I ran into an issue with the LCD screen being garbled. I also believe this is just a general Marlin firmware issue with Maker Selects and not just this specific version. But no fear! I found the fix online!

You need to edit a file in Marlin.ino, specifically ultralcd_st7920_u8glib_rrd.h around line 86 add the 2 NOP, this will fix the garbled LCD:
(You only need to do this if you LCD screen is garbled after flashing Marlin!)

This is the Reddit that I kept coming across: https://www.reddit.com/r/3Dprinting/comments/8o3wg8/installing_marlin_on_maker_select_v2/
This is the video on flashing the bootloader that seems to be popular: https://www.youtube.com/watch?v=ejpSniiJejI
This is the Instructable that shows the same thing as the YouTube video: http://www.instructables.com/id/Using-an-Arduino-to-Flash-the-Melzi-Board-Wanhao-I/
This is where I found the LCD fix: https://www.reddit.com/r/3Dprinting/comments/9i0n6z/maker_select_v2_lcd_issues/

Link to Sanguino board
Link to the U8glib library
Link to the preconfigured Marlin 1.1.x for the Maker Select v2.1

Some useful Thomas Sanladerer videos I found after I did my upgrade 🙁
Configuring thermal runaway
How to setup Marlin firmware

This was how I did it on my printer, I take no responsibility for anything that may happen to yours. Try this at your own risk.

Wanhao/Monoprice Y-carriage and heatbed upgrade

Upgrade

So I made the jump and upgraded a bunch of shit. I did it for smoother bottom first layer prints (because of the glass) and hopefully no more curling issues. I upgraded to the “Anycubic Ultrabase 3D Printer Platform with Aluminum 12V/24V Dual Power MK3 Heatbed” and while I was at it I upgraded to the Gulfcoast Robotics Y-axis carriage too, as I have read it is wise to do both at the same time and the stock bed plate is usually warped from posts I come across constantly. In fact I went a step further and bought new 40mm and 80mm Noctua fans for the printer too! Happy upgrade day!

I am going to use the 40mm to replace the stock 40mm extruder cooling fan and the 80mm to replace the control box fan(s). I printed a new backplate for the printer. I dug through Thingiverse for a bit and chose one that looked like it had a following and worked well. After printing it I realized I should have maybe dug a little more, it was not easy to install. In fact I didn’t install all of the screws back on because I cannot get an allen wrench in there to do it. But it does the job, and man are those Noctua fans fucking quiet!! If it is sitting idle I cannot tell it is on, it is in my living room. I hear if you upgrade to TMC2130 drivers (with a RAMPS board) then it is this quiet while printing too. Damn!.

I decided to write this up real quick because when I searched for relative content I found shit on it. Searches for Anycubic turns up their printers, so searching for the bed/covering/plate was a pain in the ass. All I found was this. I ended up figuring it out as it’s not that hard but if i was able to read something on it first I probably would have saved my ass about 3-4 hours of head scratching.

View Post

Problems with Micro Swiss All Metal Hotend (Wanhao I3)

Micro Swiss All Metal Hotend

If you follow the blog you know I have a 3D printer, a Monoprice Maker Select v2.1 to be exact. Over the holidays I received the Micro Swiss All Metal Hotend Conversion Kit for the Wanhao I3, I got the one with the slotted cooling block, which I’ve seen recommended. The original cooling block uses a set-screw against the thermal barrier tube. The slotted block doesn’t use a set-screw instead it is slotted and you clamp the tube in place. Much better heat transfer.

I watched a few videos, read and followed all the directions, as well as I follow a few groups for 3D printing on Facebook (tons of useful info there!) and I have seen tips here and there. But I ran into problems with my install and could not find the information I needed anywhere. I even asked the groups and no useful answers really. As I said I followed all the directions and my issue came in to place with the 1.7mm of space you are supposed to leave sticking out at the top of the cooling block. I did this (a lot of videos they just eyeball it) and this turned out to be my problem.

When I first tried to assembled it all back together the custom lever plate I had printed and was using would not fit. The thermal barrier tube was sticking up too far. I use a printed lever bracket for the extruder. This bracket allows me to print flexible filament (which I have not yet). The stock plate leaves a gap that the filament can squish through, I have switched to this a while back. The bottom of the plate is flush on the custom one. The stock plate there is a rise, about 1.7mm it looks like.

I initially thought simply this plate wasn’t compatible and was going to just find another. So I installed the original plate instead. (After writing this post and searching for the links to accompany it I discovered there is a Micro Swiss version of the back plate that I was using. This will sit flush with the 1.7mm rise the instructions say to leave, but this still would not have solved my leveling or screw hitting problem.)

But that didn’t work everything was way too far away from the heat-bed. I tried to re-level but I could not get close enough. Also, the cooling fan I use was now hitting the bed screws that stick up slightly (all more reason to recess the screws!). Something was off and didn’t fit right.

At my wit’s end and feeling frustrated I took a break and left for the day. I came back later that night to hit at it again. This time I started wondering about the aluminum lever plate Micro Swiss sells and what the bottom looked like. Is it flush or does it have a rise and require the 1.7mm extra?

 

I Googled around and looked at images and it turns out the machined lever plate they sell is flush, just like my custom plate I was using. So I decided to forgo the instructions and remove the 1.7mm rise and make it flush so the plate will sit on it. Fifteen minutes later after reinstallation (for the 3rd time) and I was printing. After making the tube flush the plate now fits, my bed now levels and the cooling fan no longer hits the bed screws. So fuck the instructions, they caused me grief and didn’t work.

Not sure if this is a one-off install or if this is standard for using a flexible filament plate or the machined Micro Swiss plate.

 

TLDR; The original instructions say to leave 1.7mm of the thermal barrier tube sticking out of the cooling block. This will only work if you are using the stock extruder lever plate that came with the printer. If you are using the machined lever plate from Micro Swiss or a custom printed flexible filament plate from Thingiverse you may need to forgo the instructions and make the thermal barrier tube flush with the top of the cooling block. Read above for more details.

This may just be a one-off install YMMV.