Connection between esp8266 and azure iot
Posted: Mon Aug 03, 2020 1:21 am
The display of the following software has been confirmed with device explorer for connecting Azure Iot.
I want to replace this software with esp8266.
Please tell me how.
Ardino sauce
/**
* A simple Azure IoT example for sending telemetry.
*/
#include <WiFi.h>
#include "Esp32MQTTClient.h"
// Please input the SSID and password of WiFi
const char* ssid = "ssid";
const char* password = "pass";
/*String containing Hostname, Device Id & Device Key in the format: */
/* "HostName=<host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>" */
/* "HostName=<host_name>;DeviceId=<device_id>;SharedAccessSignature=<device_sas_token>" */
static const char* connectionString = "device exploler id";
static bool hasIoTHub = false;
void setup() {
Serial.begin(115200);
Serial.println("Starting connecting WiFi.");
delay(10);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
if (!Esp32MQTTClient_Init((const uint8_t*)connectionString))
{
hasIoTHub = false;
Serial.println("Initializing IoT hub failed.");
return;
}
hasIoTHub = true;
}
void loop() {
int IOTA0;
int IOTA6;
const char* ESP32A0;
IOTA0 = analogRead(A0);
IOTA6 = analogRead(A6);
//ESP32A0=(const char *)IOTA0;
Serial.println("start sending events.");
if (hasIoTHub)
{
char buff[128];
snprintf(buff, 128, "%d:%d:" ,IOTA0,IOTA6);
if (Esp32MQTTClient_SendEvent(buff))
{
Serial.println("Sending data succeed");
}
else
{
Serial.println("Failure...");
}
delay(5000);
}
}
I want to replace this software with esp8266.
Please tell me how.
Ardino sauce
/**
* A simple Azure IoT example for sending telemetry.
*/
#include <WiFi.h>
#include "Esp32MQTTClient.h"
// Please input the SSID and password of WiFi
const char* ssid = "ssid";
const char* password = "pass";
/*String containing Hostname, Device Id & Device Key in the format: */
/* "HostName=<host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>" */
/* "HostName=<host_name>;DeviceId=<device_id>;SharedAccessSignature=<device_sas_token>" */
static const char* connectionString = "device exploler id";
static bool hasIoTHub = false;
void setup() {
Serial.begin(115200);
Serial.println("Starting connecting WiFi.");
delay(10);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
if (!Esp32MQTTClient_Init((const uint8_t*)connectionString))
{
hasIoTHub = false;
Serial.println("Initializing IoT hub failed.");
return;
}
hasIoTHub = true;
}
void loop() {
int IOTA0;
int IOTA6;
const char* ESP32A0;
IOTA0 = analogRead(A0);
IOTA6 = analogRead(A6);
//ESP32A0=(const char *)IOTA0;
Serial.println("start sending events.");
if (hasIoTHub)
{
char buff[128];
snprintf(buff, 128, "%d:%d:" ,IOTA0,IOTA6);
if (Esp32MQTTClient_SendEvent(buff))
{
Serial.println("Sending data succeed");
}
else
{
Serial.println("Failure...");
}
delay(5000);
}
}