Dallas Temperature

Github Repo C Header C source JS source
mongoose-os-libs/arduino-dallas-temperature DallasTemperature.h   api_arduino_dallas_temp.js

begin

void begin(void);

initialise bus

getDeviceCount

uint8_t getDeviceCount(void);

returns the number of devices found on the bus

validAddress

bool validAddress(const uint8_t*);

returns true if address is valid

validFamily

bool validFamily(const uint8_t* deviceAddress);

returns true if address is of the family of sensors the lib supports.

getAddress

bool getAddress(uint8_t*, uint8_t);

finds an address at a given index on the bus

isConnected

bool isConnected(const uint8_t*);

attempt to determine if the device at the given address is connected to the bus

isConnected

bool isConnected(const uint8_t*, uint8_t*);

attempt to determine if the device at the given address is connected to the bus also allows for updating the read scratchpad

readScratchPad

bool readScratchPad(const uint8_t*, uint8_t*);

read device's scratchpad

writeScratchPad

void writeScratchPad(const uint8_t*, const uint8_t*);

write device's scratchpad

readPowerSupply

bool readPowerSupply(const uint8_t*);

read device's power requirements

getResolution

uint8_t getResolution();

get global resolution

setResolution

void setResolution(uint8_t);

set global resolution to 9, 10, 11, or 12 bits

getResolution

uint8_t getResolution(const uint8_t*);

returns the device resolution: 9, 10, 11, or 12 bits

setResolution

bool setResolution(const uint8_t*, uint8_t, bool skipGlobalBitResolutionCalculation = false);

set resolution of a device to 9, 10, 11, or 12 bits

setWaitForConversion

void setWaitForConversion(bool);
    bool getWaitForConversion(void);

sets/gets the waitForConversion flag

setCheckForConversion

void setCheckForConversion(bool);
    bool getCheckForConversion(void);

sets/gets the checkForConversion flag

requestTemperatures

void requestTemperatures(void);

sends command for all devices on the bus to perform a temperature conversion

requestTemperaturesByAddress

bool requestTemperaturesByAddress(const uint8_t*);

sends command for one device to perform a temperature conversion by address

requestTemperaturesByIndex

bool requestTemperaturesByIndex(uint8_t);

sends command for one device to perform a temperature conversion by index

getTemp

int16_t getTemp(const uint8_t*);

returns temperature raw value (12 bit integer of 1/128 degrees C)

getTempC

float getTempC(const uint8_t*);

returns temperature in degrees C

getTempF

float getTempF(const uint8_t*);

returns temperature in degrees F

getTempCByIndex

float getTempCByIndex(uint8_t);

Get temperature for device index (slow)

getTempFByIndex

float getTempFByIndex(uint8_t);

Get temperature for device index (slow)

isParasitePowerMode

bool isParasitePowerMode(void);

returns true if the bus requires parasite power

isConversionComplete

bool isConversionComplete(void);

Is a conversion complete on the wire?

setHighAlarmTemp

void setHighAlarmTemp(const uint8_t*, char);

sets the high alarm temperature for a device accepts a char. valid range is -55C - 125C

setLowAlarmTemp

void setLowAlarmTemp(const uint8_t*, char);

sets the low alarm temperature for a device accepts a char. valid range is -55C - 125C

getHighAlarmTemp

char getHighAlarmTemp(const uint8_t*);

returns a signed char with the current high alarm temperature for a device in the range -55C - 125C

getLowAlarmTemp

char getLowAlarmTemp(const uint8_t*);

returns a signed char with the current low alarm temperature for a device in the range -55C - 125C

resetAlarmSearch

void resetAlarmSearch(void);

resets internal variables used for the alarm search

alarmSearch

bool alarmSearch(uint8_t*);

search the wire for devices with active alarms

hasAlarm

bool hasAlarm(const uint8_t*);

returns true if ia specific device has an alarm

hasAlarm

bool hasAlarm(void);

returns true if any device is reporting an alarm on the bus

processAlarms

void processAlarms(void);

runs the alarm handler for all devices returned by alarmSearch()

setAlarmHandler

void setAlarmHandler(const AlarmHandler *);

sets the alarm handler

defaultAlarmHandler

static void defaultAlarmHandler(const uint8_t*);

The default alarm handler

setUserData

void setUserData(const uint8_t*, int16_t );
    void setUserDataByIndex(uint8_t, int16_t );
    int16_t getUserData(const uint8_t* );
    int16_t getUserDataByIndex(uint8_t );

if no alarm handler is used the two bytes can be used as user data example of such usage is an ID. note if device is not connected it will fail writing the data. note if address cannot be found no error will be reported. in short use carefully

toFahrenheit

static float toFahrenheit(float);

convert from Celsius to Fahrenheit

toCelsius

static float toCelsius(float);

convert from Fahrenheit to Celsius

rawToCelsius

static float rawToCelsius(int16_t);

convert from raw to Celsius

rawToFahrenheit

static float rawToFahrenheit(int16_t);

convert from raw to Fahrenheit

delete

void operator delete(void*);

delete memory reference

calculateTemperature

int16_t calculateTemperature(const uint8_t*, uint8_t*);

reads scratchpad and returns the raw temperature

JS API


DallasTemperature.create

DallasTemperature.create(ow)

Create and return an instance of the dallas temperature: an object with methods described below. ow is an OneWire instance.

Example:

let ow = OneWire(12 /* onewire pin number */);
let myDT = DallasTemperature.create(ow);

myDT.close

myDT.close()

Close DallasTemperature handle. Return value: none.

myDT.begin

myDT.begin()

Initialise the sensor. Return value: none.

myDT.getDeviceCount

myDT.getDeviceCount()

Return the number of devices found on the bus. If an operaiton is failed, 0 is returned.

myDT.validAddress

myDT.validAddress(addr)

Check if given onewire addr (8-byte string) is valid; returns 1 if it is, or 0 otherwise.

myDT.validFamily

myDT.validFamily(addr)

Return 1 if onewire address addr (8-byte string) is of the family of sensors the lib supports. Return always 0 if an operaiton failed.

myDT.getAddress

myDT.getAddress(addr, idx)

Find an onewire address at a given index idx on the bus. Resulting address is written into the provided string buffer addr, which should be 8 bytes lont. Return value: 1 in case of success, 0 otherwise. Example:

load("api_sys.js");
load("api_arduino_dallas_temp.js");

let addr = Sys._sbuf(8);
let res = myDT.getAddress(addr, 0);
if (res === 1) {
  print("found:", addr);
} else {
  print("not found");
}

myDT.isConnected

myDT.isConnected(addr)

Determine if the device at the given onewire address (8-byte string) is connected to the bus. Return value: 1 if device is connected, 0 otherwise.

myDT.isConnectedWithScratchPad

myDT.isConnectedWithScratchPad(addr, sp)

Determine if the device at the given onewire address (8-byte string) is connected to the bus, and if so, read the scratch pad to the provided buffer (9-byte string). Return value: 1 if device is connected (and a scratchpad is read), 0 otherwise. Example:

load("api_sys.js");
load("api_arduino_dallas_temp.js");

let sp = Sys._sbuf(9);
let res = myDT.isConnectedWithScratchPad("\x28\xff\x2b\x45\x4c\x04\x00\x10", sp);
if (res === 1) {
  print("connected, scratchpad:", sp);
} else {
  print("not connected");
}

myDT.readScratchPad

myDT.readScratchPad(addr, sp)

Read device's scratchpad. sp is a string buffer (minimum 9 bytes length) to read scratchpad into. Return 1 in case of success, 0 otherwise. Example:

load("api_sys.js");
load("api_arduino_dallas_temp.js");

let sp = Sys._sbuf(9);
let res = myDT.readScratchPad("\x28\xff\x2b\x45\x4c\x04\x00\x10", sp);
if (res === 1) {
  print("scratchpad:", sp);
} else {
  print("failed to read scratchpad");
}

myDT.writeScratchPad

myDT.writeScratchPad(addr, sp)

Write device's scratchpad sp (which should be a 9-byte string) by the provided onewire address addr (a 8-byte string). Return value: none.

myDT.readPowerSupply

myDT.readPowerSupply()

Read device's power requirements. Return 1 if device needs parasite power. Return always 0 if an operaiton failed.

myDT.getGlobalResolution

myDT.getGlobalResolution()

Get global resolution in bits. Return value: 9, 10, 11 or 12. In case of a failure, returns 0.

myDT.setGlobalResolution

myDT.setGlobalResolution(res)

Set global resolution res in bits, which can be either 9, 10, 11, or

  1. If given resolution is out of range, 9 bits is used. Return value: none.

    myDT.getResolution

myDT.getResolution(addr)

Get device's resolution in bits. Return value: 9, 10, 11 or 12. In case of a failure, returns 0.

myDT.setResolution

myDT.setResolution(addr, res, skip)

Set resolution of a device with onewire address addr to 9, 10, 11, or 12 bits. If given resolution is out of range, 9 bits is used. Return 1 in case of success, 0 otherwise.

