Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Majed Abouhatab, P.E.
Published © LGPL

Wio Terminal Publishing MQTT Messages To AWS

Simple Arduino IDE sketch to send Wio Terminal data to Amazon Web Services.

IntermediateFull instructions provided2 hours777

Things used in this project

Hardware components

Wio Terminal
Seeed Studio Wio Terminal
×1

Software apps and online services

Arduino IDE
Arduino IDE
ezgif.com

Story

Read more

Schematics

Wiring

Code

WioTerminalAWS.ino

Arduino
#include "rpcWiFi.h"
#include <WiFiClientSecure.h>
#include <MQTTClient.h>
#include "secrets.h"

WiFiClientSecure net;
MQTTClient mqtt;

void setup() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) yield();
  net.setCACert(AWS_CERT_CA);
  net.setCertificate(AWS_CERT_CRT);
  net.setPrivateKey(AWS_CERT_PRIVATE);
  mqtt.begin(AWS_IOT_ENDPOINT, 8883, net);
}

void loop() {
  while (!mqtt.connect(THINGNAME)) yield();
  mqtt.publish(topic, payload);
  delay(30000);
}

secrets.h

Arduino
#define THINGNAME "WioTerminal"
#define topic "PubTopic"
#define payload "{\"millis\": " + String(millis()) + "}"
#define ssid "..."
#define password  "..."
#define AWS_IOT_ENDPOINT "..."

// Amazon Root CA 1
static const char AWS_CERT_CA[] PROGMEM = R"EOF(
-----BEGIN CERTIFICATE-----
.
.
.
-----END CERTIFICATE-----
)EOF";

// Device Certificate
static const char AWS_CERT_CRT[] PROGMEM = R"KEY(
-----BEGIN CERTIFICATE-----
.
.
.
-----END CERTIFICATE-----
)KEY";

// Device Private Key
static const char AWS_CERT_PRIVATE[] PROGMEM = R"KEY(
-----BEGIN RSA PRIVATE KEY-----
.
.
.
-----END RSA PRIVATE KEY-----
)KEY";

platformio.ini

INI
; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:seeed_wio_terminal]
platform = atmelsam
board = seeed_wio_terminal
framework = arduino
lib_deps = 
	seeed-studio/Seeed Arduino rpcWiFi@^1.0.5
	seeed-studio/Seeed Arduino rpcUnified@^2.1.3
	seeed-studio/Seeed Arduino FS@^2.1.1
	seeed-studio/Seeed_Arduino_mbedtls@^3.0.1
	256dpi/MQTT@^2.5.0

Credits

Majed Abouhatab, P.E.
54 projects • 40 followers
Electronics Professional Engineer, Pilot, Skydiver, Runner, and World Traveler.

Comments