The Telegram protocol can make light work of IoT applications, in just about any scenario - just as Alastair found out!
When Alastair bought a house that already integrated some cool technology, he found himself without any way to control it. So, like any good maker in such a situation, he decided to MAKE a solution, of course! The system he found installed was a powerful NuVo Whole Home Audio box, which is basically an intelligent controller to route multiple sources to multiple destinations - definitely something you’d want to make use of! So we caught up with Alastair to see how he put this awesome bit of hardware to use.
When you discover a high quality system is installed already, it certainly makes sense to use it. Do you have any experience with these types of systems, or was it an entirely new experience working with this hardware?
Several years ago I bought a house where the previous owner had obviously spent quite some effort installing a whole home audio system, which allowed up to six input sources (e.g., DVD, CD, tuner) to be routed to any of eight output areas (i.e., rooms, exterior and even garage/shed). When moving out he left the audio matrix router (a NuVo Grand Concerto) and all the speakers wired up, since it was probably more effort than worth it to remove it all. The previous owner controlled the system via a custom phone app, which was written in a way that was specific to his input sources since they were controlled via infrared transmitters. Of course, this owner took all of his input sources with him, and left no documentation or mechanism to control the system. The matrix router had no obvious control mechanism other than an RS-232 serial port, and there were no buttons on the chassis, no IR remote control, and no external keypads. So there it sat for several years, but it was always in the back of my mind to try and resurrect it. Some free time during the past holidays created the perfect opportunity to dig a bit deeper.
Ah, the proverbial “some day” project - we all have those! It’s definitely worth getting something like that working though. Re-facing the device with an open technology like Telegram is a fantastic idea, and it certainly makes things more simple. What’s your background that led you to having the skills required to get this idea going?
I have been tinkering with electronics since before high school in the 1980s, but I’m completely self-taught from a hardware and software perspective. My current job is entirely non-technical so this is all done as a hobby.
Like a true maker! Were you able to find documentation for the RS-232 interface on the NuVo system, or did it take some trial and error?
When Googling around for some documentation for the NuVo box, I was able to find the serial control protocol for it (see Digital Resources) and plugged my Macbook in via a USB->Serial adapter.
Using my favourite app for this type of thing (Roger Meier’s CoolTerm [Mac/Win/Linux] - see Digital Resources), I was able to establish communications with the NuVo for the first time! I was able to send commands to select which inputs went to which sources, and also control the volume. While it was great to confirm that the system technically worked, I needed to come up with a way to easily control it from anywhere in the house, and as such I had a few important requirements. These included:
- Easy use for anyone in the house.
- Wireless access with no additional cables or wiring to run.
- Able to work while being on the Guest network rather than the home network (as an aside, I have a separate SSID on my home WiFi network for my IOT devices/gadgets, which I feel is a good practice because it doesn’t expose my home network to these potentially less secure devices).
Sounds pretty straight forward! Especially with RS-232, it’s well standardised - at least, once you have the command set. Then you turned to Telegram for the IoT communication. The capabilities in Telegram seem to be well suited to this task (and many others we can think of). Are there any notable deficiencies in Telegram you’d like to mention, or anything you had to work around?
I felt that the solution would be best implemented with something like an Arduino-type device, which already has a built-in serial port. Of course, I needed one with WiFi connectivity to make it wirelessly controllable. Since the Arduino doesn’t natively talk RS-232 over its serial port, I needed a level shifter. I used a RS232 Click (see Digital Resources), which I had lying around from another project. These are really easy to use and work with 3.3V or 5V logic. On the Arduino side you just connect it up to either a hardware or software serial port. For the Arduino, I actually used an ESP8266-based board that I had lying around. It’s a cheap NodeMCU clone (see Digital Resources). Keep in mind that when using these ESP8266 boards, they only have two serial ports and one is transmit-only. You also need to find out which pin they are on.
Up until now, this is all pretty standard stuff - but to make an interface to wirelessly control it, I could have:
- Used a web front-end served from the ESP8266 - this wouldn’t have worked for me because I didn’t want the device on my main home network, so it would not have been reachable on the guest network from my main network (without complex firewall rules to maintain the separation I wanted).
- Used a cloud-service such as IFTTT - this wouldn’t have worked either, because it wouldn’t have allowed multiple users to interact with it.
- Use another solution - I had been following the Universal Arduino Telegram Bot project, which seemed like it would be perfect. I use Telegram as my primary instant messaging app, partially because of its very useful “bot” ecosystem. There are many other great reasons to use Telegram - but that would be its own article in and of itself!
The Universal Arduino Telegram Bot (UATB) offers an easy way to create bots on an Arduino. This solution ticks many boxes, such as:
- Doesn’t require the Arduino to be on the same network as the devices it is interacting with.
- Allows multiple users to interact with the bot.
- Secure - can easily decide who has access to the bot.
- Easy to use - the bot can interact with the user in “plain English” and can create simple custom keyboard interfaces.
- Responsive - there isn’t a big delay between a command and the response (although it is slower than a direct web connection to the Arduino).
- Flexible - all the logic is within the app and thus completely within the control of the person writing it.
- Easy to build - the UATB has excellent documentation, examples and an active community on Telegram itself.
- Multi-platform - Telegram is accessible on iOS, Android, Web and several fat clients.
- Cheap - There’s no cost to use Telegram, the bot or the bot library.
Putting all the pieces together (ESP8266 Board, RS232 Click and Telegram Bot) means that anyone interacting with the bot can direct any zone to have any source, at any volume level. These are done either via direct commands if you know them, or via prompts that the bot can send you with a custom keyboard.
The rough process is that the bot receives commands, translates them into commands that the NuVo can understand, and then pushes them out over the serial port.
Telegram is indeed very powerful, and we can see ourselves using it a lot more in the future for IoT comms. Does the Arduino provide feedback to the stream too, or is it effectively “read only”?
The Arduino code isn’t stateful, in that it doesn’t assume any particular state of the NuVo. The Arduino doesn’t know which zones are connected to which sources, and I don’t keep track of that info. With a two-way RS232 link I could easily do that, but so far there hasn’t been the need.
Yes it does sound somewhat redundant. After all, if it doesn’t work, you won’t see any change to the volume or source routing wherever you are in the house, so you effectively already have feedback! Is there anything about this setup that you would change, if you had to redo it all over again?
- Remove all the technical debt in the code - it’s quite messy and was largely written by spreadsheet.
- Add IR senders to the equation such as those that the previous owner left behind (https://www.globalcache.com/products/itach/ip2irspecs/). This would allow me to send commands to the sources (PLAY, PAUSE on the CD Player, for example). This isn’t a particularly high priority since most of the content is actually in digital form now, so the NuVo’s sources are mostly internet-connected music devices (e.g., Airport Express).
- Display information from the NuVo. The NuVo sends information back via the serial port which is easy to read with the Arduino, but because I’m not using any of the more sophisticated features of the NuVo (custom keypads in each room - which I don’t have and may not even be available anymore) there isn’t much there.
It sounds like it’s going to keep you busy for some time to come! What other exciting project are you working on?
I’ve been so happy with the Telegram interface that I’m going to make a home automation controller out of a Telegram bot, which will let me remotely do things (e.g., turn lights on/off, open/close garage, view CCTV images).
That sounds fun! We look forward to seeing your results in the future. Thanks for taking us through your Telegram-based NuVo controller, Alastair.