Created
November 6, 2019 16:51
-
-
Save MikeBild/45a6f13c582a59bfd9e6da30e162b69a to your computer and use it in GitHub Desktop.
ESP8622 AWS IoT Client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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