-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from amalabey/add-ssl-support
Enable secure MQTT support by parameterising the port number
- Loading branch information
Showing
3 changed files
with
59 additions
and
2 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,45 @@ | ||
#include <CumulocityClient.h> | ||
#ifdef ESP8266 | ||
#include <ESP8266WiFi.h> | ||
#else //ESP32 | ||
#include <WiFiClientSecure.h> | ||
#endif | ||
|
||
const char *ssid = "........"; | ||
const char *wifiPassword = "........"; | ||
char *host = "xxx.cumulocity.com"; | ||
char *username = "........"; // fixed credentials can be registered in the Administration section | ||
char *c8yPassword = "........"; // create a user in usermanagement with the "device"role and fill the credentials here | ||
char *tenant = "........"; //tenant ID can be found by clicking on your name in the top right corner of Cumulocity | ||
char *clientId = "........."; //Should be a unique identifier for this device, e.g. IMEI, MAC address or SerialNumber | ||
|
||
WiFiClientSecure wifiClient; | ||
CumulocityClient c8yClient(wifiClient, clientId); | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
Serial.print("Connecting to WiFi"); | ||
|
||
WiFi.begin(ssid, wifiPassword); | ||
while (WiFi.status() != WL_CONNECTED) | ||
{ | ||
delay(500); | ||
Serial.print("."); | ||
} | ||
Serial.println("connected to wifi"); | ||
|
||
c8yClient.connect(host, 8883, tenant, username, c8yPassword); | ||
c8yClient.registerDevice(clientId, "c8y_esp32"); | ||
} | ||
|
||
void loop() | ||
{ | ||
delay(3000); | ||
c8yClient.loop(); | ||
|
||
int8_t rssi = WiFi.RSSI(); | ||
char rssiStr[10]; | ||
sprintf(rssiStr, "%d", rssi); | ||
c8yClient.createMeasurement("SignalStrength", "T", rssiStr, "*db"); | ||
} |
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
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