Node-Red IVR with Twilio

Twilio

A while back I posted about using Twilio and Node-Red to send/receive SMS messages. I was fiddling around with some older project stuff (uncompleted) earlier today and bounced into the IVR setup I had. Wondering if it was working I called it, and no it wasn’t. So I had to fix it. It took me a minute to come across all the related pages needed to get it working again so I decided to compile them here.

What is an IVR?

Well if you Google IVR you get: Interactive voice response (IVR) is a technology that allows a computer to interact with humans through the use of voice and DTMF tones input via keypad.

And that basically sums it up. It allows you the person, to call a computer and have the computer know what you want when pressing 1, or 5. Similar to a phone switching system but they are usually used to report some kind of information instead of route calls. IVRs basically cut out someones job once upon a time.

A better example is of a field technician calling an IVR system to read back what signals were received on the clients security system he just tested.

What we are doing here?

Were are going to get a basic IVR running on our Node-Red server to interact with and read back data or to activate/deactivate things over MQTT. If you would rather (and/or) use SMS to achieve kinda the same thing read here.

Prerequisites

 

The Flow!

the flow

Here is the glorious flow!

You will need to create a global and have its value set so the IVR can read it back (in this example).

Drop a line in the comments if you have a question.

 

What helped:

https://flows.nodered.org/node/node-red-node-twilio
old outdated flow https://flows.nodered.org/flow/637b5f6128a8d423503f
https://groups.google.com/d/topic/node-red/yAEx5k2UHJw/discussion


