Friday, October 14, 2016

Wednesday, June 01, 2016

Converting unix epoch to datetime in streaming analytics

sample input:
    {
        "Key": "Dryer_Sensor",
        "State": "0.8",
        "Timestamp": "1464782405968",
        "Site": "Bir57",
        "EventProcessedUtcTime": "2016-06-01T13:24:49.4517020Z",
        "PartitionId": 0,
        "EventEnqueuedUtcTime": "2016-06-01T12:00:06.4520000Z",
        "IoTHub": {
            "MessageId": "7e6d0379d85046f295c0cdaeaabe25d8",
            "CorrelationId": null,
            "ConnectionDeviceId": "openhab",
            "ConnectionDeviceGenerationId": "635957210185596241",
            "EnqueuedTime": "0001-01-01T00:00:00.0000000",
            "StreamId": null
        }
   }

 query: DATEADD(millisecond, CAST([Timestamp] as bigint), '1970-01-01T00:00:00Z') as timeFromString

this will result in  '1970-01-03T07:09:18.032Z' which is wrong!

you can correct this by modifying the input so its strips the quotes from the epoch


    {
        "Key": "Dryer_Sensor",
        "State": "0.8",
        "Timestamp": "1464782405968",
        "epochtime": 1464782405968,
        "Site": "Bir57",
        "EventProcessedUtcTime": "2016-06-01T13:24:49.4517020Z",
        "PartitionId": 0,
        "EventEnqueuedUtcTime": "2016-06-01T12:00:06.4520000Z",
        "IoTHub": {
            "MessageId": "7e6d0379d85046f295c0cdaeaabe25d8",
            "CorrelationId": null,
            "ConnectionDeviceId": "openhab",
            "ConnectionDeviceGenerationId": "635957210185596241",
            "EnqueuedTime": "0001-01-01T00:00:00.0000000",
            "StreamId": null
        }
   }

and modifying the query so it omits the cast (where the bug resides):  DATEADD(millisecond, epochtime, '1970-01-01T00:00:00Z') as time

this will result in the expected result: 2016-06-01T12:00:05.968Z


Friday, April 08, 2016

Registering a device in Azure IoT Hub


Using Node.js

npm install -g iothub-explorer@latest
iothub-explorer <connection string> create MyDevice

source

Using Device Explorer

See: azure iot sdk on github

Friday, February 26, 2016

Installing Z-Wave Stick Gen 5 on Windows IoT Core


I am currently fiddling around with Windows 10 IoT Core on a raspberry Pi. I wanted to use Z-Wave to be able to control a Fibaro Wall Plug (http://www.fibaro.com/uk/the-fibaro-system/wall-plug)

But I could not find the Z-Stick that was on the supported hardware list of windows iot core

so I bought a Z-Wave Aeon Labs Z-Stick USB Controller - Gen5.

the following steps will explain how to get it working for windows iot core

Step 1
Download the drivers here: http://aeotec.com/z-wave-usb-stick/1358-z-wave-drivers.html

step 2
Connect to tou you raspberry e.g. \\freyr\c$\Data\Users\Administrator\Documents
and unzip and copy the drivers

step 3
connect using powershell

[freyr]: PS C:\Data\Users\Administrator\Documents>

freyr]: PS C:\Data\Users\Administrator\Documents> dir


    Directory: C:\Data\Users\Administrator\Documents


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        8/24/2015   8:34 PM           8424 uzb.cat
-a----        8/24/2015   8:34 PM            710 uzb.inf

[freyr]: PS C:\Data\Users\Administrator\Documents> devcon dp_add .\uzb.inf

....

Driver package 'oem0.inf' added.
[freyr]: PS C:\Data\Users\Administrator\Documents>

[freyr]: PS C:\Data\Users\Administrator\Documents> devcon status usb*

...

USB\VID_0658&PID_0200\5&3753427A&0&4
    Name: USB Serial Device
    Driver is running.

...