IoT sensor/controller using STM32, W5500 ethernet, MQTT
Dependencies: mbed WIZnet_Library Watchdog DHT MQTT DS1820
Diff: main.cpp
- Revision:
- 8:6d7be3bed961
- Parent:
- 7:3c2222251deb
- Child:
- 9:a8098e772b48
--- a/main.cpp Wed Feb 26 17:22:18 2020 +0000 +++ b/main.cpp Wed Feb 26 23:36:16 2020 +0000 @@ -34,12 +34,17 @@ #define D_12 PA_4 // digital output D12 - SPI1 MISO //#define D_13 PA_4 // digital output D13 - SPI1 CLK - GREEN LED #define D_14 PB_8 // digital output D14 +#define D_35 PC_6 // pin 13 on Extension +#define D_36 PC_7 // pin 14 on Extension +#define D_37 PC_8 // pin 15 on Extension (last) // ================= *************** ================== -#define USART3_TX PC_10 // D26 - pin 4 on Extension +#define USART3_TX PC_10 // D26 - pin 4 on Extension // ================= *************** ================== // serial output? for uLCD // ================= *************** ================== -// sensor inputs? +// sensor inputs +#define ONEWIRE_PIN D_37 // pin 15 on Extension +#define MAX_TEMP_PROBES 4 // ================= *************** ================== #define NODE_NAME "controller03" // TODO just define node number @@ -71,8 +76,8 @@ enum IO_STATE{IO_ON, IO_OFF}; uint8_t mac_addr[6]={0x00, 0x00, 0x00, 0xBE, 0xEF, 0x03}; // TODO make last byte dynamic -const char* mqtt_broker = "192.168.10.4"; -//const char* mqtt_broker = "192.168.1.99"; +//const char* mqtt_broker = "192.168.10.4"; +const char* mqtt_broker = "192.168.1.99"; const int mqtt_port = 1883; unsigned long uptime_sec = 0; int connected = -1; @@ -190,8 +195,7 @@ } -void read_inputs(MClient &client) -{ +void read_inputs(MClient &client) { for(int i=0; i<NUM_INPUTS; i++) { bool old_state = input_state[i]; // save old state input_state[i] = inputs[i]; // read new value @@ -207,6 +211,17 @@ } +void read_temp(MClient &client) {/* + probe.convertTemperature(true, DS1820::all_devices); //Start temp conversion, wait until ready + temp = probe.temperature(); + pc.printf("Temp0 is %3.1foC\r\n", temp); + // convert to string and publish + char temp_str[6]; + sprintf(temp_str, "%3.1f", temp); + connected = publish_value(client,"temp0",temp_str); +*/} + + int networking_init(MQTTSocket &sock, MClient &client, WIZnetInterface &wiz) { int ret = 0; pc.printf("\n\nNode: %s\r\n", NODE_NAME); @@ -268,8 +283,8 @@ int main() { - //WIZnetInterface wiz(PA_7, PA_6, PA_5, PA_4, PB_10); // SPI1 with D29 (reset) - WIZnetInterface wiz(PB_15, PB_14, PB_13, PB_12, NC); // SPI2 with no reset + WIZnetInterface wiz(PA_7, PA_6, PA_5, PA_4, NC); // SPI1 with no reset +// WIZnetInterface wiz(PB_15, PB_14, PB_13, PB_12, NC); // SPI2 with no reset MQTTSocket sock; MClient client(sock);