[{"id":"4868a284.66517c","type":"http response","z":"feaafa48.a34f88","name":"Send TwiML","x":870,"y":200,"wires":[]},{"id":"1444c0f8.9e1bff","type":"http in","z":"feaafa48.a34f88","name":"Incomming Twilio Call","url":"/twiliovoice","method":"post","upload":false,"swaggerDoc":"","x":316,"y":202,"wires":[["8cebf57a.769bc8","a77ee63.fbb7618"]]},{"id":"8cebf57a.769bc8","type":"function","z":"feaafa48.a34f88","name":"Process Call","func":"var twiml_response = \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"yes\\\"?> \\\n <Response> \\\n <Gather action=\\\"https://yourserver.com/twilioivr\\\" numDigits=\\\"1\\\"> \\\n <Say voice=\\\"woman\\\">Welcome to Node-Red. For power usage press 1. To ring the bell press 2. For anything else press 3</Say> \\\n </Gather> \\\n <Say voice=\\\"woman\\\">Sorry, I didn't get your response.</Say> \\\n </Response>\";\nmsg.payload = twiml_response;\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":200,"wires":[["4868a284.66517c","daf3c74e.9d90e8"]]},{"id":"2e446272.06064e","type":"http in","z":"feaafa48.a34f88","name":"IVR Data Call","url":"/twilioivr","method":"post","upload":false,"swaggerDoc":"","x":290,"y":280,"wires":[["f769d46d.3e7fc8","a306c4e8.68fd58"]]},{"id":"daf3c74e.9d90e8","type":"debug","z":"feaafa48.a34f88","name":"","active":true,"complete":false,"x":870,"y":280,"wires":[]},{"id":"f769d46d.3e7fc8","type":"debug","z":"feaafa48.a34f88","name":"","active":true,"complete":false,"x":630,"y":320,"wires":[]},{"id":"a77ee63.fbb7618","type":"debug","z":"feaafa48.a34f88","name":"","active":false,"console":false,"complete":"payload","x":630,"y":160,"wires":[]},{"id":"a306c4e8.68fd58","type":"function","z":"feaafa48.a34f88","name":"handleGather","func":"// Use 2 outputs, 2nd is for mqtt topic/payload combination\n// Could be useful to post other caller info to a topic\nvar mqttOut = null;\nvar responseMsg = \"\";\n\nvar name = \"wholehouse\";\nvar reading = context.global[name];\nvar digit = msg.payload.Digits;\nif( digit == \"1\" ) {\n var twiml_response = \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"yes\\\"?> \\\n <Response> \\\n <Say voice=\\\"woman\\\">Power usage is \" + reading + \"</Say> \\\n </Response>\";\n msg.payload = twiml_response;\n} else if( digit == \"2\" ) {\n\tmqttOut = {topic: \"bellduino/ring\", payload: \"ringmybell\" };\n var twiml_response = \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"yes\\\"?> \\\n <Response> \\\n <Say voice=\\\"woman\\\">Turing on the bell</Say> \\\n </Response>\";\n msg.payload = twiml_response;\n} else {\n\tresponseMsg = \"You pressed \" + digit;\n}\n\nreturn [msg, mqttOut];","outputs":"2","noerr":0,"x":640,"y":280,"wires":[["4868a284.66517c","daf3c74e.9d90e8"],["a023a81c.a3e318","442a4b04.0c3c64"]]},{"id":"413a0cf4.24b0e4","type":"globalGetSet","z":"feaafa48.a34f88","name":"Text Global","topic":"","context":"msg","variable":"payload","outContext":"global","outVar":"wholehouse","x":490,"y":380,"wires":[[]]},{"id":"390ea068.1c8f8","type":"inject","z":"feaafa48.a34f88","name":"","topic":"","payload":"42.1","payloadType":"num","repeat":"","crontab":"","once":true,"x":290,"y":380,"wires":[["413a0cf4.24b0e4"]]},{"id":"a023a81c.a3e318","type":"mqtt out","z":"feaafa48.a34f88","name":"","topic":"","qos":"","retain":"","broker":"bdbaaa3f.072c48","x":850,"y":400,"wires":[]},{"id":"442a4b04.0c3c64","type":"debug","z":"feaafa48.a34f88","name":"","active":true,"console":"false","complete":"true","x":850,"y":360,"wires":[]},{"id":"bdbaaa3f.072c48","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]

 

SEND IT.

The ATOM editor

ATOM Editor

When I ran with the unwashed (ms windows) I used notepad++, then I moved to sublime when I started using a mac. I had used it for several years, then I decided to look for alternatives one day. I can’t remember why I was unhappy with sublime. I tried Brackets, Komodo, Aptana Studio and a few others but they didn’t feel right. Then I found ATOM, and that felt right. Maybe because it was so similar to sublime, that’s probably it. But it is so much more. It has many plugins you can well, plugin. You can make it just like sublime (but its better), and that may help with the transition. Fuck notepad++ that shit is old news and windows only, and windows fucking sucks. ATOM is cross-platform. Even if I had to do it all over again I would choose mac or Linux over windows, except for gaming (I bought a PS4, yeah fuck xboxes too). That is the only thing you can do with windows that makes sense, but then it doesn’t even really make sense. Everything about windows is wrong but that’s for another story all together.

So, https://atom.io/.

READ THIS or at least skim through it https://www.shopify.com/partners/blog/best-atom-packages-2017.

One of the most helpful plugins I have found is atom-beautify which is the reason I decided to write this post. Because it was such a pain in the ass to get this running. But in the end it wasn’t. It was a ID10T issue. I didn’t understand what exactly it was supposed to do, exactly. But now I do and knowing is half the battle! What is a beautifier? Well it takes all that horribly formatted code and makes it all nice and pretty to work with and look at. Its so fucking helpful.

I had installed atom-beautify and its sub component php-cs-fixer. Upon opening a php file I received an error that php-cs-fixer could not be found. So it looks like I need to install it. Well the ATOM websites directions for installing php-cs-fixer on a mac are wrong. You need to visit FriendsOfPHP at Github. Those directions there do work.

I did a few things to try to get it to work, these are probably not the correct steps, but they got me there. In the end I am thinking one may be able to use the compose install and run with that, omitting the manual/curl install. Remember, I am on a mac (latest OS as of this writing).

I tried the composer install first.

But when I tried which php-cs-fixer I got nothing. Now I know I was using the wrong paths in hind-sight. If I were you I would try installing via composer then using the proper composer path in the settings. If that doesn’t work and you still get the error then you know you need to do the manual install as well. But I am thinking not.

Then I tried the homebrew, at first it was producing errors for read/write permissions on a folder. Persistence paid off and it eventually just installed without any errors. Go figure. But alas, doing which php-cs-fixer  produced nothing once again. So I tried the manual installation, as the others did not produce any positive results. From a terminal do this:

then:

Turns out this comment also explains the same thing on how to install it.

Then, just run which php-cs-fixer, and it should hopefully give you good news (a path). I copied that path, and pasted it in the config settings for atom-beautify and php-cs-fixer. But that also produced the same errors from atom-beautify/php-cs-fixer. Then I found this https://github.com/pfefferle/atom-php-cs-fixer/issues/31#issuecomment-239443397. In that picture lied my salvation. I was using the wrong path this whole time and didn’t know it. As soon as I changed the path for php-cs-fixer I was good to go. That path was:

/Users/yourusername/.composer/vendor/bin/php-cs-fixer

Also of note, no matter what I did I was not able to get php php-cs-fixer  to work, never. I saw it posted all over but it never worked for me. So I did get it working, but I still thought it wasn’t working. Because it wasn’t doing anything (or so I thought). I was running the beautifier on all kinds of pages and I didn’t see any code change, I would even remove all indents and nothing! What the fuck dude? So I tried some html pages, and some JavaScript files. Those all worked just fine. It was just the php pages that were not working. Well as it turns out it was working just not how I though it should, which it should. All of the files I have that are php are intermixed php with html, for websites. I rarely have pages that are pure php. Well this plugin doesn’t structure html, at all. Or even call to the html formatter, as I think it should. It just formats pure php. So if you change the page type to html and run the beautifier it works just fine. I was expecting it to restructure all the contents of the php file, not just the actual php code. My mistake.

TLDR; php-cs-fixer just formats/indents pure php code, not php code intermixed with another language like html.. Also you need to update php5.6 to 7+ and I would install php-cs-fixer via composer, check your paths.

View Post

I am not responsible for anything that you fuck up or that goes wrong. Take these steps at your own risk. You have been warned.

Creating a mini NES with a Raspberry Pi

Mini NES RetroPie
Mini NES RetroPie
Mini NES RetroPie

It all started with the Nintendo Classic craze. I had a friend that was rambling about one the other day. I mentioned that I could totally make him one but better because it would emulate more than just Nintendo. Enter RetroPie. I was looking at putting the bill of materials together and thinking of cases for the mini NES, then I realized why not just print one! So BAM and BAM.

 

https://www.thingiverse.com/thing:1887826 
then this https://www.thingiverse.com/thing:2011955 

Then this for giggles
https://www.thingiverse.com/thing:1710104

 

Here’s what we are doing

  1. Flashing RetroPie to an SD card for a Raspberry Pi
  2. Soldering header pins to the RUN pin holes on the RPi
  3. Soldering wires to some push buttons
  4. Soldering some wires to an LED
  5. 3D Printing a mini NES case for the RPi
  6. 3D Printing a bracket for the NES case
  7. Glueing push buttons, LED and bracket into the printed case
  8. Wiring the LED and buttons to the RPi
  9. Testing it all

 

Here’s what you need

  1. Raspberry Pi (save yourself a headache, get a RPi 3!)
  2. RPi power supply MINIMUM of 2.5A!
  3. SD card 8gb+ class 10
  4. HDMI cable
  5. USB keyboard
  6. Network cable (even though the RPi 3 has wifi you will at least need to do the initial wifi setup with a LAN connection)
  7. A 3D Printer to print the case and the bracket
  8. (2) push buttons
  9. (2) male header pins
  10. Super glue and hot glue
  11. (1) red LED
  12. (1) 100 ohm resistor
  13. (6) pieces of jumper wire with connections (you can cut some in half if long enough)

 

Whats Up

I will assume you have a network connection (non wifi) a USB keyboard a TV or Monitor or tv with an HDMI connection and that you have active internet. You will need to know how to solder, and be somewhat comfortable with a terminal and hopefully the Linux environment. I also assume you have and know how to use a 3D printer. I will also assume that you know and are comfortable with Raspberry Pies. Lots of ASSumptions.

This post is not designed as a how to install RetroPie but more of a how to get RetroPie installed and create the scripts for shutdown the Pi and lighting the LED, then you can follow the first install guide by RetroPie to get you going with the actual RetroPie software.

View Post

I am not responsible for any damage that may happen to you, your computer, or your Raspberry Pi etc. Take this adventure at your own risk.

The Leap of Faith

Leap of Faith

I am doing some work for a client that involves migrating a bunch of their old websites from one server to a new one. The old hosting/design company hasn’t been helpful or very professional at all. They’ve got a stick up their ass apparently, pissed off they lost business I guess. Have caused us some delays and a few issues. Anyways, I have to SSH into the servers no cPanel or anything of the sort, no phpMyadmin, they rock it old school. So I tarballed the site and download it. After doing the SQL and tarball dance I went to access the site and was presented with a bunch of depreciation errors. The errors were coming from wp-settings.php. Depreciated calls. The old servers were also using mySQL v5.3. Get with the times man.

The errors I were getting was  Parse error: syntax error, unexpected new (T_NEW) .

I did some Google-Fu and found this site http://codecaveme.de/blog/en/php-7-and-wordpress-how-to-fix-unexpected-new-t_new-error/. I had to go through and take out all the  &  in the code calls. After doing that the blog loaded.

WordPress v2! Holy WTF!? Why are they still operating on WP2??? Well the server they were on was also old as bones, Ubuntu 10. Great hosting company eh? After logging in to the admin section I was presented with a super super old admin interface. I should have taken a screenshot, damn it. So being that it was WP2 I decided fuck this, I am going to try to upgrade.

I went and clicked the WordPress upgrade button and bam! It worked. Holy shit. There were no problems. I did not however update any of the plugins or themes in use. I was not willing to risk that. I’m sure that would break something. So far all functionality of the site is fine, everything seems to work ok. I’ll comment back if something does go wrong or pop up. But for now upgrading from WP 2.8.4 to 4.8.1 is pretty straight forward. Who’da thought?

Oh, I also had to change the PHP version from 7 to 5.5, shit just wouldn’t run. I have not tried moving it back to PHP 7 since the upgrade.

My 3d Printer Toughts: Revisited

Thoughts

Updated: October 5th, 2017

I have a 3D printer, a Monoprice Maker Select v2.1. I have had this thing for a few months now and feel like I have gotten a pretty good hang of it. I can get some pretty nice looking prints out of this thing. So here are my rambling thoughts on 3D printers so far:

Get something entry level your first time around. Don’t go spending thousands of dollars on it, you won’t know what you are doing. You wont know the basics. I nabbed a Monoprice (Wanhao/Cocoon Create clone) Maker Select v2.1. It’s a great entry level printer and for a great price. Once you’ve got it all setup and tweaked it will produce great prints. But it did print pretty decent right out of the box. If I had to choose again I would have gotten the Creality CR-10, but purely for its build size. I have found that I would very much like to produce larger objects. Bigger than the build plate of the Maker Select can handle. The MS is 8″ x 8″ x 7″. The CR-10 is 12″ x 12″ x 15″!! But I have no regrets on getting the Maker Select.

Being that it is an entry level printer and a cheap one from China, it needs some help in the safety “I won’t burn your house down” department. Remember those stupid “hover” boards and the fires? Yeah. So buy a $10 MOSFET to offload the heatbed amperage from the printer board to the more powerful MOSFET. The traces on the printer board cannot handle the amps the bed requires and will eventually burn out. Some people have tried just swapping the plugs for a higher rated plug but thats just bypassing the issue, not fixing it. Don’t do the XT plug mod, it won’t solve the problem.

  • Wire up the and install the MOSFET immediately, there are tons of tutorials and YouTube videos for it, its pretty simple. Order the MOSFET and printer at the same time.
  • Level that bed, then level that bed. Then level the bed. Then level the bed. Seriously. This is THE most important step out of everything minus the MOSFET. If you are not level you WILL have issues of some kind.

Level the bed again! This WILL be the hardest thing you have to do. There are many methods to do this, find one that works for you. For me I use a single piece of paper. With a cold bed and a cold nozzle I will slide the paper between the nozzle and bed and loosen the bed screws until its a snug fit but still moves. Then when I heat up and print (I use a 0.2mm first layer) everything is rockin.

  • Make sure you’ve squared your printer. It did NOT come that way. https://www.youtube.com/watch?v=XaroNfMVE4M
  • Make sure all the scews are tight
  • Print some Z-axis levelers, and make sure they are level to the bed.
  • I would order at least (2) 5150 radial fans to replace the 40mm stock fans. They suck and are loud, prone to failure. Or upgrade to noctua ($$) fans as people suggest.
  • A lot of people replace the electronics box fan with a 120mm for air flow and noise.
  • Print some Z braces. AzzA’s Z-brace is pretty nice, thats what I went with. But now there are rear Z-brace kits. I’d rock one of those if I had to do it again. Check out “Z-brace yourself” on Thingiverse.
  • Get a glass bed. This is next on my list of upgrades as well as… I want those glass smooth first layer surfaces.
  • Ditch the thumbwheels on the build plate and print some new ones, use M3 nylon nuts. The stock ones vibrate lose over time and don’t hold.
  • Print a razor blade part scraper (and this), the default putty knife can damage the buildtak surface.
  • Print the cable chain relocation bracket and cable shroud for the extruder head.
  • Upgrade and install the MicroSwiss all metal hotend. No more PTFE tubes and I hear it prints so much better. This is next on my list of things to-do.
  • Get a few rolls of filament in different colors. Stock up. Its nice to have that perfect color needed for something whenever it pops up. Or when you feel like a certain color. Its nice. I use Inland and Hatchbox.
  • Get some good superglue for glueing prints together. I use Gorilla Glue Super Glue 10 second bond. Good stuff.
  • Get a Raspberry Pi 3 and run OctoPrint (OctoPi) on it for ease of use. No fucking with an SD card, and you get to monitor and control the printer from a browser or cellphone/tablet (TouchUI).
  • Get a camera for the RPi to take timelapses or see progress. I use a raspberry pi camera and this mount.
  • Use an app. I use Printoid (for Android) to monitor and control the printer from my phone and tablet. It is much better and way more responsive than using the TouchUI.
  • Have a ton of things lined up that you want to print, and they better not be fucking fidget spinners! You are gonna have the urge to keep that machine printing 24/7.
  • Build an enclosure for it. It prints so much better when enclosed. No air drafts from doors or vents to fudge up your print. Having it enclosed also greatly reduces the amount of dust that will build up on the printer.
  • Have some shit on hand for maintenance. Oil and lubes, heh. Got to lube them rods! I use oil on the rods and lithium grease on the screw rods (z axis).
  • Print belt tensioners. Ditch the springs and tension the belts. They are probably too loose already, think guitar string. Some people just use zip ties like stock, I like the tensioners.
  • Lower your jerk and acceleration settings, as well as your speed. Jerk and acceleration settings you can play with. Most people seem to cut them in half of the default. Setting accel to 800 and jerk to 8 or lower. Speed, I did drop to 40mm/s. I print slow. I find anything over 50mm/s causes visible problems in your prints. My first layer speed I always run 8-15mm/s. Depending on how intricate the design is. This speed gets me screw hole circles perfectly. Over 15mm/s and the filament doesn’t stick for small circles and such, maybe better luck with glass?
  • Print a bed cable relief.
  • Print some brackets to hold the printer in one spot.
  • Print a filament runout sensor.
  • I print PLA with a heated bed. Nozzle at 200-215C and the bed at 60-70C. I print directly on the Buildtak (black mat surface) and have zero adhesion issues (most of the time). I don’t use glue or hairspray or anything of the sort. Too fucking messy, and I find it unneeded. YMMV. But I do have issues here and there with edges curling on large prints.
  • Get some lighting for your printer. You are going to want some LED lights in your enclosure, or at least on the printer pointing at your print. Because I guarantee you are going to sit there and watch it print. Plus you need the light for the camera (either just to watch or for time lapses).
  • Print test cubes and heat temperature towers for every new roll of filament that you get. Every roll is different. I guess you should also measure the filament with some calipers to make sure its 1.75mm (adjust in your slicer if not).
  • Get yourself some good fucking calipers!! You WILL need these. To check measurements on test cubes and such to make sure your printer is calibrated correctly. And to help you out when designing and making your own prints (the fun stuff!!).
  • Hot glue doesn’t stick well to printed parts, it does and doesn’t.

I’m sure there is more but thats what I have noticed so far.