Friday, November 24, 2017

Adding TCP service checking to Node-Red

The following C program can be used with Node-Red to provide service indicators in a dashboard. Basically, it accepts two arguments: the IP address and the port number of the target system/service. It then attempts to connect to that IP and port and returns either the word "on" or the word "off". When run with Node-Reds timer and exec modules, it provides a dashboard status for each of the targeted services.

Save the following to "portcheck.c" and compile it by running "gcc -o portcheck portcheck.c"

  // Tim Kramer - 18 Nov 2017

  // adapted from Silver Moon's code at:
  // www.binarytides.com/tcp-connect-port-scanner-c-code-linux-sockets/

  // Purpose of this is to work with Node-Red in checking on services.
  // This determines if a specific port on a specific machine is open
  // and returns "on" if a port is open, or "off" if port is closed.

  // This will exit without two arguments
  // Syntax:  portcheck IP_ADDR PORT

  // Possible issue: takes a few seconds to timeout if target machine 
  // is offline

  #include <stdio.h>
  #include <sys/socket.h>
  #include <errno.h>
  #include <netdb.h>
  #include <string.h>
  #include <stdlib.h>

  int main(int argc, char **argv){

     //###############################################//
     // check if there are two arguments, exit if not //
     //###############################################//

     if(argc!=3) {
        printf("usage: portcheck IP PORT\n");
        exit(1);
     }

     //##################################//
     // declare variables and structures //
     //##################################//

     struct hostent *host;
     int err, i, sock;
     struct sockaddr_in sa;

     //######################//
     // set up the sa struct //
     //######################//

     strncpy((char*)&sa, "", sizeof sa);
     sa.sin_family = AF_INET;

     //######################################//
     // add the IP and port to the sa struct //
     //######################################//

     sa.sin_addr.s_addr = inet_addr(argv[1]);  
     sa.sin_port=htons(atoi(argv[2]));

     //#######################//
     // check the IP and port //
     //#######################//

     sock = socket(AF_INET, SOCK_STREAM, 0);
     if(socket < 0){
        exit(1);    
     }
     err = connect(sock, (struct sockaddr*)&sa, sizeof sa);

     //######################################################//
     // return "on" if port is open, "off" if port is closed //
     //######################################################//

     if (err < 0){
        printf("off");
     } else {
        printf("on");
     }

     close(sock);
     fflush(stdout);
     return 0;
  }

Thursday, November 9, 2017

Why MQTT use has increased, and why I'm hating on a certain ZWave IP owner

I ran across the this post during my daily perusal of tech news. It's both interesting and a bit limited, in that it only looks at protocol use and doesn't dig into why.

I believe that the "why" for the increased MQTT/MQTTS use is: hobbyists and developers. Tools like HomeAssistant and Node-Red have experienced a large growth in the home automation area. Both tools can use locally implemented protocols (Zigbee, ZWave, etc.) but tend to focus on use of MQTT for over-the-netwrok communications. Although they've been around for about 5 years, prices for Linux-based automation hubs, like Samsung's Artik boards, have decreased recently (mostly due to increases competition[1]). Couple this with free (for hobbyist) Internet-based MQTT(S) servers (list here) and it's easy to see why use of the protocol has expanded.

That's not to say that everything is sunshine and roses. Example: I have some reservations about Samsung's Artik series boards, it's mostly due to third party licensing for the Z-Wave interface. To explain, the Artik 5 board can be acquired for less than $100 and has interfaces for Wi-Fi, Bluetooth, Zigbee, and a few other not-so-popular wireless protocols. While the board does have a ZWave chipset, its use requires a separate purchase of firmware and a license from the intellectual property owner of the ZWave technology. The bad news is that said third party requires that you purchase a $1500 development kit, just to acquire the firmware. This greed effectively kills[2] just about every hobbyist-driven ZWave project and will likely create a market for alternative protocols and solutions.

In defense of the Artik 5 board, it's a nice piece of kit. Simply put, it's an ARM board that comes with the Fedora 22 distro[3] pre-installed. It has multiple antennas for the supported wireless technologies[4] and also has the ability to interface with Arduino boards. Of serious value is the USB-based serial interface (separate from the power supply connector) which allows for operating system access[5] without having the network configured.

For now, I'm stuck with working around the no-ZWave limitation by using getting automation software on the Artik 5 to talk to the same software running on a Raspberry Pi, which hosts a HUSBZB-1 dongle[6]. To tie in the opening of this post, such is achieved via use of Node-Red, using MQTT and/or MQTTS for over-the-network comms (rule of thumb: develop with MQTT, put into productions with MQTTS).

