I was able to get this working - https://www.youtube.com/watch?v=8hpro1olRK0 - send an SMS and email of temperature and humidity data from AWS IOT using esp8266 + dht11 but all of a sudden it stopped updating the shadow.
Here is the code
#include <ESP8266WiFi.h>
#include <DHT11.h>
#include <AmazonIOTClient.h>
#include <ESP8266AWSImplementations.h>
Esp8266HttpClient httpClient;
Esp8266DateTimeProvider dateTimeProvider;
AmazonIOTClient iotClient;
ActionError actionError;
const char* ssid = "";
const char* password = "";
// Pin 2 will be used to read sensor data
int pin = 2;
// Initializing the sensor
DHT11 dht11(pin);
//Function to convert Celsius to Fahrenheit
double Fahrenheit(double celsius) {
return ((celsius * 9 / 5) + 32);
}
void setup() {
Serial.begin(115200);
delay(10);
Serial.println();
// Connecting to Wi-Fi
WiFi.mode(WIFI_STA);
Serial.println();
Serial.println();
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
iotClient.setAWSRegion("us-west-2");
iotClient.setAWSEndpoint("amazonaws.com");
iotClient.setAWSDomain("al1x5kb4rzh0x.iot.us-west-2.amazonaws.com");
iotClient.setAWSPath("$aws/things/esp8266/shadow/update/accepted");
iotClient.setAWSKeyID("AKIAJJQ6ASLIDIPBE4PQ");
iotClient.setAWSSecretKey("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");
iotClient.setHttpClient(&httpClient);
iotClient.setDateTimeProvider(&dateTimeProvider);
}
void loop() {
int err;
float temp, humi;
//Reading the sensor data
if ((err = dht11.read(humi, temp)) == 0) {
Serial.print(" temperature:");
Serial.print(temp);
Serial.print(" humidity:");
Serial.print(humi);
Serial.println();
} else {
Serial.println();
Serial.print(" Error No :");
Serial.print(err);
Serial.println();
}
// Converting the float data to char arrays
char sTemp[10], sHumi[10];
dtostrf(humi, 6, 2, sHumi);
dtostrf(temp, 6, 2, sTemp);
// Creating the thing shadow to be sent to aws iot
char shadow[100];
strcpy(shadow, "{\"state\":{\"reported\": {\"Humidity\":");
strcat(shadow, sHumi);
strcat(shadow, ", \"Temperature\":");
strcat(shadow, sTemp);
strcat(shadow, "}}}");
Serial.print(shadow);
char* result = iotClient.update_shadow(shadow, actionError);
Serial.print(result);
delay(60000);
}
Output as expected
Connecting to
NETGEAR53
.........
WiFi connected
temperature:31.00 humidity:32.00
{"state":{"reported": {"Humidity": 32.00, "Temperature": 31.00}}}al1x5kb4rzh0x.iot.us-west-2.amazonaws.com
443
POST $aws/things/esp8266/shadow/update/accepted HTTP/1.1
Content-Type: application/json
Connection: close
Content-Length: 65
Host: al1x5kb4rzh0x.iot.us-west-2.amazonaws.com
x-amz-content-sha256: 923ed1ae613a9e14b45e4d080b092daf5cf61118041dc5225956299d5b0f8d49
x-amz-date: 20180323T034259Z
Authorization: AWS4-HMAC-SHA256 Credential=AKIAJJQ6ASLIDIPBE4PQ/20180323/us-west-2/iotdata/aws4_request,SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date,Signature=a10f0969043e609743412478567c10290b8c000185f2824e4a9cf07bb96cf279
{"state":{"reported": {"Humidity": 32.00, "Temperature": 31.00}}}
-
#include <ESP8266WiFi.h> #include <DHT11.h> #include <AmazonIOTClient.h> #include <ESP8266AWSImplementations.h> Esp8266HttpClient httpClient; Esp8266DateTimeProvider dateTimeProvider; AmazonIOTClient iotClient; ActionError actionError;Susindran Srinivasan– Susindran Srinivasan2018年03月23日 03:51:21 +00:00Commented Mar 23, 2018 at 3:51
-
A small correction on the output, sometimes its perfect but some other times i get timeout receiving time server data {"state":{"reported": {"Humidity": 41.00, "Temperature": 31.00}}}al1x5kb4rzh0x.iot.us-west-2.amazonaws.com 443 POST /things/ESP/shadow HTTP/1.1 ------------------------ {"state":{"reported": {"Humidity": 41.00, "Temperature": 31.00}}}timeout receiving timeserver dataSusindran Srinivasan– Susindran Srinivasan2018年03月24日 03:15:15 +00:00Commented Mar 24, 2018 at 3:15
-
1I am also facing the same problem and still, I didn't get any answer...current I am also working on thatSoumen Nayak– Soumen Nayak2018年10月24日 12:49:09 +00:00Commented Oct 24, 2018 at 12:49
-
Anyone get this solved? I have the same issueDavid Glass– David Glass2019年06月30日 12:26:04 +00:00Commented Jun 30, 2019 at 12:26
-
I am planning to try cleaning the AWSiot libraries, that worked last time but again only one device works for me as of now. Probably I might try a different set of code. Please share your code guys -- I will try to help. Also I am trying different AWS keys.Susindran Srinivasan– Susindran Srinivasan2019年07月01日 13:28:26 +00:00Commented Jul 1, 2019 at 13:28
2 Answers 2
I was facing a similar problem: trying to update a thing's shadow on AWS IoT with no success. After some research, I found out that I was using an outdated library. In this question they advise to use heskew's aws-sdk-arduino
, on iot-get-shadow-and-cleanup
branch:
https://github.com/heskew/aws-sdk-arduino/tree/iot-get-shadow-and-cleanup.
Additionally, I think you have a little error on your code. As far as I know, AWSPath
, it should look like:
iotClient.setAWSPath("/things/esp8266/shadow");
At least that works for me, and they use it this way on this video.
That's all I can tell... I am learning at this moment as well. Hope it helps!!
-
Thank you so much for your response, really appreciate it. My thing name is actually ESP so i have it set as ---iotClient.setAWSPath("/things/ESP/shadow");--- or should it only be esp8266? i deleted old libraries and used the one above but still my thing shadow is not updating. Please help. The other example video you referred - that also is not workingSusindran Srinivasan– Susindran Srinivasan2018年04月04日 04:40:45 +00:00Commented Apr 4, 2018 at 4:40
-
arduino.stackexchange.com/questions/51059/…Susindran Srinivasan– Susindran Srinivasan2018年04月04日 06:23:34 +00:00Commented Apr 4, 2018 at 6:23
Just Change the Aws topic : it should be $aws/things/esp8266/shadow/update
and you have to add the certificate path also