//-------------------------------------------------------------------------------------------------------------------------------- //Arduino Sketch Sends a Message after the Setup-Routine is finished and then Every minute a Message with a Messagecounter //-------------------------------------------------------------------------------------------------------------------------------- #include #include const char* ssid = "yourSSID"; const char* password = "yourPassword"; unsigned long lastTime = 0; unsigned long timerDelay = 60000; static int aCounter = 0; String ServerAndPort = "http://192.168.1.175:81"; // Put here the IP-Adress and Port witch you see in the "iot messager" //Application! its Your PC-IP //-------------------------------------------------------------------------------------------------------------------------------- void PostMessage(String aServer,String aTitle,String aMessage) // This is the Routine you call to Post the message { if(WiFi.status()== WL_CONNECTED) { HTTPClient http; http.setConnectTimeout(1000); // if your PC is Offline routine waits max 1 secound for connection then continue. String serverPath = aServer +"/iot_messager?" + "title=" + aTitle + "&" + "message=" + aMessage; //Concatenate the Post string Serial.println(serverPath); // Show the whole POST string http.begin(serverPath); //Start the Http-client http.POST(serverPath); //Post the Message http.end(); //End the http-client } } //-------------------------------------------------------------------------------------------------------------------------------- void setup() { Serial.begin(115200); // Init Serial WiFi.begin(ssid, password); // Set ID and Password Serial.println("Connecting"); while(WiFi.status() != WL_CONNECTED) { // Connect WiFi delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to WiFi network with IP Address: "); Serial.println(WiFi.localIP()); // Show the IP of the Device // Send a Message to IotMessager PostMessage(ServerAndPort,"ESP32","Setup routine has just been run! The IP address of the ESP32 is: "+WiFi.localIP().toString()); } //-------------------------------------------------------------------------------------------------------------------------------- void loop() { if ((millis() - lastTime) > timerDelay) { aCounter++; PostMessage(ServerAndPort, "ESP32", "Send Message NR: " + String(aCounter)); // Send a Message to IotMessager lastTime = millis(); } } //-------------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------------