You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.
Wanted implementing ESP 8266 firmware update
upon receiving a command from IOT Central to device, devices would pull a .bin file from Azure storage https URL (no other security for now to keep it simple). Issue:
Not able to connect to Azure storage https endpoint through "command received" event handler
Diagnostic so far:
Steps:
to understand where is failure, moved makeHttpRequest method to before and afterconnect_client(SCOPE_ID, DEVICE_ID, DEVICE_KEY) (in code below)
used a known https url (with fingerprint hardcoded in the code) to eliminate quirks, if any, of Azure storage URLs
Observations:
https request works before connect_client(SCOPE_ID, DEVICE_ID, DEVICE_KEY), but not after. Logs as below:
Connecting to WiFi..
[HTTP] GET
[HTTP] GET code: 200
removing most HTML for brevity
hostname: iot hub host name parsed from device key by iot-central-firmware
deviceId: device id parsed from device key by iot-central-firmware
username: device id parsed from device key by iot-central-firmware
password: password parsed from device key by iot-central-firmware
[HTTP] GET
[HTTP] GET code: -1
[HTTP] GET failed, error: connection refused
reviewed code of iot-central-firmware and WiFiClient class. But not able to understand why https calls don't work after connect_client(SCOPE_ID, DEVICE_ID, DEVICE_KEY) call
Any explanation would be great.
Thanks
ESP8286 Code is like this:
#include<ESP8266WiFiMulti.h>
#include<ESP8266HTTPClient.h>
#include"src/iotc/common/string_buffer.h"
#include"src/iotc/iotc.h"
#defineWIFI_SSID your-wifi-ssid
#defineWIFI_PASSWORD your-wifi-password
constchar* SCOPE_ID = your iot-central-device-scope-id;
constchar* DEVICE_ID = your iot-central-device-id;
constchar* DEVICE_KEY = your iot-central-device-key;
voidon_event(IOTContext ctx, IOTCallbackInfo* callbackInfo);
#include"src/connection.h"voidon_event(IOTContext ctx, IOTCallbackInfo* callbackInfo)
{
// ConnectionStatusif (strcmp(callbackInfo->eventName, "Command") == 0)
{
AzureIOT::StringBuffer buffer;
if (callbackInfo->payloadLength > 0) buffer.initialize(callbackInfo->payload, callbackInfo->payloadLength);
LOG_VERBOSE("- Command name was => %s. Command Payload => %s\r\n", callbackInfo->tag,buffer.getLength() ? *buffer : "EMPTY");
makeHttpRequest();
}
}
voidmakeHttpRequest()
{
WiFiClientSecure client;
client.setFingerprint("40 af 00 6b ec 90 22 41 8e a3 ad fa 1a e8 25 41 1d 1a 54 b3");
HTTPClient http;
if (http.begin(client,"https://jigsaw.w3.org/HTTP/connection.html"))
{
Serial.print("[HTTP] GET...\n");
int httpCode = http.GET();
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
if (httpCode > 0)
{
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY)
Serial.println(http.getString());
}
else Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
http.end();
}
else Serial.printf("[HTTP} Unable to connect\n");
}
voidsetup()
{
Serial.begin(9600);
connect_wifi(WIFI_SSID, WIFI_PASSWORD);
makeHttpRequest();
connect_client(SCOPE_ID, DEVICE_ID, DEVICE_KEY);
makeHttpRequest();
if (context != NULL) lastTick = 0;
}
voidloop()
{
if (isConnected)
{
unsignedlong ms = millis();
if (ms - lastTick > 5000) //send telemetry every 5 seconds
{
char msg[128] = {0};
lastTick = ms;
int pos = snprintf(msg, sizeof(msg) - 1, "{\"Temperature\": %d, \"Humidity\": %d}",10 + (rand() % 20), 11 + (rand() % 20));
//int errorCode = iotc_send_telemetry(context, msg, pos);
msg[pos] = 0;
//if (errorCode != 0) LOG_ERROR("Sending message has failed with error code %d", errorCode);
}
iotc_do_work(context); // do background work for iotc
}
else
{
iotc_free_context(context);
context = NULL;
connect_client(SCOPE_ID, DEVICE_ID, DEVICE_KEY);
}
}
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Wanted implementing ESP 8266 firmware update
upon receiving a command from IOT Central to device, devices would pull a .bin file from Azure storage https URL (no other security for now to keep it simple).
Issue:
Not able to connect to Azure storage https endpoint through "command received" event handler
Diagnostic so far:
Steps:
Observations:
https request works before connect_client(SCOPE_ID, DEVICE_ID, DEVICE_KEY), but not after. Logs as below:
reviewed code of iot-central-firmware and WiFiClient class. But not able to understand why https calls don't work after connect_client(SCOPE_ID, DEVICE_ID, DEVICE_KEY) call
Any explanation would be great.
Thanks
ESP8286 Code is like this:
The text was updated successfully, but these errors were encountered: