-->
Page 1 of 3

Connection between esp8266 and azure iot

PostPosted: Mon Aug 03, 2020 1:21 am
by NY20200803
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);
}
}

Re: Connection between esp8266 and azure iot

PostPosted: Tue Aug 04, 2020 5:28 pm
by davydnorris
You should be able to just replace the MQTT library with the ESP8266 version. Rest is all very generic

Additional inquiry about connection between ESP8266 and AZUR

PostPosted: Wed Aug 05, 2020 6:07 am
by NY20200803
Thank you very much.

excuse me but,
In order to do the following method, the same as #include "Esp32MQTTClient.h"
If you have the ESP8266 header file
Please tell me how to get it.
Please tell me the library required to use the header.


Reason: To connect to Microsoft Azure,
if (!Esp32MQTTClient_Init((const uint8_t*)connectionString))
{
Find the part that corresponds to
This is because you need to create a program.
I haven't found the MQTT communication header for the ESP8266 that can do this, so
MQTT communication
I gave up half.

Re: Connection between esp8266 and azure iot

PostPosted: Wed Aug 05, 2020 7:32 pm
by davydnorris
There are multiple Arduino library packages so you just install it using your package manager. The libraries come with multiple examples so you will be able to easily see what to replace.

The most common one for ESP8266 seems to be the generic PubSubClient package, which works pretty well. This is the documentation: https://pubsubclient.knolleary.net/api