Posted by & filed under article.

If you are new to working with USB serial devices and are about to setup OpenHAB2 and configure your new Z-Stick, then you are the target audience of this post. Being new both to OpenHAB2 and USB serial devices I found it quite frustrating to configure the Z-Wave controller with OpenHAB2.

 

The first thing you need to know, by plugging the USB Z-Stick into a computer with a Linux operating system running will assign cause the USB to be assigned a port. When the Z-Stick is plugged inn try running:

ll /dev/ttyACM*

The wildcard is needed as the Z-Stick might be assigned to /dev/ttyACM0, /dev/ttyACM1 etc..

Okay, so this is how you locate the serial port the Z-Stick acquired, move over to OpenHAB2 and paperui. Navigate to add-ons and install the Z-Wave Binding.

paperui-bindings-zwave

When the Z-Wave Binding is install, navigate to Configurations -> Things and edit the Z-Wave Serial Controller. The only thing you need to configure is the serial port as found earlier.

configure-wave-serial-controller

 

Aight! Almost done. OpenHAB2 is configured, but is currently not allowed to read the USB port. You could quickly test it by doing a chmod 666 on the serial port, but dont do that. Instead edit the /etc/default/openhab2 file and add EXTRA_JAVA_OPTS=-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0.

# openHAB 2 service configuration
#
# Additional options for the JAVA_OPTS environment variable.
# These will be appended to the execution of the openHAB Java runtime in front of all other options.
#
# A couple of independent examples:
#   EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyAMA0"
#   EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0:/dev/ttyS0:/dev/ttyS2:/dev/ttyACM0:/dev/ttyAMA0"
#   EXTRA_JAVA_OPTS="-Djna.library.path=/lib/arm-linux-gnueabihf/ -Duser.timezone=Europe/Berlin -Dgnu.io.rxtx.SerialPorts=/dev/ttyS0"

# The ports openHAB will bind its HTTP/HTTPS web server to.
#OPENHAB_HTTP_PORT=8080
#OPENHAB_HTTPS_PORT=8443

EXTRA_JAVA_OPTS=-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0

Add openhab to dialout and tty.

sudo adduser openhab dialout
sudo adduser openhab tty

Now restart OpenHAB2 with “sudo service openhab2 restart” and you should see the Z-Stick Serial Controller come online.

Walk the extra mile

Yeah, I know… So much configuration when does it stop?! Well there is one more thing you can do. As I mentioned in the beginning you cant be sure that the serial port will change after a restart or if you re-plug the Z-Stick. There is a way you can fix this and that’s with the udev rules. You should checkout this site for a deeper understanding http://www.domoticz.com/wiki/PersistentUSBDevices

However, this is the short version for the “Aeotec Z-Stick Gen5”.

Create a new rules file.

sudo nano /etc/udev/rules.d/usb-serial.rules

Create a new entry

SUBSYSTEM=="tty", ATTRS{idVendor}=="0658", ATTRS{idProduct}=="0200", SYMLINK+="ttyUSB-ZWAVE"

I have already found the idVendor and idProduct for Aeotec Z-Stick Gen5. Now reboot and the Z-Stick will be accessible via the symlink /dev/ttyUSB-WAVE.

ttyUSB-ZWAVE

Remember to update /etc/default/openhab2 and the Z-Wave Serial Controller with the symlink and you should be set.

Hope you found this helpful as I spent a lot of unnecessary time to figure out these concepts.

Posted by & filed under article.

Every morning I open the Buypass desktop app and enter my personal pin. In return I get a passcode (that I cant copy) so I need to type it into Check Point Endpoint Security in order to logon to the network. Security wise this is great, however too tiresome. Therefore the idea of automating the process came to life! A quick view of the results in action can be viewed in the video below.

Technical approach

By starting the Buypass process from the C# application, the process handle for Buypass is return to the application.

process = Process.Start(processPath);

Proceeding to start the process as defined by the processPath, that when properly configured will point to the Buypass executable file. We have no way of knowing precisely when the Buypass application is ready, however some cleaver guy on stackoverflow checks for a non-zero window handler to confirm the application is fully loaded.

isFormRdy = (process.MainWindowHandle != IntPtr.Zero);

