-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Commit
- Loading branch information
0 parents
commit 967696e
Showing
8 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#include <ESP8266WiFi.h> | ||
#include <Ticker.h> | ||
#include <AsyncMqttClient.h> | ||
|
||
//Add you WIFI Connectionn here in order to make sure the ESP can conenct to the internet | ||
|
||
#define WIFI_SSID "YOUR_SSID" | ||
#define WIFI_PASSWORD "YOUR_PASSWORD" | ||
|
||
// ADD your cumulocity URL here, if you don´t have one you could start one for free as a trial | ||
// In this example the unsecure 1883 port is used. We recommend to use 8883 together with SSL. | ||
|
||
#define MQTT_HOST "YOUR_CUMULOCITY_URL" | ||
#define MQTT_PORT 1883 | ||
|
||
//Your can get your Tenant ID from your administrator, it starts with "t", e.g. t1231231235 | ||
// Your Tenat User start with your ID and a backslah, followd by user, e.g. t2131324124/myuser | ||
|
||
#define TENANT_ID "YOUR_TENANT_ID" | ||
#define TENANT_USER "YOUR_USER" | ||
#define TENANT_PASSWORD "YOUR_PASSWORD" | ||
|
||
//The Topic for static messages with build in (e.g. battery, signalstrength etc.). If you want to use costom templates you need to use "s/uc/TEMPLATENAME" | ||
//The device ID you use for the connection will be used as identifier. If the device was not created before it will be created, but with prefix "My MQTT Device" | ||
|
||
#define TOPIC "s/us" | ||
#define DEVICE_ID "YOUR_DEVICE_ID" | ||
|
||
AsyncMqttClient mqttClient; | ||
Ticker mqttReconnectTimer; | ||
|
||
WiFiEventHandler wifiConnectHandler; | ||
WiFiEventHandler wifiDisconnectHandler; | ||
Ticker wifiReconnectTimer; | ||
|
||
void connectToWifi() { | ||
Serial.println("Connecting to Wi-Fi..."); | ||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); | ||
} | ||
|
||
void onWifiConnect(const WiFiEventStationModeGotIP& event) { | ||
Serial.println("Connected to Wi-Fi."); | ||
connectToMqtt(); | ||
} | ||
|
||
void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) { | ||
Serial.println("Disconnected from Wi-Fi."); | ||
mqttReconnectTimer.detach(); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi | ||
wifiReconnectTimer.once(2, connectToWifi); | ||
} | ||
|
||
void connectToMqtt() { | ||
Serial.println("Connecting to MQTT..."); | ||
mqttClient.connect(); | ||
} | ||
|
||
void onMqttConnect(bool sessionPresent) { | ||
Serial.println("Connected to MQTT."); | ||
Serial.print("Session present: "); | ||
Serial.println(sessionPresent); | ||
} | ||
|
||
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) { | ||
Serial.println("Disconnected from MQTT."); | ||
|
||
if (WiFi.isConnected()) { | ||
mqttReconnectTimer.once(2, connectToMqtt); | ||
} | ||
} | ||
|
||
void sendWiFiStrenght(long value){ | ||
String payload = "210," + String(value); | ||
mqttClient.publish(TOPIC,0,true,payload.c_str()); | ||
} | ||
|
||
//Creating a Critical Alarm via Payload 301 and the given Alarmtype on the build in static topic | ||
|
||
void createCriticalAlarm(String Alarmtype){ | ||
String payload = "301," + Alarmtype; | ||
mqttClient.publish(TOPIC,0,true,payload.c_str()); | ||
} | ||
|
||
//Creating a Warning via Payload 304 and the given Alarmtype on the build in static topic | ||
|
||
void createWarninglAlarm(String Alarmtype){ | ||
String payload = "304," + Alarmtype; | ||
mqttClient.publish(TOPIC,0,true,payload.c_str()); | ||
} | ||
|
||
//Events are created via 400. In this example the type of the Event is just c8y | ||
|
||
void createEvent(){ | ||
mqttClient.publish(TOPIC,0,true,"400,c8y"); | ||
} | ||
|
||
void setup() { | ||
//Starting Serialconnector | ||
Serial.begin(115200); | ||
Serial.println(); | ||
Serial.println(); | ||
|
||
wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect); | ||
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect); | ||
|
||
//MQTT | ||
mqttClient.onConnect(onMqttConnect); | ||
mqttClient.onDisconnect(onMqttDisconnect); | ||
mqttClient.setServer(MQTT_HOST, MQTT_PORT); | ||
mqttClient.setClientId(DEVICE_ID); | ||
mqttClient.setCredentials(TENANT_USER,TENANT_PASSWORD); | ||
|
||
//Connect to Wifi | ||
connectToWifi(); | ||
} | ||
|
||
void loop() { | ||
sendWiFiStrenght(WiFi.RSSI()); | ||
delay(2000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Cumulocity Example for ESP Boards | ||
This is an example for an ESP Board in order to communicate RSSI and other Data to the cumulocity platform via MQTT. Its a short example on how to implement the basic communication on a very small device or how to implement communication embedded. | ||
Cumulocity is an IoT platform that enables rapid connections of many, many different devices and applications. It allows you to monitor and respond to IoT data in real time and to spin up this capability in minutes. More information on Cumulocity IoT and how to start a free trial can be found [here](https://www.softwareag.cloud/site/product/cumulocity-iot.html#/). | ||
|
||
Cumulocity IoT enables companies to to quickly and easily implement smart IoT solutions. | ||
|
||
![Dashboard](pics/Dashboard.png) | ||
______________________ | ||
For more information you can Ask a Question in the [TECHcommunity Forums](http://tech.forums.softwareag.com/techjforum/forums/list.page?product=webmethods-io-b2b). | ||
|
||
You can find additional information in the [Software AG TECHcommunity](http://techcommunity.softwareag.com/home/-/product/name/webmethods-io-b2b). | ||
______________________ | ||
|
||
These tools are provided as-is and without warranty or support. They do not constitute part of the Software AG product suite. Users are free to use, fork and modify them, subject to the license agreement. While Software AG welcomes contributions, we cannot guarantee to include every contribution in the master project. | ||
|
||
Contact us at [TECHcommunity](mailto:technologycommunity@softwareag.com?subject=Github/SoftwareAG) if you have any questions. | ||
|
||
## ESP 8266 | ||
|
||
![ESP](pics/esp_board.jpg) | ||
|
||
The ESP8266 is a low-cost Wi-Fi microchip with full TCP/IP stack and microcontroller. | ||
The ESP-01 module allows microcontrollers to connect to a Wi-Fi network and make simple TCP/IP connections using Hayes-style commands. Since it is very cheap and has multiple in- and outputs it is very common in IoT Projects or PoC´s. | ||
|
||
## Preparation of Arduino IDE | ||
|
||
The Arduino IDE is very easy to use. | ||
![ArduinoIDE](pics/ArduinoIDE_1.png) | ||
In order to setup your Arduino IDE to work with your esp8266 arduino compatible module you need to make the following steps: | ||
|
||
1. Connect your ESP8266-01 Module to PC | ||
2. Open your Arduino IDE | ||
3. Go to File -> Preferences | ||
4. Add this link to Additional Board Manager | ||
5. Go to Tools -> Board Manager | ||
6. Find ESP8266 board set and activate it | ||
7. Select Generic ESP8266 board from Tools->Boards | ||
8. Choose your programmer COM port | ||
|
||
![ArduinoIDE Board Manager](pics/ArduinoIDE_Board_1.png) | ||
![ArduinoIDE ESP Boards](pics/ArduinoIDE_Board_2.png) | ||
|
||
## Device Creation | ||
|
||
You could either create the device in advance or just keep sending data. The device will be created if it is not registered on the platform. The Client ID of the MQTT Connector gives the Identifier within the device management. | ||
|
||
![Identifier](pics/ID.png) | ||
|
||
Additional Information regarding device creation can be found either in the examples or on the official documentation. | ||
|
||
1. [Device Creation](https://github.com/SoftwareAG/cumulocity-iot-examples/tree/master/devicecreation) | ||
2. [Cumulocity Documentation](https://cumulocity.com/guides/device-sdk/introduction/) | ||
|
||
## Example Code | ||
|
||
Within the loop() function the RSSI of the WLAN module will be send in a 2s interval. | ||
Additional functions are already implement such as creation of Events or Alarms. | ||
You can find additonal information regarding the MQTT interface on the MQTT cheat sheet or in the documentation. | ||
|
||
1. [Cheat Sheet](https://support.cumulocity.com/hc/en-us/article_attachments/360000089547/cheatsheet.pdf) | ||
2. [MQTT Interface](https://cumulocity.com/guides/device-sdk/mqtt-examples/) | ||
|
||
|
||
## Multi-product | ||
|
||
1. [Cumulocity-Freshdesk](https://github.com/SoftwareAG/webmethodsio-examples/tree/master/cumulocitytofreshdesk) | ||
1. [Cumulocity-S3](https://github.com/SoftwareAG/webmethodsio-examples/tree/master/cumulocity-s3) | ||
1. [Process EDI from Cumulocity Alarm](https://github.com/SoftwareAG/webmethods-b2b-examples/tree/master/c8y-wmio-hybrid-b2b-create-edi850) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.