For anyone that wants to experiment with Samsung's offerings, I'd recommend the Artik 7 or 10 series boards. They come with a USB host interface (which the Artik 5 lacks) that allows for use of ZWave via the addition of a HUSBZB-1 or Anteon dongle. I'm also taking a look at using USB2IP, but such requires cross-compiling because the Artik 5 doesn't have enough storage to support installation of the tool chain needed to compile the code. In any case, it's not much of a shortcoming for me as I only have 3 ZWave outlets and 2 Zigbee bulbs. Moving off of ZWave, should I ever do it[7], will not be a major financial hit. I'll just continue experimenting with the other protocols.

Notes:

[1] Manufacturers have no one to blame but themselves. Being first out of the gate doesn't justify exorbitant pricing. That just leads to having your lunch eaten in the time it takes for an engineer to design a similar product (these days, it's down to weeks).
[2] I learned about the licensing problem after I'd received the Artik 5 board for my birthday.
[3] I've managed to update the board to both Fedora 24 and the current Fedora 25. I've also managed to run Ubuntu 16.04 LTS from the SD card. (Note: the Artik 5 board does not support installation of Ubuntu, though the Artik 7 and 10 does.)
[4] It also has an antenna jack for ZWave, should you ever get around to adding it.
[5] On Linux, the easiest method for accessing the serial interface amounts to: screen /dev/ttyUSB0 115200
[6] Both Node-Red and HomeAssistant also work with the ZWave interface provided by the RaZberry daughterboard.
[7] I originally used the SmartThing's hub, with a MQTT interface to control those but I didn't like the need to have Internet connectivity to control the lights. We live in an older (Internet-wise) neighborhood and connectivity can best be described as "intermittent during damp weather".

Friday, November 3, 2017

What was I reading in October 2017?

2017-10-01

- ntpd won't save you from one particular rogue bit

2017-10-05

- How SSH became port 22

2017-10-07

- alvarcarto/url-to-pdf-api - I need to experiment with this as I've been wanting an internal PrintFriendly-like service.
- WaveNet launches in the Google Assistant DeepMind - Another item on my list to try.
- An Update on Firefox Containers - ... and another...
- AWK for Multimedia - ... and another.

2017-10-15

- Steve Wozniak announces tech education platform Woz U
- Exploding Git Repositories - Discussion of an issue similar to zip bombs.

2017-10-19

- Falling through the KRACKs
- Dive into Deep Learning with 15 free online courses
- Practical public key cryptography
- Screen capture in Google Chrome - A possible partner for the url-to-pdf tool above?
- URG - A discussion of TCP.
- Everything You Wanted To Know About Blockchains - Part 1
- Vim After 15 Years
- Using cgroups to limit I/O

2017-10-21

- Researchers find that LastPass 2FA can become 1FA
- ssh_scan: A SSH configuration and policy scanner for Linux and UNIX server

2017-10-23

- An ode to pack: gzip’s forgotten decompressor
- Getting the Most out of Sqlite3 with Python
- Do you have the Learners Syndrome? - Uhm... I admit nothing, because I do get use out of what I learn. (Okay, maybe not the Japanese language lessons, but...)
- Unix is my IDE

2017-10-25

- The Uncanny Resurrection of Dungeons & Dragons
- SSH Escape Sequences (aka How to Kill Dead SSH Sessions) - Just when you think you know a tool... Guess it pays to reread man pages now and then.
- Remember that $86 million license plate scanner I replicated? I caught someone with it.
- Newfound Wormhole Allows Information to Escape Black Holes

2017-10-26

- Speech Recognition Is Not Solved - I'm not liking the author's argument because speech recognition only needs to be "good enough". Much of what he wants borders on AI (e.g., recognition of context).
- learnbyexample/Command-line-text-processing - Notes on processing text with awk.

2017-10-28

- SNMP Authentication Bypass Cripples Numerous Devices
- OpenSSH Removes SSHv1 Support

2017-10-29

- Secretary problem
- Outlawry Supervillians and Modern Law
- Replace your exploit-ridden firmware with a Linux kernel
- 10 charts that show why sleep is so important

2017-10-30

- Understanding deep learning requires re-thinking generalization
- Stop Feeling Like an Imposter

Above was generated by a homegrown bolt-on script for Wallabag, which is a free utility for capturing web content so that it can be read later.