Garage Door Monitor and Opener

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Introduction

This system implements a simple garage door opener and environmental monitor. The hardware connects to the internet using Wi-Fi then on to the Pelion Device Management Platform which provides device monitoring and secure firmware updates over the air (FOTA). Pelion Device Management provides a flexible set of REST APIs which we will use to communicate to a web application running on an EC-2 instance in AWS. The web application will serve a web page where we can monitor and control our garage..

This project is intended to work on the DISCO-L475VG-IOT01A from ST Microelectronics It implements a simple actuator to drive a relay to simulate pushing the "open" button on older style garage doors which do not use a rolling code interface.

The system is designed to be mounted over the door so that the on board time of flight sensor can be used to detect if the door is open or closed.

The system also monitors temperature, humidity and barometric pressure.

https://os.mbed.com/media/uploads/JimCarver/garageopener.jpg

Hardware Requirements:

DISCO-L475G-IOT01A https://os.mbed.com/platforms/ST-Discovery-L475E-IOT01A/

Seeed Studio Grove Relay module https://www.seeedstudio.com/Grove-Relay.html

Seeed Studio Grove cable, I used this one: https://www.seeedstudio.com/Grove-4-pin-Male-Jumper-to-Grove-4-pin-Conversion-Cable-5-PCs-per-Pack.html

Connect to the PMOD connector like this:

https://os.mbed.com/media/uploads/JimCarver/opener.jpg

This shows how I installed so that the time of flight sensor can detect when the door is open

https://os.mbed.com/media/uploads/JimCarver/opener1.jpg https://os.mbed.com/media/uploads/JimCarver/opener2.jpg

To use the project:

You will also need a Pelion developers account.

I suggest you first use the Pelion quick state to become familiar with Pelion Device Management. https://os.mbed.com/guides/connect-device-to-pelion/1/?board=ST-Discovery-L475E-IOT01A

Web Interface

For my web interface I am running node-red under Ubuntu in an EC2 instance on AWS. This can run for 12 month within the constraints of their free tier. Here is a tutorial: https://nodered.org/docs/getting-started/aws

You will also need to install several node-red add ons:

sudo npm install -g node-red-dashboard

sudo npm install -g node-red-contrib-mbed-cloud

sudo npm istall -g node-red-contrib-moment

After starting node-red import the contents of GarageFlow.txt from the project, pin the flow into the page.

To enable your web app to access your Pelion account you need an API key.

First you will neet to use your Pelion account to create an API key.

https://os.mbed.com/media/uploads/JimCarver/api_portal.jpg

Now we need to apply that API key to your Node-Red flow.

https://os.mbed.com/media/uploads/JimCarver/api_node-red.jpg

Revision:
29:6ff737b67e7d
Parent:
28:0e774865873d
Child:
30:15743b79c6cb
--- a/main.cpp	Mon Mar 04 22:11:02 2019 +0000
+++ b/main.cpp	Thu Mar 07 15:39:45 2019 +0000
@@ -48,7 +48,7 @@
 // Default block device
 BlockDevice* bd = BlockDevice::get_default_instance();
 SlicingBlockDevice sd(bd, 0, 2*1024*1024);
-LittleFileSystem fs("fs", &sd);
+LittleFileSystem fs("fs");
 
 // Default User button for GET example
 InterruptIn button(BUTTON1);
@@ -95,7 +95,7 @@
  * @param newValue Updated value for the resource
  */
 void led_put_callback(MbedCloudClientResource *resource, m2m::String newValue) {
-    printf("PUT received, new value: %s\n", newValue.c_str());
+    printf("*** PUT received, new value: %s                             \n", newValue.c_str());
     led = atoi(newValue.c_str());
 }
 
@@ -107,7 +107,7 @@
  * @param size Size of the body
  */
 void led_post_callback(MbedCloudClientResource *resource, const uint8_t *buffer, uint16_t size) {
-    printf("POST received. Payload: %s\n", res_led->get_value().c_str());
+    printf("*** POST received. Payload: %s                              \n", res_led->get_value().c_str());
     led = atoi(res_led->get_value().c_str());
 }
 
@@ -117,7 +117,7 @@
 void button_press() {
     int v = res_button->get_value_int() + 1;
     res_button->set_value(v);
-    printf("Button clicked %d times                                \n", v);
+    printf("*** Button clicked %d times                                 \n", v);
 }
 
 /**
@@ -126,7 +126,7 @@
  * @param status The delivery status of the notification
  */
 void button_callback(MbedCloudClientResource *resource, const NoticationDeliveryStatus status) {
-    printf("Button notification, status %s (%d)\n", MbedCloudClientResource::delivery_status_to_string(status), status);
+    printf("*** Button notification, status %s (%d)                     \n", MbedCloudClientResource::delivery_status_to_string(status), status);
 }
 
 /**
@@ -142,8 +142,9 @@
  * Initialize sensors
  */
 void sensors_init() {
-    uint8_t id;
+    uint8_t id1, id2, id3, id4;
 
+    printf ("\nSensors configuration:\n");
     // Initialize sensors
     sen_hum_temp.init(NULL);
     sen_press_temp.init(NULL);
@@ -154,21 +155,18 @@
     /// Call sensors enable routines
     sen_hum_temp.enable();
     sen_press_temp.enable();
-    //sen_mag.enable();
     sen_acc_gyro.enable_x();
     sen_acc_gyro.enable_g();
 
-    printf("\033[2J\033[20A");
-    printf ("\nSensors configuration:\n");
+    sen_hum_temp.read_id(&id1);
+    sen_press_temp.read_id(&id2);
+    sen_mag.read_id(&id3);
+    sen_acc_gyro.read_id(&id4);
 
-    sen_hum_temp.read_id(&id);
-    printf("HTS221  humidity & temperature    = 0x%X\n", id);
-    sen_press_temp.read_id(&id);
-    printf("LPS22HB pressure & temperature    = 0x%X\n", id);
-    sen_mag.read_id(&id);
-    printf("LIS3MDL magnetometer              = 0x%X\n", id);
-    sen_acc_gyro.read_id(&id);
-    printf("LSM6DSL accelerometer & gyroscope = 0x%X\n", id);
+    printf("HTS221  humidity & temperature    = 0x%X\n", id1);
+    printf("LPS22HB pressure & temperature    = 0x%X\n", id2);
+    printf("LIS3MDL magnetometer              = 0x%X\n", id3);
+    printf("LSM6DSL accelerometer & gyroscope = 0x%X\n", id4);
 
     printf("\n"); ;
 }
@@ -234,11 +232,18 @@
 int main(void) {
     printf("\nStarting Simple Pelion Device Management Client example\n");
 
-    // If the User button is pressed ons start, then format storage.
-    if (button.read() == MBED_CONF_APP_BUTTON_PRESSED_STATE) {
-        printf("User button is pushed on start. Formatting the storage...\n");
-        bd->erase(0, bd->size());
-        int storage_status = fs.reformat(&sd);
+    int storage_status = fs.mount(&sd);
+    if (storage_status != 0) {
+        printf("Storage mounting failed.\n");
+    }
+    bool btn_pressed = (button.read() == MBED_CONF_APP_BUTTON_PRESSED_STATE);
+    if (btn_pressed) {
+        printf("User button is pushed on start...\n");
+    }
+    if (storage_status || btn_pressed) {
+        printf("Formatting the storage...\n");
+        sd.erase(0, sd.size());
+        storage_status = fs.reformat(&sd);
         if (storage_status != 0) {
             if (sd.erase(0, sd.size()) == 0) {
                 if (fs.format(&sd) == 0) {