#include //Wifi #include //MQTT #include //sensor libraries #include //Wifi variables const char* ssid = "FabAcademy"; const char* password = "fabacademy"; IPAddress wemosIP; //IP addres that wemos received //MQTT server const char* mqtt_server = "192.168.4.1"; const int mqtt_port = 1883; WiFiClient espClient; const char* mqttServerStatus = "mqttServerStatus"; PubSubClient MQTTclient(espClient); String wemosListener; //message received from MQTT char* mqttSensorTopic = "mqttSensorListener"; char* mqttOLEDTopic = "mqttOLEDListener"; //MQTT send message unsigned long lastMsg = 0; #define MSG_BUFFER_SIZE (50) char msg[MSG_BUFFER_SIZE]; //sensor VL53L0X sensor; const int8_t PIN_SDA = D1; const int8_t PIN_SCL = D2; void setup_wifi() { delay(10); // We start by connecting to a WiFi network Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } randomSeed(micros()); wemosIP = WiFi.localIP(); Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(wemosIP); } void mqttMessageCallback(char* topic, byte* payload, unsigned int length) { char* message = (char*) malloc(sizeof(char)*(length+1)); for(int i=0; i 2000) { long distance = sensor.readRangeContinuousMillimeters(); lastMsg = now; snprintf (msg, MSG_BUFFER_SIZE, "sensor #%ld mm", distance/10); Serial.print("Publish message: "); Serial.println(msg); mqttPublishMessage(mqttOLEDTopic, msg); } }