From 627df20e53d30f4266a08147e5fa4a9dedb49320 Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Mon, 21 Jan 2019 20:14:09 -0500 Subject: [PATCH 1/6] Squashed commit of the following: commit a4632bb7ad684a5587f313bd25304609d7c66e16 Author: A.M. Rowsell Date: Mon Jan 21 20:13:12 2019 -0500 Sanitizing key and wifi Signed-off-by: A.M. Rowsell commit 5e3be0f5615d55d76ec1a09cd919add82cb21bdf Author: A.M. Rowsell Date: Mon Jan 21 19:53:42 2019 -0500 It's alive! New code all working. The OneWire library works. It's a bit hacked together, as neither the software timer or hardware timer APIs would have worked well, because they are implemented terribly by Espressif. The easiest way to get around this was to just use system_get_time() and work off of that for timing in one-wire comms. Split the publish function into two separate functions: one to publish floating point numbers, and one to publish integers. In a language like Lua or C++ you could have these as one function, but in C it's easier to just split them. The main.c has a new function called dataLog that deals with getting the DS18B20 data and then handing that off to pubfloat(). I updated the timer names to be more descriptive. I grabbed some code to convert integers and floats to strings, as I can't be bothered to write that code myself for the millionth time. If something goes wrong and we are disconnected from our TCP connection, all timers are halted so we don't blindly keep trying to send packets over a non-existent link. Unfortunately the onewire library is hardcoded to use pin 5. That will be the next update. Signed-off-by: A.M. Rowsell commit 48702bf3288cc7f9646617baf057173d609fb2c7 Author: A.M. Rowsell Date: Sun Jan 20 21:13:04 2019 -0500 First version that compiles with new file layout. Had to make many changes to get it to compile across many files, including removing the LOCAL specifier from almost all functions. Edited the Makefile to compile all three files and link them. Haven't tested on hardware yet, that's the next step. Lots of small changes to avoid warnings, now that I have turned -Wall on. This makes the code a bit "better". Signed-off-by: A.M. Rowsell commit 1cd81916822aae46332569951381706f20869910 Author: A.M. Rowsell Date: Sat Jan 19 15:25:44 2019 -0500 New branch for my new AIO key. Will have to remember to sanitize before committing to master. Signed-off-by: A.M. Rowsell Signed-off-by: A.M. Rowsell --- Makefile | 12 ++--- main.c | 135 +++++++++++++++++++++++++++++++++++----------------- main.h | 14 ++++-- mqtt.c | 112 ++++++++++++++++++++++++++++++++++++++----- mqtt.h | 21 ++++---- onewire.c | 109 ++++++++++++++++++++++++++++++++++-------- onewire.h | 16 +++---- strtoarr.py | 4 +- 8 files changed, 317 insertions(+), 106 deletions(-) diff --git a/Makefile b/Makefile index be6a43f..4d82140 100644 --- a/Makefile +++ b/Makefile @@ -2,14 +2,14 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -P=mqtt +P=main CC=xtensa-lx106-elf-gcc AR=xtensa-lx106-elf-ar LDLIBS=-nostdlib -ggdb -Wl,-Map=output.map -Wl,--start-group -lm -lc -lhal -lpp -llwip -lphy -lnet80211 -lwpa -lat -lwpa2 -lmain -Wl,--end-group -lgcc -CFLAGS= -I. -mlongcalls -std=gnu11 +CFLAGS= -I. -mlongcalls -std=gnu11 -Wall LDFLAGS=-Teagle.app.v6.ld -OBJ=mqtt.o -DEPS=mqtt.h +OBJ=main.o mqtt.o onewire.o +DEPS=main.h mqtt.h onewire.h $(P)-0x00000.bin: $(P) esptool.py elf2image $^ @@ -19,10 +19,10 @@ $(P): $(OBJ) %.o: %.c $(DEPS) flash: $(P)-0x00000.bin - esptool.py --port /dev/feather1 write_flash 0 $(P)-0x00000.bin 0x10000 $(P)-0x10000.bin + esptool.py --port /dev/feather0 write_flash 0 $(P)-0x00000.bin 0x10000 $(P)-0x10000.bin clean: - rm -f $(P) $(P).o $(P)-0x00000.bin $(P)-0x10000.bin + rm -f $(P) $(OBJ) $(P)-0x00000.bin $(P)-0x10000.bin *~ library: $(CC) -c -fPIC $(CFLAGS) $(P).c -o $(P).o diff --git a/main.c b/main.c index b544ebe..9d96351 100644 --- a/main.c +++ b/main.c @@ -1,37 +1,62 @@ +#include +#include "user_interface.h" +#include "ets_sys.h" +#include "os_type.h" +#include "osapi.h" +#include "mem.h" #include "espconn.h" -#include "main.h" #include "mqtt.h" #include "onewire.h" +#include "main.h" +os_timer_t tcpTimer; +os_timer_t pingTimer; +os_timer_t pubTimer; LOCAL void ICACHE_FLASH_ATTR con(void *arg) { os_printf("Entered con!\n"); mqtt_session_t *pSession = (mqtt_session_t *)arg; mqtt_send(pSession, NULL, 0, MQTT_MSG_TYPE_CONNECT); - os_timer_disarm(&oneTimer); - os_timer_setfn(&oneTimer, (os_timer_func_t *)sub, arg); - os_timer_arm(&oneTimer, 200, 0); + os_timer_disarm(&pingTimer); + os_timer_setfn(&pingTimer, (os_timer_func_t *)ping, arg); + os_timer_arm(&pingTimer, 1000, 0); } -LOCAL void ICACHE_FLASH_ATTR pub(void *arg) { - os_printf("Entered pub!\n"); +LOCAL void ICACHE_FLASH_ATTR pubuint(void *arg) { + os_printf("Entered pubuint!\n"); mqtt_session_t *pSession = (mqtt_session_t *)arg; - uint8_t data[] = "2.718281828459045"; - uint32_t dataLen = os_strlen(data); - mqtt_send(pSession, &data[0], dataLen, MQTT_MSG_TYPE_PUBLISH); - os_timer_disarm(&oneTimer); - os_timer_setfn(&oneTimer, (os_timer_func_t *)ping, arg); - os_timer_arm(&oneTimer, 200, 0); + uint8_t *data = (uint8_t *)(pSession->userData); + char *dataStr = os_zalloc(20 * sizeof(char)); + intToStr(*data, dataStr, 4); + int32_t dataLen = os_strlen(dataStr); + mqtt_send(pSession, (uint8_t *)dataStr, dataLen, MQTT_MSG_TYPE_PUBLISH); + os_timer_disarm(&pingTimer); + os_timer_setfn(&pingTimer, (os_timer_func_t *)ping, arg); + os_timer_arm(&pingTimer, 1000, 0); +} + +LOCAL void ICACHE_FLASH_ATTR pubfloat(void *arg) { + os_printf("Entered pubfloat!\n"); + mqtt_session_t *pSession = (mqtt_session_t *)arg; + float *data = (float *)(pSession->userData); + char *dataStr = os_zalloc(20 * sizeof(char)); + ftoa(*data, dataStr, 2); + int32_t dataLen = os_strlen(dataStr); + os_printf("Encoded string: %s\tString length: %d\n", dataStr, dataLen); + mqtt_send(pSession, (uint8_t *)dataStr, dataLen, MQTT_MSG_TYPE_PUBLISH); + os_timer_disarm(&pingTimer); + os_timer_setfn(&pingTimer, (os_timer_func_t *)ping, arg); + os_timer_arm(&pingTimer, 1000, 0); } LOCAL void ICACHE_FLASH_ATTR ping(void *arg) { os_printf("Entered ping!\n"); mqtt_session_t *pSession = (mqtt_session_t *)arg; mqtt_send(pSession, NULL, 0, MQTT_MSG_TYPE_PINGREQ); - os_timer_disarm(&oneTimer); - os_timer_setfn(&oneTimer, (os_timer_func_t *)sub, arg); - os_timer_arm(&oneTimer, 200, 0); + os_timer_disarm(&pingTimer); + os_timer_setfn(&pingTimer, (os_timer_func_t *)ping, arg); + os_timer_arm(&pingTimer, 1000, 0); } LOCAL void ICACHE_FLASH_ATTR sub(void *arg) { @@ -45,58 +70,80 @@ LOCAL void ICACHE_FLASH_ATTR discon(void *arg) { os_printf("Entered discon!\n"); mqtt_session_t *pSession = (mqtt_session_t *)arg; mqtt_send(pSession, NULL, 0, MQTT_MSG_TYPE_DISCONNECT); - os_timer_disarm(&oneTimer); + os_timer_disarm(&pingTimer); +} + +LOCAL void ICACHE_FLASH_ATTR dataLog(void *arg) { + mqtt_session_t *pSession = (mqtt_session_t *)arg; + oneWire_t DS18; + oneWire_t *pDS18 = &DS18; + uint16_t temp = 0; + sint32 time = 0; + pDS18->temperature = 0; + reset(); + transact(pDS18, SKIP_ROM); + transact(pDS18, CONVERT_T); + time = system_get_time() + 750000; + while(system_get_time() < time); + reset(); + transact(pDS18, SKIP_ROM); + transact(pDS18, SCRATCH_READ); + //os_printf("\nReceived onewire data: %x %x\n", pDS18->scratchpad[0], pDS18->scratchpad[1]); + temp = ((uint16_t)pDS18->scratchpad[1] << 8) | pDS18->scratchpad[0]; + pDS18->temperature += (temp >> 4) + ((temp & 0x0F) * 0.0625); + pSession->userData = (void *)&pDS18->temperature; + os_printf("\nTemperature is: %d.%02d\n", (int)pDS18->temperature, (int)(pDS18->temperature * 100) % 100); + pubfloat(pSession); // publish the temperature + } void ICACHE_FLASH_ATTR user_init() { - uint8_t wifiStatus; + //uint8_t wifiStatus; LOCAL mqtt_session_t globalSession; LOCAL mqtt_session_t *pGlobalSession = &globalSession; char ssid[32] = "yourwifissid"; - char passkey[64] = "yourwifipassword"; + char passkey[64] = "yourwifipass"; struct station_config stationConf; gpio_init(); // init gpio so we can use the LED + uart_div_modify(0, UART_CLK_FREQ / 115200); // set UART to 115200 wifi_status_led_install(0, PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0); // set GPIO0 as status LED stationConf.bssid_set = 0; os_memcpy(&stationConf.ssid, ssid, 32); // copy the ssid and passkey into the station_config struct os_memcpy(&stationConf.password, passkey, 64); wifi_set_opmode_current(0x01); //station mode wifi_station_set_config_current(&stationConf); // tell it about our config, this auto-connects us as well - // prepare the TCP/MQTT connection stuff // Adafruit IO is at 52.5.238.97 - - static const char testUser[11] = { 0x4d, 0x72, 0x41, 0x75, 0x72, 0x65, 0x6c, 0x69, 0x75, 0x73, 0x52 }; - static const uint8_t testUser_len = 11; - static const char testPass[32] = { 0x63, 0x61, 0x62, 0x31, 0x39, 0x36, 0x36, 0x34, 0x31, 0x66, 0x33, 0x63, 0x34, 0x34, 0x36, 0x32, 0x61, 0x35, 0x30, 0x39, 0x64, 0x62, 0x64, 0x31, 0x34, 0x61, 0x30, 0x61, 0x66, 0x36, 0x64, 0x32 }; - static const uint8_t testPass_len = 32; - //static const char testPass[4] = { 0x74, 0x65, 0x73, 0x74 }; - //static const uint8_t testPass_len = 4; - static const char testTopic[37] = { 0x4d, 0x72, 0x41, 0x75, 0x72, 0x65, 0x6c, 0x69, 0x75, 0x73, 0x52, 0x2f, 0x66, 0x65, 0x65, 0x64, 0x73, 0x2f, 0x62, 0x65, 0x64, 0x72, 0x6f, 0x6f, 0x6d, 0x2e, 0x62, 0x65, 0x64, 0x72, 0x6f, 0x6f, 0x6d, 0x74, 0x65, 0x6d, 0x70 }; - static const uint8_t testTopic_len = 37; - //static const char testTopic[4] = { 0x74, 0x65, 0x73, 0x74 }; - //static const uint8_t testTopic_len = 4; - static const char clientID[5] = { 0x46, 0x5a, 0x5a, 0x4e, 0x30 }; + static const char ioUser[11] = { 0x4d, 0x72, 0x41, 0x75, 0x72, 0x65, 0x6c, 0x69, 0x75, 0x73, 0x52 }; // MrAureliusR + static const uint8_t ioUser_len = 11; + static const char ioKey[32] = { }; // use strtoarr.py to generate these + static const uint8_t ioKey_len = 32; + static const char ioTopic[27] = { 0x4d, 0x72, 0x41, 0x75, 0x72, 0x65, 0x6c, 0x69, 0x75, 0x73, 0x52, 0x2f, 0x66, 0x65, 0x65, 0x64, 0x73, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x74, 0x6f, 0x70, 0x69, 0x63 }; // MrAureliusR/feeds/testtopic + static const uint8_t ioTopic_len = 27; + /* static const char ioTopic[37] = { 0x4d, 0x72, 0x41, 0x75, 0x72, 0x65, 0x6c, 0x69, 0x75, 0x73, 0x52, 0x2f, 0x66, 0x65, 0x65, 0x64, 0x73, 0x2f, 0x62, 0x65, 0x64, 0x72, 0x6f, 0x6f, 0x6d, 0x2e, 0x62, 0x65, 0x64, 0x72, 0x6f, 0x6f, 0x6d, 0x74, 0x65, 0x6d, 0x70 }; */ + /* static const uint8_t ioTopic_len = 37; */ + static const char clientID[5] = { 0x46, 0x52, 0x5a, 0x4e, 0x30 }; // FRZN0 static const uint8_t clientID_len = 5; pGlobalSession->port = 1883; // mqtt port - static const char esp_tcp_server_ip[4] = {52, 5, 238, 97}; - os_memcpy(pGlobalSession->ip, esp_tcp_server_ip, 4); - pGlobalSession->username_len = testUser_len; + static const char adafruitIO_ip[4] = {52, 5, 238, 97}; + os_memcpy(pGlobalSession->ip, adafruitIO_ip, 4); + pGlobalSession->username_len = ioUser_len; pGlobalSession->username = os_zalloc(sizeof(uint8_t) * pGlobalSession->username_len); - os_memcpy(pGlobalSession->username, testUser, pGlobalSession->username_len); - pGlobalSession->password_len = testPass_len; + os_memcpy(pGlobalSession->username, ioUser, pGlobalSession->username_len); + pGlobalSession->password_len = ioKey_len; pGlobalSession->password = os_zalloc(sizeof(uint8_t) * pGlobalSession->password_len); - os_memcpy(pGlobalSession->password, testPass, pGlobalSession->password_len); - pGlobalSession->topic_name_len = testTopic_len; + os_memcpy(pGlobalSession->password, ioKey, pGlobalSession->password_len); + pGlobalSession->topic_name_len = ioTopic_len; pGlobalSession->topic_name = os_zalloc(sizeof(uint8_t) * pGlobalSession->topic_name_len); - os_memcpy(pGlobalSession->topic_name, testTopic, pGlobalSession->topic_name_len); + os_memcpy(pGlobalSession->topic_name, ioTopic, pGlobalSession->topic_name_len); pGlobalSession->client_id_len = clientID_len; pGlobalSession->client_id = os_zalloc(sizeof(uint8_t) * pGlobalSession->client_id_len); os_memcpy(pGlobalSession->client_id, clientID, pGlobalSession->client_id_len); - os_timer_setfn(&oneTimer, (os_timer_func_t *)tcpConnect, pGlobalSession); - os_timer_arm(&oneTimer, 15000, 0); - os_timer_setfn(&testTimer, (os_timer_func_t *)con, pGlobalSession); - os_timer_arm(&testTimer, 16000, 0); + os_timer_setfn(&tcpTimer, (os_timer_func_t *)tcpConnect, pGlobalSession); + os_timer_arm(&tcpTimer, 12000, 0); + os_timer_setfn(&pingTimer, (os_timer_func_t *)con, pGlobalSession); + os_timer_arm(&pingTimer, 16000, 0); + os_timer_setfn(&pubTimer, (os_timer_func_t *)dataLog, pGlobalSession); + os_timer_arm(&pubTimer, 20000, 1); } -#endif diff --git a/main.h b/main.h index b0fd905..b37edbe 100644 --- a/main.h +++ b/main.h @@ -1,8 +1,16 @@ -#include "mqtt.h" -#include "onewire.h" +#include "os_type.h" + +extern os_timer_t tcpTimer; +extern os_timer_t pingTimer; +extern os_timer_t pubTimer; + +void reverse(char *str, int len); +int intToStr(int x, char str[], int d); +void ftoa(float n, char *res, int afterpoint); LOCAL void ICACHE_FLASH_ATTR con(void *arg); -LOCAL void ICACHE_FLASH_ATTR pub(void *arg); +LOCAL void ICACHE_FLASH_ATTR pubuint(void *arg); +LOCAL void ICACHE_FLASH_ATTR pubfloat(void *arg); LOCAL void ICACHE_FLASH_ATTR sub(void *arg); LOCAL void ICACHE_FLASH_ATTR ping(void *arg); LOCAL void ICACHE_FLASH_ATTR discon(void *arg); diff --git a/mqtt.c b/mqtt.c index 61b3cfe..7192c25 100644 --- a/mqtt.c +++ b/mqtt.c @@ -3,6 +3,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. #include +#include #include "user_interface.h" #include "ets_sys.h" #include "osapi.h" @@ -12,6 +13,7 @@ #include "os_type.h" #include "mqtt.h" #include "onewire.h" +#include "main.h" /* Functions we will need to implement: * Send -- will handle all sending of all packets @@ -22,18 +24,75 @@ * security or QoS in this basic implementation. */ -#ifdef DEBUG -static os_timer_t oneTimer; -static os_timer_t testTimer; -#endif static os_timer_t MQTT_KeepAliveTimer; static os_timer_t waitForWifiTimer; -LOCAL void ICACHE_FLASH_ATTR data_sent_callback(void *arg) { +// reverses a string 'str' of length 'len' +void reverse(char *str, int len) +{ + int i=0, j=len-1, temp; + while (ireverse; // deal with received data @@ -72,9 +131,15 @@ LOCAL void ICACHE_FLASH_ATTR data_recv_callback(void *arg, char *pdata, unsigned os_printf("Connection refused -- illegal CONNACK return code.\n"); break; } + if(session->connack_cb != NULL) { + session->connack_cb(pdata); + } break; case MQTT_MSG_TYPE_PUBLISH: os_printf("Application message from server: %s\n", &pdata[3]); // probably incorrect + if(session->publish_cb != NULL) { + session->publish_cb(pdata); + } break; case MQTT_MSG_TYPE_SUBACK: os_printf("Subscription acknowledged\n"); @@ -85,11 +150,27 @@ LOCAL void ICACHE_FLASH_ATTR data_recv_callback(void *arg, char *pdata, unsigned case MQTT_MSG_TYPE_PINGRESP: os_printf("Pong!\n"); break; + // all remaining cases listed to avoid warnings + case MQTT_MSG_TYPE_CONNECT: + case MQTT_MSG_TYPE_PUBACK: + case MQTT_MSG_TYPE_PUBREC: + case MQTT_MSG_TYPE_PUBREL: + case MQTT_MSG_TYPE_PUBCOMP: + case MQTT_MSG_TYPE_SUBSCRIBE: + case MQTT_MSG_TYPE_UNSUBSCRIBE: + case MQTT_MSG_TYPE_PINGREQ: + case MQTT_MSG_TYPE_DISCONNECT: + default: + if(msgType == MQTT_MSG_TYPE_DISCONNECT) { + os_printf("MQTT Disconnect packet\n"); + } + return; + break; } } -LOCAL void ICACHE_FLASH_ATTR connected_callback(void *arg) { +void ICACHE_FLASH_ATTR connected_callback(void *arg) { struct espconn *pConn = arg; mqtt_session_t *pSession = pConn->reverse; #ifdef DEBUG @@ -102,16 +183,18 @@ LOCAL void ICACHE_FLASH_ATTR connected_callback(void *arg) { pSession->validConnection = 1; } -LOCAL void ICACHE_FLASH_ATTR reconnected_callback(void *arg, sint8 err) { +void ICACHE_FLASH_ATTR reconnected_callback(void *arg, sint8 err) { os_printf("Reconnected?\n"); os_printf("Error code: %d\n", err); } -LOCAL void ICACHE_FLASH_ATTR disconnected_callback(void *arg) { +void ICACHE_FLASH_ATTR disconnected_callback(void *arg) { os_printf("Disconnected\n"); + os_timer_disarm(&pubTimer); + os_timer_disarm(&pingTimer); } -LOCAL uint8_t ICACHE_FLASH_ATTR tcpConnect(void *arg) { +uint8_t ICACHE_FLASH_ATTR tcpConnect(void *arg) { os_timer_disarm(&waitForWifiTimer); struct ip_info ipConfig; mqtt_session_t *session = arg; @@ -158,11 +241,13 @@ LOCAL uint8_t ICACHE_FLASH_ATTR tcpConnect(void *arg) { // set timer to try again os_timer_setfn(&waitForWifiTimer, (os_timer_func_t *)tcpConnect, session); os_timer_arm(&waitForWifiTimer, 1000, 0); + return 2; } + return 0; } -LOCAL uint8_t ICACHE_FLASH_ATTR *encodeLength(uint32_t trueLength) { +uint8_t ICACHE_FLASH_ATTR *encodeLength(uint32_t trueLength) { uint8_t *encodedByte = os_zalloc(sizeof(uint8_t) * 5); // can't be more than 5 bytes uint8_t numBytes = 1; do { @@ -179,12 +264,12 @@ LOCAL uint8_t ICACHE_FLASH_ATTR *encodeLength(uint32_t trueLength) { } -LOCAL void ICACHE_FLASH_ATTR pingAlive(void *arg) { +void ICACHE_FLASH_ATTR pingAlive(void *arg) { mqtt_session_t *pSession = (mqtt_session_t *)arg; mqtt_send(pSession, NULL, 0, MQTT_MSG_TYPE_PINGREQ); } -LOCAL uint8_t ICACHE_FLASH_ATTR mqtt_send(mqtt_session_t *session, uint8_t *data, uint32_t len, mqtt_message_type msgType) { +uint8_t ICACHE_FLASH_ATTR mqtt_send(mqtt_session_t *session, uint8_t *data, uint32_t len, mqtt_message_type msgType) { if(session->validConnection == 1) { os_timer_disarm(&MQTT_KeepAliveTimer); // disable timer if we are called #ifdef DEBUG @@ -355,4 +440,5 @@ LOCAL uint8_t ICACHE_FLASH_ATTR mqtt_send(mqtt_session_t *session, uint8_t *data } else { os_printf("No wifi! Narf!\n"); } + return 0; } diff --git a/mqtt.h b/mqtt.h index 0f50434..a593341 100644 --- a/mqtt.h +++ b/mqtt.h @@ -82,7 +82,10 @@ typedef struct { uint32_t password_len; /**< The length of the password string */ char validConnection; /**< Boolean value which indicates whether or not the TCP connection is established, set in tcpConnect() */ struct espconn *activeConnection; /**< A pointer to the espconn structure containing details of the TCP connection */ + void *userData; /**< Used to pass data to the PUBLISH function */ // Add pointers to user callback functions + void (*publish_cb)(void *arg); /**< Pointer to user callback function for publish */ + void (*connack_cb)(void *arg); /**< Pointer to user callback function for connack */ } mqtt_session_t; /** @@ -90,9 +93,9 @@ typedef struct { * @param arg A pointer to void, so it can be called from a timer or task * @return 0 on success */ -LOCAL uint8_t ICACHE_FLASH_ATTR tcpConnect(void *arg); -LOCAL void ICACHE_FLASH_ATTR disconnected_callback(void *arg); -LOCAL void ICACHE_FLASH_ATTR reconnected_callback(void *arg, sint8 err); +uint8_t ICACHE_FLASH_ATTR tcpConnect(void *arg); +void ICACHE_FLASH_ATTR disconnected_callback(void *arg); +void ICACHE_FLASH_ATTR reconnected_callback(void *arg, sint8 err); /** * A callback function which is called when TCP connection is successful. @@ -101,7 +104,7 @@ LOCAL void ICACHE_FLASH_ATTR reconnected_callback(void *arg, sint8 err); * * This function is called once the TCP connection to the server is completed. This allows us to register the callbacks for received and sent data, as well as enable TCP keepalive and set validConnection in mqtt_session_t to 1 to show the connection has been successful. */ -LOCAL void ICACHE_FLASH_ATTR connected_callback(void *arg); +void ICACHE_FLASH_ATTR connected_callback(void *arg); /** * A callback function that deals with received data. @@ -112,9 +115,9 @@ LOCAL void ICACHE_FLASH_ATTR connected_callback(void *arg); * * At this point the function does little more than detect what type of MQTT message is sent, and prints out debug info to the serial port. The next few versions should improve this so the user can register their own callback functions which will be called when the particular message type is receieved. */ -LOCAL void ICACHE_FLASH_ATTR data_recv_callback(void *arg, char *pdata, unsigned short len); -LOCAL void ICACHE_FLASH_ATTR data_sent_callback(void *arg); -LOCAL void ICACHE_FLASH_ATTR pingAlive(void *arg); +void ICACHE_FLASH_ATTR data_recv_callback(void *arg, char *pdata, unsigned short len); +void ICACHE_FLASH_ATTR data_sent_callback(void *arg); +void ICACHE_FLASH_ATTR pingAlive(void *arg); /** * A function which takes a uint32_t and returns a pointer to a properly formatted MQTT length. @@ -125,7 +128,7 @@ LOCAL void ICACHE_FLASH_ATTR pingAlive(void *arg); * The MQTT standard uses a very strange method of encoding the lengths of the various sections * of the packets. This makes it simpler to implement in code. */ -LOCAL uint8_t ICACHE_FLASH_ATTR *encodeLength(uint32_t trueLength); +uint8_t ICACHE_FLASH_ATTR *encodeLength(uint32_t trueLength); /** * This function handles all the sending of various MQTT messages. @@ -135,4 +138,4 @@ LOCAL uint8_t ICACHE_FLASH_ATTR *encodeLength(uint32_t trueLength); * @param msgType the type of message to be send, one of the mqtt_message_type * @return -1 in case of error, 0 otherwise */ -LOCAL uint8_t ICACHE_FLASH_ATTR mqtt_send(mqtt_session_t *session, uint8_t *data, uint32_t len, mqtt_message_type msgType); +uint8_t ICACHE_FLASH_ATTR mqtt_send(mqtt_session_t *session, uint8_t *data, uint32_t len, mqtt_message_type msgType); diff --git a/onewire.c b/onewire.c index 85ae1d5..ce22697 100644 --- a/onewire.c +++ b/onewire.c @@ -1,38 +1,105 @@ #include +#include "os_type.h" +#include "osapi.h" +#include "user_interface.h" #include "gpio.h" -#include "hw_timer.c" #include "onewire.h" -LOCAL void timerISR(void) { - return; -} +#define OWBUS BIT5 -LOCAL void reset(oneWire_t *owDev) { +sint8 ICACHE_FLASH_ATTR reset(void) { + uint32_t time; // reset the ow line, check for presence? + time = system_get_time() + 500; + gpio_output_set(0, OWBUS, OWBUS, 0); // pull GPIO4 low + while(system_get_time() < time); // delay 500uS + gpio_output_set(0, 0, 0, OWBUS); // let go of GPIO4 + time = system_get_time() + 60; + while(system_get_time() < time); + uint8_t presence = (uint8_t)(gpio_input_get() >> 5) & 0x1; + // give a 480uS pause so the next onewire event doesn't get trampled + time = system_get_time() + 480; + while(system_get_time() < time); + + if(!presence) { + return 1; + } else { + return -1; + } } -LOCAL void ICACHE_FLASH_ATTR transact(oneWire_t *owDev, ds18b20_cmds cmd) { +void ICACHE_FLASH_ATTR transact(oneWire_t *owDev, ds18b20_cmds cmd) { + uint32_t time; + uint8_t sendBit; + uint8_t inBit = 0x00; + uint8_t inByte = 0x00; switch(cmd) { - case READ_ROM: - break; - case MATCH_ROM: - break; - case SEARCH_ROM: - break; - case ALARM_SEARCH: - break; + os_printf("\nOnewire command: %d\n", cmd); case SKIP_ROM: - break; case CONVERT_T: + for(uint8_t i = 0; i < 8; i++) { + sendBit = (cmd >> i) & 0x1; + //os_printf("\nThe bit is: %d \t i is %d\n", sendBit, i); + if(sendBit == 1) { + //os_printf("\nWe are in sendBit == 1\n"); + time = system_get_time() + 10; + gpio_output_set(0, OWBUS, OWBUS, 0); // pull low + while(system_get_time() < time); + gpio_output_set(0, 0, 0, OWBUS); // let go + time = system_get_time() + 50; + while(system_get_time() < time); + } else { + //os_printf("\nWe are in the sendBit else\n"); + time = system_get_time() + 100; + gpio_output_set(0, OWBUS, OWBUS, 0); //pull low + while(system_get_time() < time); + gpio_output_set(0, 0, 0, OWBUS); // let go + time = system_get_time() + 10; + while(system_get_time() < time); + } + } break; case SCRATCH_READ: + for(uint8_t i = 0; i < 8; i++) { + sendBit = (cmd >> i) & 0x1; + if(sendBit == 1) { + //os_printf("\nWe are in sendBit == 1\n"); + time = system_get_time() + 10; + gpio_output_set(0, OWBUS, OWBUS, 0); // pull low + while(system_get_time() < time); + gpio_output_set(0, 0, 0, OWBUS); // let go + time = system_get_time() + 50; + while(system_get_time() < time); + } else { + //os_printf("\nWe are in the sendBit else\n"); + time = system_get_time() + 100; + gpio_output_set(0, OWBUS, OWBUS, 0); //pull low + while(system_get_time() < time); + gpio_output_set(0, 0, 0, OWBUS); // let go + time = system_get_time() + 10; + while(system_get_time() < time); + } + } + // now read the scratchpad + for(uint8_t i = 0; i < 2; i++) { + for(uint8_t j = 0; j < 8; j++) { + time = system_get_time() + 8; + gpio_output_set(0, OWBUS, OWBUS, 0); + while(system_get_time() < time); + gpio_output_set(0, 0, 0, OWBUS); + time = system_get_time() + 15; + while(system_get_time() < time); + inBit = (uint8_t)(gpio_input_get() >> 5) & 0x01; + inByte |= inBit << j; + time = system_get_time() + 45; + while(system_get_time() < time); + } + owDev->scratchpad[i] = inByte; + inByte = 0; // clear inByte + } break; - case SCRATCH_WRITE: - break; - case SCRATCH_COPY: - break; - case E2_RECALL: + default: + os_printf("\nIncorrect command\n"); break; } - } diff --git a/onewire.h b/onewire.h index 2e4c474..9993365 100644 --- a/onewire.h +++ b/onewire.h @@ -1,5 +1,6 @@ #include -#include "hw_timer.c" +#include "os_type.h" +#include "gpio.h" /** * @struct oneWire_t @@ -7,14 +8,15 @@ */ typedef struct { uint8_t address[8]; - uint8_t scratchpad[20]; + uint8_t scratchpad[9]; + float temperature; } oneWire_t; /** * @enum ds18b20_cmds * This enum simply gives easy to read names to all the various one-wire commands that the DS18B20 can accept */ -enum ds18b20_cmds { +typedef enum { READ_ROM = 0x33, MATCH_ROM = 0x55, SEARCH_ROM = 0xF0, @@ -25,9 +27,7 @@ enum ds18b20_cmds { SCRATCH_WRITE = 0x4E, SCRATCH_COPY = 0x48, E2_RECALL = 0xB8 -}; +} ds18b20_cmds; - -LOCAL void timerISR(void); -LOCAL void ICACHE_FLASH_ATTR reset(oneWire_t *owDev); -LOCAL void ICACHE_FLASH_ATTR transact(oneWire_t *owDev, ds18b20_cmds cmd); +sint8 ICACHE_FLASH_ATTR reset(void); +void ICACHE_FLASH_ATTR transact(oneWire_t *owDev, ds18b20_cmds cmd); diff --git a/strtoarr.py b/strtoarr.py index b038afb..5f3198d 100755 --- a/strtoarr.py +++ b/strtoarr.py @@ -3,7 +3,7 @@ # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. - +#!/usr/bin/python3 ## # @file # @brief File to create string arrays @@ -28,5 +28,5 @@ for letter in inString[:-1]: p = ord(inString[-1]) print("{0:#x} ".format(int(p)), end='') -print("};") +print("}; // " + inString) print("static const uint8_t {0}_len = {1};".format(sys.argv[2], len(inString))) From b253769f9f61d320580e4254ca9148f6476f1ed3 Mon Sep 17 00:00:00 2001 From: AMRowsell Date: Tue, 22 Jan 2019 01:23:51 +0000 Subject: [PATCH 2/6] Add .gitlab-ci.yml --- .gitlab-ci.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..a9c4116 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,14 @@ +# This file is a template, and might need editing before it works on your project. +# Full project: https://gitlab.com/pages/doxygen +image: alpine + +pages: + script: + - apk update && apk add doxygen + - doxygen Doxyfile + - mv docs/html/ public/ + artifacts: + paths: + - public + only: + - master From 31eb087a7a0b98fef6bcb5d4aec68503764c7ee4 Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Mon, 21 Jan 2019 20:26:58 -0500 Subject: [PATCH 3/6] Updated README and created Doxygen automation Signed-off-by: A.M. Rowsell --- .gitignore | 3 +- README.md | 133 +---------------------------------------------------- 2 files changed, 3 insertions(+), 133 deletions(-) diff --git a/.gitignore b/.gitignore index 28ce62e..2e52dc7 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ mqtt \#*\# .\#* pcap/ -docs/ +docs/latex/ +docs/man/ \ No newline at end of file diff --git a/README.md b/README.md index f2f1f36..1f2f07d 100644 --- a/README.md +++ b/README.md @@ -7,135 +7,4 @@ While working on a series of tutorials for Hackaday, I realized MQTT would be th At this point, it's a bit messy. It still needs a lot of work. This documentation will help me keep everything organized and easy-to-use. -## API Structures - -``` -typedef struct { - uint8_t ip[4]; - uint32_t port; - uint32_t localPort; - uint8_t *client_id; - uint32_t client_id_len; - uint8_t *topic_name; - uint32_t topic_name_len; - uint8_t qos_level; - uint8_t *username; - uint32_t username_len; - uint8_t *password; - uint32_t password_len; - char valid_connection; - struct espconn *activeConnection; -} mqtt_session_t; -``` - -This is the main structure that contains all the information about the connection to the server. The IP address, port, client\_id, topic\_name, username, and password are all specified here by the end user. localPort is set by the API, and qos\_level should be set to 0. *activeConnection will point to the espconn struct that represents the TCP connection to the server. The end-user shouldn't need to touch anything in this struct. - -## API Functions - -### `LOCAL uint8_t ICACHE_FLASH_ATTR mqtt_send(mqtt_session_t *session, uint8_t *data, uint32_t len, mqtt_message_type msgType);` - -This is the only function that needs to be called by the user. You pass the `mqtt_session_t` that you have created with all the fields filled in, you pass `*data` if you are publishing (NULL otherwise), len which is the length of `*data` (again, only if publishing, 0 otherwise), and then the message type you want to send, which is one of these enums: - -``` -typedef enum mqtt_message_enum -{ - MQTT_MSG_TYPE_CONNECT = 1, - MQTT_MSG_TYPE_CONNACK = 2, - MQTT_MSG_TYPE_PUBLISH = 3, - MQTT_MSG_TYPE_PUBACK = 4, - MQTT_MSG_TYPE_PUBREC = 5, - MQTT_MSG_TYPE_PUBREL = 6, - MQTT_MSG_TYPE_PUBCOMP = 7, - MQTT_MSG_TYPE_SUBSCRIBE = 8, - MQTT_MSG_TYPE_SUBACK = 9, - MQTT_MSG_TYPE_UNSUBSCRIBE = 10, - MQTT_MSG_TYPE_UNSUBACK = 11, - MQTT_MSG_TYPE_PINGREQ = 12, - MQTT_MSG_TYPE_PINGRESP = 13, - MQTT_MSG_TYPE_DISCONNECT = 14 -} mqtt_message_type; -``` - -Obviously, the user will only be choosing CONNECT, PUBLISH, SUBSCRIBE, UNSUBSCRIBE, PINGREQ and DISCONNECT. The rest are messages from the broker back to the client. If you send an incorrect message type, nothing will happen, and no TCP packets will be sent to the broker. - -Due to a strange bug with the way pointers to strings are passed between functions, all the fields in the `mqtt_session_t` need to be allocated and have their contents memcpy'd. They also need to be in hex format. This is a pain in the butt, so there is an included Python 3 script to create the arrays for you. Running it is as simple as the following: - -``` -$ chmod +x strtoarr.py -$ ./strtoarr.py MyUsername username -static const char username[10] = { 0x4d, 0x79, 0x55, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65 }; -static const uint8_t username_len = 10; -``` - -Then copy and paste the result into your code. Allocate the correct amount of memory, then copy and pass the pointer into the struct: - -``` -static const char username[10] = { 0x4d, 0x79, 0x55, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65 }; -static const uint8_t username_len = 10; -pGlobalSession->username_len = username_len; -pGlobalSession->username = os_zalloc(sizeof(uint8_t) * pGlobalSession->username_len); -os_memcpy(pGlobalSession->username, testUser, pGlobalSession->username_len); -``` - -Slightly more complex than just passing the address of a char array, but until I can figure out why the ESP8266 butchers strings that are passed by reference, this is how it has to be. - -A very basic, fully working example that doesn't do anything but establish a connection might look like this: - -``` -LOCAL mqtt_session_t globalSession; -LOCAL mqtt_session_t *pGlobalSession = &globalSession; -char ssid[32] = "WirelessAP"; -char passkey[64] = "myAPpassword"; -struct station_config stationConf; -gpio_init(); // init gpio so we can use the LED -wifi_status_led_install(0, PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0); // set GPIO0 as status LED -stationConf.bssid_set = 0; -os_memcpy(&stationConf.ssid, ssid, 32); // copy the ssid and passkey into the station_config struct -os_memcpy(&stationConf.password, passkey, 64); -wifi_set_opmode_current(0x01); //station mode -wifi_station_set_config_current(&stationConf); // tell it about our config, this auto-connects us as well - -// testUser = MrAureliusR -static const char testUser[11] = { 0x4d, 0x72, 0x41, 0x75, 0x72, 0x65, 0x6c, 0x69, 0x75, 0x73, 0x52 }; -static const uint8_t testUser_len = 11; -// testPass = test -static const char testPass[4] = { 0x74, 0x65, 0x73, 0x74 }; -static const uint8_t testPass_len = 4; -// testTopic = test -static const char testTopic[4] = { 0x74, 0x65, 0x73, 0x74 }; -static const uint8_t testTopic_len = 4; -// clientID = FRZN0 (this can be anything you like, under 21 characters) -static const char clientID[5] = { 0x46, 0x52, 0x5a, 0x4e, 0x30 }; -static const uint8_t clientID_len = 5; -pGlobalSession->port = 1883; // mqtt port -static const char esp_tcp_server_ip[4] = {8, 8, 8, 8}; // the IP address of the server you want to connect to - -// copy all these into their proper locations -os_memcpy(pGlobalSession->ip, esp_tcp_server_ip, 4); -pGlobalSession->username_len = testUser_len; -pGlobalSession->username = os_zalloc(sizeof(uint8_t) * pGlobalSession->username_len); -os_memcpy(pGlobalSession->username, testUser, pGlobalSession->username_len); -pGlobalSession->password_len = testPass_len; -pGlobalSession->password = os_zalloc(sizeof(uint8_t) * pGlobalSession->password_len); -os_memcpy(pGlobalSession->password, testPass, pGlobalSession->password_len); -pGlobalSession->topic_name_len = testTopic_len; -pGlobalSession->topic_name = os_zalloc(sizeof(uint8_t) * pGlobalSession->topic_name_len); -os_memcpy(pGlobalSession->topic_name, testTopic, pGlobalSession->topic_name_len); -pGlobalSession->client_id_len = clientID_len; -pGlobalSession->client_id = os_zalloc(sizeof(uint8_t) * pGlobalSession->client_id_len); -os_memcpy(pGlobalSession->client_id, clientID, pGlobalSession->client_id_len); -``` - -After this, you can set up a task or timer to actually call mqtt_send with the pointer to mqtt_session_t and the MQTT_MSG_TYPE_CONNECT. A connect function might look like this: - -``` -LOCAL void ICACHE_FLASH_ATTR con(void *arg) { - mqtt_session_t *pSession = (mqtt_session_t *)arg; - tcp_connect(pSession); // establish tcp connection - os_delay_us(60000); - // a future version of the API won't require a delay here - // if you are having problems, try adding more os_delay_us(60000); here. Sometimes the TCP - // connection takes longer to start - mqtt_send(pSession, NULL, 0, MQTT_MSG_TYPE_CONNECT); -} -``` +The documentation has now been turned into Doxygen documentation. You can view the latest documentation [here](https://mraureliusr.gitlab.io/mqtt-esp8266/index.html) From 86b180e5f2f00a0f3d8daa5e0d26aa3474b037d3 Mon Sep 17 00:00:00 2001 From: AMRowsell Date: Tue, 22 Jan 2019 01:33:02 +0000 Subject: [PATCH 4/6] Update .gitlab-ci.yml to add graphviz --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a9c4116..7507317 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ image: alpine pages: script: - - apk update && apk add doxygen + - apk update && apk add doxygen graphviz - doxygen Doxyfile - mv docs/html/ public/ artifacts: From 930d00a9a03eb7fcaeb9d13067c97c52b857b1b6 Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Mon, 21 Jan 2019 20:35:28 -0500 Subject: [PATCH 5/6] Added logo and updated Doxyfile Signed-off-by: A.M. Rowsell --- Doxyfile | 2 +- fortune-cookie_small.png | Bin 0 -> 13489 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 fortune-cookie_small.png diff --git a/Doxyfile b/Doxyfile index c6e8fd7..122a79d 100644 --- a/Doxyfile +++ b/Doxyfile @@ -51,7 +51,7 @@ PROJECT_BRIEF = "MQTT library for ESP8266" # pixels and the maximum width should not exceed 200 pixels. Doxygen will copy # the logo to the output directory. -PROJECT_LOGO = /home/amr/Pictures/284737-cute-food/png/fortune-cookie_small.png +PROJECT_LOGO = fortune-cookie_small.png # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path # into which the generated documentation will be written. If a relative path is diff --git a/fortune-cookie_small.png b/fortune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~BXHm-0j01=Jbki3mj9~*&Pc=+{$M*)avyc_tEmurh*QCoJHmJrb1 zBx$OztX{x^R)ePciFFJ$&0OBi$8vtjvWaVo**#of?y378uW5j}419OLAek{&{%oEn zX)LgXTsmW}6dDfZUr@0UFeK=@An5Okrdu)hNcNQvJSTxC7;qEYH+Wg@l&cnXIbOdE!| zjrwph`<1Lk?RwbN`%#pIXNcr~xkkWkpJ=gBu4Rw-JTg%cyJp`;5(fI2s6IEW*S_RyIi$K!ah&h;3 zUsHbLgE{e(Z)^9#k+Kx<0I)%|@xiC<;6yb38gL=-k{{{&ja^+YrN=(6cU}T6w4SMQ zd~0i4{nIs=E!G)DO<3lgw5h9+rQBb3E3l^6zP=s4cD6(`-V3}JxXaIcRHJF+TL)-fKNW-zb@wWg_-L%)rvdQsr4JBS}HukRW52UDK9%Mk#s#{g@+sKleQ+ zO1xXPOvIL91}t7!%6w-KJAjXiXnbF(GA!wMn{{LBfiD6>rOdm+8Nz%f>q}{TD6t2a zj7-Fq0{?}>eeSE6hk?(EX#8L~GB10tTP9)`0k;F^m$@jV=1;&aA{zhSau%ZOQ!XMJ z{{!YG#~%QmFK=l|!t00aKcwV8xI0S3~wy2!IQAx!LU<{dv1u(tA2Y}0g1?4SKLEZ#@jk%`66CxU~ z=q1i7UI3GkiI@hQ2fWYvtfc(+Ab~x=udL5=A{w7D0d3`ects%-v1VX3rYOcfepeTV zfafNCcKJPA>nAf>0J)HfSO;(h=BCM~P5O5MP-lJWC;bgDY<-3%{rx89Ldypy{kva8 f Date: Tue, 22 Jan 2019 12:16:39 -0500 Subject: [PATCH 6/6] Added documentation, removed library from Makefile Making the mqtt as a .a library is a project for a later date. The recipe was broken and so was removed to avoid confusion. Added the Mozilla License header to the new files. Also a few small corrections and additions to the Doxygen documentation. Signed-off-by: A.M. Rowsell --- Makefile | 4 ---- mqtt.h | 2 +- onewire.c | 6 +++++- onewire.h | 19 +++++++++++++++++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 4d82140..7fa6b32 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,3 @@ flash: $(P)-0x00000.bin clean: rm -f $(P) $(OBJ) $(P)-0x00000.bin $(P)-0x10000.bin *~ - -library: - $(CC) -c -fPIC $(CFLAGS) $(P).c -o $(P).o - $(AR) rcs lib$(P).a $(P).o diff --git a/mqtt.h b/mqtt.h index a593341..22ef4ed 100644 --- a/mqtt.h +++ b/mqtt.h @@ -100,7 +100,7 @@ void ICACHE_FLASH_ATTR reconnected_callback(void *arg, sint8 err); /** * A callback function which is called when TCP connection is successful. * @param *arg A pointer to void, which needs to be cast to espconn *pConn - * @returns Void + * @return Void * * This function is called once the TCP connection to the server is completed. This allows us to register the callbacks for received and sent data, as well as enable TCP keepalive and set validConnection in mqtt_session_t to 1 to show the connection has been successful. */ diff --git a/onewire.c b/onewire.c index ce22697..c6a8208 100644 --- a/onewire.c +++ b/onewire.c @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #include #include "os_type.h" #include "osapi.h" @@ -5,7 +9,7 @@ #include "gpio.h" #include "onewire.h" -#define OWBUS BIT5 +#define OWBUS BIT5 /**< This define determines which pin is used */ sint8 ICACHE_FLASH_ATTR reset(void) { uint32_t time; diff --git a/onewire.h b/onewire.h index 9993365..0da4c8d 100644 --- a/onewire.h +++ b/onewire.h @@ -1,7 +1,16 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + #include #include "os_type.h" #include "gpio.h" +/** + * @file + * @brief This is the header file for the one-wire library + */ + /** * @struct oneWire_t * Structure that holds all the information about onewire connections, including the 64-bit ROM address for each device and some buffer memory to read out the scratchpad @@ -29,5 +38,15 @@ typedef enum { E2_RECALL = 0xB8 } ds18b20_cmds; +/** + * Function sends a reset pulse on the one-wire bus and checks for a presence pulse + * @return 0 if no presence, 1 if presence + */ sint8 ICACHE_FLASH_ATTR reset(void); + +/** + * Function which handles all one-wire communication besides the reset sequence. + * @param owDev A pointer to the oneWire_t variable for this device + * @param cmd One of the commands from ds18b20_cmds + */ void ICACHE_FLASH_ATTR transact(oneWire_t *owDev, ds18b20_cmds cmd);