Copyright (c) By Thomas Kirr Software
Examples
Examples
The origin of a message can be any source that can send a "Get" or "POST" command.
This can be the folowing sources:
- Browser
- Networkable and programmable IOT devices.
- Arduino compatible network-compatible boards such as ESP8266, ESP32 etc.
- HTML page with a button
- Smartphones in the same network.
If a message is to be received from outside the network, a port forwarding must be done in the router.
You can find out how to do this in the operating instructions for your router under "Port forwarding".
Start Iot Messager or look at the bottom right under "Show hidden icons" if Iot Messager already
running.
Notifications should be turned on in Windows.
Example for your browser:
Tap or copy the following line into your browser (Internet Explorer or Chrome or Firefox etc.)
Change the IP-Adress and Port to the values shown in IotMessager Application.
http://192.168.1.175:81/Iot_Messager?title=YOUR_TITLE&message=YOUR_MESSAGE
Example of a website with a GET and a POST button
Copy the following html code into a text file with the file name "test.html" and run it in your Browser
Change the IP-Adress and Port to the Values shown in IotMessager Application.
<!doctype html>
<html lang='de'>
<head>
<meta charset='utf-8'>
<meta name='description' content='Iot Messager demo'>
<title>IOT Messager</title>
</head>
<body bgcolor='#000000'>
<br>
<a href="http://192.168.1.175:81/Iot_Messager?title=YOUR_GET_TITLE&message=YOUR_GET_MESSAGE">
<button>Per GET an „Iot Messager“ senden</button>
</a>
<br>
<br>
<form>
<button
formmethod="POST"
formaction="http://192.168.1.175:81/Iot_Messager?title=YOUR_POST_TITLE&message=YOUR_POST_MESSAGE">
Per POST an „Iot Messager“ senden
</button>
</form>
</body>
</html>
Example of an Arduino sketch.
Create a new file with the Arduino IDE and copy the following code into this file.
Upload the sample code to your ESP32. The libraries required for the ESP32 should already be installed.
Change the IP-Adress and Port to the Values shown in IotMessager Application.
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
//Arduino Sketch Sends a Message after the Setup-Routine is finished and then Every minute a Message with a Messagecounter
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
#include <WiFi.h>
#include <HTTPClient.h>
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();
}
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------------------------------------------