So this weekend, I ended up overhauling my ESP8266 DHT library to make it plug and play into other projects. One big thing to take aware from this is that GPIO 15 is off limits due to the pin being required to be low / grounded during boot or it will not leverage SPI to start up.
Also GPIO16 is also off limits as well for GPIO toggling, With this being said 6-11 is also offlimits for SPI. So what’s left? Not much, I’m testing with GPIO13 at the moment to see if it can handle the data line floating while the esp is rebooting.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
//https://www.mikrocontroller.net/attachment/263828/The-ESP8266-Book-August-2015.pdf #include "ets_sys.h" #include "osapi.h" #include "gpio.h" #include "os_type.h" #include "ip_addr.h" #include "mem.h" #include "user_interface.h" #include "lwip/stats.h" #include "espconn.h" #include "c_types.h" ////ONE WIRE #include "../library/uart.h" //Copy these from your Driver Lib to your local folder #include "../library/gpio16.h" //Copy these from your Driver Lib to your local folder #include "../library/common.h" #include "../library/dht.h" #include "../library/station.h" #include "../library/sockets.h" /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// #define user_procTaskPrio 0 #define user_procTaskQueueLen 1 os_event_t user_procTaskQueue[user_procTaskQueueLen]; void ICACHE_FLASH_ATTR StationConnected() { os_printf("[%s]\r\n", __func__); os_printf("Socket function Temp = %d *F, Hum = %d %%\n", (int)(GlobalReading.temperature * 1.8 + 32), (int)(GlobalReading.humidity)); init_sockets(NULL, NULL, NULL, NULL); //Do not override Socket.H callbacks //Creates Timer Socket uint8 FreeSocket = GetFreeSocket(); if (FreeSocket == 255) { os_printf("No Free socket avilable\r\n"); return; } os_strcpy(MySendDataStruct[FreeSocket].Name, "MyThermSocket"); MySendDataStruct[FreeSocket].Domain = DOMAIN; os_sprintf(MySendDataStruct[FreeSocket].DataToSend, "GET /MyEsp.php?ssid=myssid&IP=MyIp2&ID=MyId2&temp=%d&hum=%d HTTP/1.1\r\nUser-Agent: SomeAgent\r\nHost: %s\r\nAccept: */*\r\n\r\n", (int)(GlobalReading.temperature * 1.8 + 32), (int)(GlobalReading.humidity), DOMAIN); StartSendingSocketTimer(FreeSocket); } void ICACHE_FLASH_ATTR myDHTFunctionCallback(struct sensor_GlobalReading * MyReading) { os_printf("[%s]\r\n", __func__); os_printf("Callback function Temp = %d *F, Hum = %d %%\n", (int)(GlobalReading.temperature * 1.8 + 32), (int)(GlobalReading.humidity)); init_station("Thermastat.local", true, &StationConnected); //Connect to stronegest open AP } void ICACHE_FLASH_ATTR sdk_init_done_cb(void) { os_printf("[%s] initializing ESP8266!\r\n", __func__); SpiFlashOpResult ReadResult = spi_flash_read(ThermMemorySpace,(uint32 *)&ThermostatConfig,sizeof(ThermostatConfig)); if (ReadResult != SPI_FLASH_RESULT_OK || ThermostatConfig.programmed != 1 || true) //If not set, Set it.. { os_printf("Setting's not found, Calling Set_ThermostatSettings\r\n"); //NOTE: Don't use GPIO16/D0, This is reserved. //DHT22 GPIO=GPIO0/D3 Power=GPIO15/D8 PollingEnabled Interval=5Min SendOnInit=true SendIfOnlyIf=false tempatureDegrees=40 classification="warmer" DeepSleepAfterSend DeepSleepTime Enabled Reserved //SpiFlashOpResult writeResult = Set_ThermostatSettings(MySensor_DHT22, 0, 15, true, 5, true, false, 40, "warmer", false, NULL, true, NULL); //DHT22 Data=GPIO15/D8 Power=GPI13/D7 PollingEnabled Interval=5Min SendOnInit=true SendIfOnlyIf=false tempatureDegrees=40 classification="warmer" DeepSleepAfterSend DeepSleepTime Enabled Reserved SpiFlashOpResult writeResult = Set_ThermostatSettings(MySensor_DHT22, 13, 15, true, 5, true, false, 40, "warmer", false, NULL, true, NULL); //DHT22 GPIO=GPIO0/D3 Power=GPIO4/D2 PollingEnabled Interval=1Min SendOnInit=true SendIfOnlyIf=false tempatureDegrees=NULL classification=warmer/colder DeepSleepAfterSend DeepSleepTime Enabled Reserved //Set_ThermostatSettings(MySensor_DHT22, 0, 4, true, 1, true, false, NULL, "warmer", false, 5, true, NULL); if (writeResult == SPI_FLASH_RESULT_OK) { init_ThermostatSettings(&myDHTFunctionCallback); } } else { init_ThermostatSettings(&myDHTFunctionCallback); } } void ICACHE_FLASH_ATTR user_init() { //void uart0_tx_buffer(uint8 *buf, uint16 len) uart_div_modify(0, UART_CLK_FREQ / 115200); wifi_set_opmode(0); wifi_set_sleep_type( NONE_SLEEP_T ); ETS_GPIO_INTR_DISABLE();// Disable gpio interrupts gpio_init(); //Start os task system_init_done_cb(sdk_init_done_cb); //system_os_task(loop, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen); //Task to Signal for later } |