Hey Group,
This question was attached to another thread that I started, but I decided it needed its own topic in the “Device” category.
So I have been working with the example 1-wire code found here…
http://electricimp.com/docs/resources/onewire/
In the second part of the tutorial the code is changed to discover multiple attached 1-wire sensors. But the code does not (for me anyway) make it easy to act on each of the discovered sensors individually.
I would greatly appreciate assistance in modifying the code to assign each “found” sensors value to a variable that I can later test for value and act on or send specific values to the agent or to the server.log
The scenario is that I may have several temperature sensors (ds18b20’s) but only want to send the value of a specific sensor in an email or the value of a different sensor to the server.log or sound a local alarm when another sensors value exceeds a threshold.
Therefore from my perspective (experience in BASIC language only) I need to be able to test the value of a chosen sensor and to do that I need a way to name each found sensor. or is there a better way to do it??
It would be sufficient if each found sensors current value was simply assigned to ow1, ow2, ow3, etc, then I could easily act on a given sensors value.
`
foreach (device, slave_id in slaves)
{
// Run through the list of discovered slave devices, getting the temperature
// if a given device is of the correct family number: 0x28 for BS18B20
if (slave_id[7] == 0x28)
{
one_wire_reset();
// Issue 1-Wire MATCH ROM command (0x55) to select device by ID
one_wire_write_byte(0x55);
// Write out the 64-bit ID from the array's eight bytes
for (local i = 7 ; i >= 0; i--)
{
one_wire_write_byte(slave_id[i]);
}
// Issue the DS18B20's READ SCRATCHPAD command (0xBE) to get temperature
one_wire_write_byte(0xBE);
// Read the temperature value from the sensor's RAM
temp_LSB = one_wire_read_byte();
temp_MSB = one_wire_read_byte();
// Signal that we don't need any more data by resetting the bus
one_wire_reset();
// Calculate the temperature from LSB and MSB
temp_celsius = ((temp_MSB * 256) + temp_LSB) / 16.0;
server.log(format("Device: %02d Family: %02x Serial: %02x%02x%02x%02x%02x%02x Temp: %3.2f", (device + 1), slave_id[7], slave_id[1], slave_id[2], slave_id[3], slave_id[4], slave_id[5], slave_id[6], temp_celsius));
}
}
`
Guidance, direction, code snippets, any form of enlightenment, all appreciated.
This squirrel is a real challenge for a newbie
thanks in advance.
dwight