Since we cant know excactly how long time the application will require before fully loaded, a timer is started to poll the process and to check if the window handle is not null with a interval of 500ms. Now knowing when the Buypass application is loaded and ready to receive the pin as input, I use the System.Windows.Forms.SendKeys function to type the personal pin. It’s therefore critical that no other application steels the input focus at this point or else it will for instance write out the personal pin into Word if Word was selected right after Buypass is fully loaded. Followed by the pin, the SendKey function is used to send the enter keypress.

SendKeys.SendWait(privatePin);
SendKeys.SendWait("{ENTER}");

At this point Buypass will generate what I assume to be an image of the passcode. Before proceeding to grab a screenshot of the passcode, I pass the window handle from the process and a referenced variable to the User32 API GetWindowRect.

[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hwnd, ref Rect rectangle);

// Get the possition of the form.
IntPtr ptr = process.MainWindowHandle;
Rect pRect = new Rect();
GetWindowRect(ptr, ref pRect);

Now knowing the position of the Buypass application, its possible to target the passcode area with some offsets so that a screenshot is grabbed of the passcode and only the passcode. Reducing the noise drastically compared to running OCR on the whole screen.

Further I assume from the network traffic that Buypass produces, a network call to a server is issued in order to verify the client with the provided pin. Dealing with network we cant be exactly sure when the passcode is available. For instance if there is a network lag, a screen capture might occur before the passcode is available. Since we cant be certain, a recursive retry function is used to retry the screen capture and process OCR up to five times with a delay of one second.

Log("OCR returned: " + word.Text);
if(word.Text.Length >= 5) {
  Clipboard.SetText(word.Text);
  Log("Password copied to clipboard.");
} else {
  Thread.Sleep(1000);
  Log("OCR not accepted. Retrying... " + retry);
  CaptureScreen(rect, retry - 1);
}

To accept the OCR results, it needs to return a string containing at least 5 characters. Finally returning the password to the Clipboard.

Also, if the application is started with the argument -run, it will start the process of opening Buypass and grabbing the passcode, before exiting Buypass and Byepass leaving a clean exit!

 

The project is available on GitHub: https://github.com/Olavz/byepass

Please leave a comment if you found this interesting or if you would like to suggest improvements.

Cheers

Posted by & filed under article.

JavaZone 2015 is just around the corner and here is my picks so far. Some slots are still empty and TBD while other slots are double booked. Might just need to decide a couple of minutes before the talks start and let my guts decide.

 

Wednesday 9/9

Thursday 10/9

Posted by & filed under article.

 

Here the other day I tried Chrome without any extensions. A clean Chrome without any customization. It made me realize how important the extensions have become and that the extensions added make the browser. I have listed my installed Chrome extensions bellow hoping other developers will be inspired to get them as well, if not already have them installed.

Leisure Extensions

Development Extensions

Misc Extensions

These extensions fulfill my browser experience. Other suggestions on extensions I should be using is gladly appreciated.

Cheers

Posted by & filed under article.

Woah!!! I created a inefficient but working 3D printer in Minecraft. The 3D printer is built with the ComputerCraft mod. The turtles within the mod are blocks that looks like small or big computers depending one you Minecraft perspective. The turtles are controlled by LUA scripts with a comprehensive API to control the turtle.

The 3D printing script is hosted on pastebin for your convinience, http://pastebin.com/7Uukwe9b

To install it to your turtle, type pastebin get 7Uukwe9b printer

The first editor for creating instructions to the 3D printer is located online here, http://hosting.olavz.com/minecraft/editorr/

It its currently limited to a 2D view and by adding layers, you are working your way upwards along the Y axis. Remember to add layer before you try to export. Copy the exported data and create a new paste on pastebin.com. After you submitted the data to pastebin, look at the last ending characters in the url. Example: http://pastebin.com/5uzbb6P0

Going back to the turtle you install the 3D printer as printer.

Type printer <pastebin code>

Example: printer 5uzbb6P0

Turtle slots
Slot 1: Fuel
Slot 2: Resource
Slot 5: Ender chest with fuel
Slot 6: Ender chest with resources

 

In addition to the 2D view editor. Morgan Sandbæk is working on a 3D editor with import/export capabilities so the two editors can be used in a combined effort. The 3D editor is still in development, however I will leave you with a teaser.

3d editor unity

Cheers