Devices & Components
Shelly 1
USB-TTL serial adapter
Hardware & Tools
10 Pc. Jumper Wire Kit, 5 cm Long
Breadboard, 170 Pin
Software & Tools
Arduino IoT Cloud
Project description
Code
Arduino sketch for Shelly 1
arduino
Copy and paste this code in the web interface of the IoT Cloud.
1#include "thingProperties.h" 2#include <TOTP.h> 3#include <NTPClient.h> 4#include <WiFiUdp.h> 5 6// OTP configuration 7uint8_t hmacKey[] = {0x2, 0x63}; 8constexpr int keySize = 2; 9 10TOTP totp = TOTP(hmacKey, keySize); 11WiFiUDP ntpUDP; 12NTPClient timeClient(ntpUDP, "time.ien.it"); 13 14constexpr int SHELLY_RELAY = 4; 15 16void setup() { 17 // Connect to Arduino IoT Cloud 18 initProperties(); 19 ArduinoCloud.begin(ArduinoIoTPreferredConnection); 20 21 // Initialize variables and pins 22 access_code = ""; 23 pinMode(SHELLY_RELAY, OUTPUT); 24 digitalWrite(SHELLY_RELAY, LOW); 25} 26 27void loop() { 28 ArduinoCloud.update(); 29} 30 31// Handle incoming messages 32void onAccessCodeChange() { 33 if (access_code == "") return; 34 35 timeClient.update(); 36 unsigned long now = timeClient.getEpochTime(); 37 String correct_code = totp.getCode(now); 38 39 if (access_code == correct_code) { 40 digitalWrite(SHELLY_RELAY, HIGH); 41 delay(700); 42 digitalWrite(SHELLY_RELAY, LOW); 43 access_code = "Door open!"; 44 } else { 45 access_code = "Invalid code"; 46 } 47} 48 49
Downloadable files
Wiring (only for programming)
Wiring (only for programming)

Comments
Only logged in users can leave comments