Ibutton ID example

Ibutton ID example

 

Ibutton ID example
#include <io> #include <read> #include <float> #include <string> #include <core> #include <write> #include <define> #include <socket> new str_temp[10]; new ibutton_low; new ibutton_high; forward public callback (event); public callback (event) { switch(event) { case IBUTTON_ID: { ibutton_parse(); } } return 0; } ibutton_parse() { ibutton_low = get_val(SENSOR_IBUTTON_ID, Bit64_low); ibutton_high = get_val(SENSOR_IBUTTON_ID, Bit64_high); set_val(SENSOR_IBUTTON_ID, 0, Bit64_low); set_val(SENSOR_IBUTTON_ID, 0, Bit64_high); } main() { Init(RS232, 9600, WORDLENGTH_8, STOPBITS_1, PARITY_NONE); // Baud rate: 9600, Word length: 8bit, Stop bit: 1, Parity: none Init(IBUTTON_ID); while(1) { if(get_val(SENSOR_IBUTTON_PRESENT) == 1) { idL = get_val(SENSOR_IBUTTON_ID, Bit64_low); // Read Ibutton_ID lowest 32bit from 64bit (0x00000000FFFFFFFF) idH = get_val(SENSOR_IBUTTON_ID, Bit64_high); // Read Ibutton_ID highest 32bit from 64bit (0xFFFFFFFF00000000) snprintf(str_temp, 6, "%i", idL); // Convert to string write_buf(RS232, strlen(str_temp), str_temp); // Print string via RS232 write_buf(RS232, 1, "1"); snprintf(str_temp, 6, "%i", idH); // Convert to string write_buf(RS232, strlen(str_temp), str_temp); // Print string via RS232 write_buf(RS232, 2, "\r\n"); // Print new line MQTT_PublishSensor(SENSOR_IBUTTON_ID); // Publish sensor to server set_val(SENSOR_IBUTTON_ID, 0, Bit64_low); // Set Ibbuton_ID lowest 32bits to 0 set_val(SENSOR_IBUTTON_ID, 0, Bit64_high); // Set Ibbuton_ID highest 32bits to 0 } Delay(500); // 500ms delay } }