For some time now I’d been wanting to look into the one wire interface, mainly for the temperature sensors. There seems to be a lot of experimentation and projects around using the Raspberry Pi, the Arduino and plenty of free software to enable home automation and to take readings, but I really wanted to play about with the code, in a Windows Environment, as part of a larger development project and also use my SQL Server skills. I’d also wanted to use this with my lab HP Microserver.
So let’s start! At the minimum for the hardware we’re going to need a host interface and a sensor with the connecting cables.
We’ll need the host interface and I sourced the DS9490R USB Host Adapter from Sheepwalk Electronics at http://www.sheepwalkelectronics.co.uk/product_info.php?cPath=22&products_id=29
We’ll also need a cable connecting the RJ11 to RJ45 http://www.sheepwalkelectronics.co.uk/product_info.php?cPath=26&products_id=35
We can that wrap all this code up nicely in a function returning a structure datatype and insert the returned information into our SQL Server Table. We would setup a timer in the application to run the polling every minute or so, but never more than every 15 seconds, not many environments change temperature that quickly.
In our table we would use a 64-bit integer to store the 1-wire unique ID, decimal(5,4) to store the temperature and a datetime2(7) to store the date time. Using small fixed data types like these is not only good practice its essential if we are using a limited version such as SQL Server express.