myDT.setWaitForConversion

myDT.setWaitForConversion(waitForConversion)

Set/clear the waitForConversion flag. Return value: none.

myDT.getWaitForConversion

myDT.getWaitForConversion()

Get the value of the waitForConversion flag: either 1 or 0. In case of a failure, return 0.

myDT.setCheckForConversion

myDT.setCheckForConversion(checkForConversion)

Set/clear the checkForConversion flag.

myDT.getCheckForConversion

myDT.getCheckForConversion()

Get the value of the checkForConversion flag: either 1 or 0. In case of a failure, return 0.

myDT.requestTemperatures

myDT.requestTemperatures()

Send command for all devices on the bus to perform a temperature conversion.

Return value: 1 in case of success, 0 otherwise.

myDT.requestTemperaturesByAddress

myDT.requestTemperaturesByAddress(addr)

Send command to a device with the given onewire address addr to perform a temperature conversion.

Return value: 1 in case of success, 0 otherwise.

myDT.requestTemperaturesByIndex

myDT.requestTemperaturesByIndex(idx)

Send command to a device with the given index idx to perform a temperature conversion.

Return value: 1 in case of success, 0 otherwise.

myDT.getTemp

myDT.getTemp(addr)

Return raw temperature value (12 bit integer of 1/128 degrees C) or DallasTemperature.DEVICE_DISCONNECTED_RAW in case of a failure.

myDT.getTempC

myDT.getTempC(addr)

Returns temperature in degrees C or DallasTemperature.DEVICE_DISCONNECTED_C in case of a failure.

myDT.getTempF

myDT.getTempF(addr)

Returns temperature in degrees F or DallasTemperature.DEVICE_DISCONNECTED_F in case of a failure.

myDT.getTempCByIndex

myDT.getTempCByIndex(idx)

Get temperature from the device with the given index idx in degrees C, or DallasTemperature.DEVICE_DISCONNECTED_C in case of a failure.

myDT.getTempFByIndex

myDT.getTempFByIndex(idx)

Get temperature from the device with the given index idx in degrees F, or DallasTemperature.DEVICE_DISCONNECTED_F in case of a failure.

myDT.isParasitePowerMode

myDT.isParasitePowerMode()

Return 1 if the bus requires parasite power, 0 otherwise. In case of a failure return 0.

myDT.isConversionComplete

myDT.isConversionComplete()

Return whether a conversion is completed.

myDT.millisToWaitForConversion

myDT.millisToWaitForConversion(res)

Return number of milliseconds to wait until the conversion is completed for the given resolution res in bits (9, 10, 11 or 12). In case of a failure, return 0.

myDT.setHighAlarmTemp

myDT.setHighAlarmTemp(grc)

Set the upper alarm temperature (in degrees C) for a device; valid range for grc is from -55 to 125. Return value: none.

myDT.setLowAlarmTemp

myDT.setLowAlarmTemp()

Set the lower alarm temperature (in degrees C) for a device; valid range for grc is from -55 to 125. Return value: none.

myDT.getHighAlarmTemp

myDT.getHighAlarmTemp()

Return upper alarm temperature in degrees C (from -55 to 125), or DallasTemperature.DEVICE_DISCONNECTED_C in case of a failure.

myDT.getHighAlarmTemp

myDT.getHighAlarmTemp()

Return lower alarm temperature in degrees C (from -55 to 125), or DallasTemperature.DEVICE_DISCONNECTED_C in case of a failure.

myDT.alarmSearch

myDT.alarmSearch(addr)

Search the wire for devices with active alarms.

addr should be a string buffer of at least 8 bytes.

If the next device is found, 1 is returned and the device's address is written to addr; otherwise 0 is returned.

Use myDT.resetAlarmSearch() to start over. Example:

load("api_sys.js");
load("api_arduino_dallas_temp.js");

print("Looking for devices with active alarms...");
let addr = Sys._sbuf(8);
while (myDT.alarmSearch(addr) === 1) {
  print("Found:", addr);
}
print("Done.");

myDT.resetAlarmSearch

myDT.resetAlarmSearch()

Reset alarm search. Return value: none.

myDT.hasAlarm

myDT.hasAlarm(addr)

Return 1 if device with the given onewire address has active alarm; 0 otherwise. In case of a failure, 0 is returned.

myDT.hasAlarms

myDT.hasAlarms()

Return 1 if any device on the bus has active alarm; 0 otherwise. In case of a failure, 0 is returned.

myDT.toHexStr

myDT.toHexStr(addr)

Return device address addr in the hex format.

edit this doc