Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ESP8622 AWS IoT Client
#define ESP8622
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <AmazonIOTClient.h>
#include "Esp8266AWSImplementations.h"
#include <Wire.h>
#include <MechaQMC5883.h>
Esp8266HttpClient httpClient;
Esp8266DateTimeProvider dateTimeProvider;
AmazonIOTClient iotClient;
ActionError actionError;
MechaQMC5883 qmc;
char macAddr[18];
const char *ssid = "";
const char *password = "";
void setup() {
byte mac[6];
Serial.begin(115200);
delay(500);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(300);
Serial.print(".");
}
Serial.println("WiFi connected");
Serial.println(WiFi.localIP());
WiFi.macAddress(mac);
sprintf(macAddr, "%2X:%2X:%2X:%2X:%2X:%2X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
Serial.println(macAddr);
iotClient.setAWSRegion("eu-central-1");
iotClient.setAWSEndpoint("amazonaws.com");
iotClient.setAWSDomain("");
iotClient.setAWSPath("");
iotClient.setAWSKeyID("");
iotClient.setAWSSecretKey("");
iotClient.setHttpClient(&httpClient);
iotClient.setDateTimeProvider(&dateTimeProvider);
Wire.begin();
qmc.init();
}
void loop() {
int x, y, z, head = 0;
qmc.read(&x, &y, &z);
char shadow[1024];
sprintf(shadow, "{\"state\":{\"reported\": {\"clientId\": \"%s\", \"head\": \"%i\"}}}", macAddr, head);
iotClient.update_shadow(shadow, actionError);
delay(3000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment