Issue #011 [Fixed/closed] - Add OneWire support (Patch attached)

Posted by stuartmarsden

ENHANCEMENT - Patch against Rev 605

Really like webiopi. I am planning to use it as the basis of a swimming pool control server. To do this I am using a Dallas 1-Wire temperature sensor. I decided I might as well add 1-Wire functionality to webiopi if I have to write it anyway.

The patch is based on the w1-gpio module. The first thing it does is detect if the module is loaded and if so turns GPIO pin 4 into ALT mode to stop it being used. It adds at the bottom of the table a list of all detected 1-Wire devices and lets you read from them. The raw data is displayed or by checkbox can have the temperature extracted.

I have updated the RESTAPI docs to show what you can do. 1-Wire can be enabled or disabled which loads or unloads the w1-gpio module. A list of devices can be requested and then the data for a deviceId can be taken. This is easily manipulated by Javascript like extracting the temperature.

The webiopi main page will show the 1-wire devices below the GPIOs only when it is enabled. The list is updated dynamically so new devices will appear when they have been connected with no user intervention. They will also be removed when disconnected.

I only have one device so have only tested with that but it should work with many. It will only work with devices that give data in the w1_slave file. It does not support writing to devices but it could be added easily.

Hope it is useful to others. Any comments welcome.

Files attached

Comment 1

Posted by trouch

Will be added later at the same time as SPI, I2C

Comment 2

Posted by trouch

Comment 3

Posted by trouch

In progress, but I don't have any 1-Wire device to make some test... is the w1-temp module mandatory for RAW and generic 1-Wire communication ? I mean, is the device detected if you only load w1-gpio module ?

Comment 4

Posted by stuartmarsden

The device will still show up without the w1-temp module but it will not give any data. This is for 1 wire temp sensors. Which is all I have. I imagine that other devices may need other modules.

Comment 5

Posted by trouch

Okay... thanks for feedback I think I'll need to hand on some 1-wire devices... I've designed something generic that suits UART, I2C and SPI, and I'd like to use the same approach for 1-wire

Comment 6

Posted by stuartmarsden

I will be happy to test against my one wire devices if you have a test build. I might even get a few more types of one wire devices on eBay (they don't cost much).

Comment 7

Posted by trouch

For sure, but I will not be able to buy all devices. What devices do you have ?

Comment 8

Posted by trouch

Good find :

Comment 9

Posted by trouch

DS18B20 samples received and tested. I first checked differences with and without w1-therm, then looked in w1* modules sources. Getting a raw access to the 1-wire interface seems to be hard from Python and use w1-therm is certainly the best choice. So I need to adapt my current design to load extra modules keeping a generalization for OneWire bus that will just load w1-gpio. Adding other 1-wire device family like IO expander will then be easier.

Comment 10

Posted by trouch

working in r817, closes this issue. only device listing is missing from the patch, it will be added as a more generic device listing to get all kinds of devices.

Comment 11

Posted by stuartmarsden

Travelling at the moment so cannot try for a few days. Was looking at the code but cannot figure out where the onewire bit is. You have done a big refactor so maybe I am looking in the wrong place. Or is it possible you forgot to add the onewire file to version control? Thanks for adding onewire, I look forward to trying it.

Comment 12

Posted by trouch

oops, you totally right, i missed to add before commiting others changes. now fixed. you have to go in devices/, for the starting point, wich then use classes in

Comment 13

Posted by sebastienbarrau

Sorry, but how do i use the patch ? is there a command to apply it ?