Have you ever had that feeling of not remembering if you locked the front door? Or perhaps caught up in the rush of the situation, you were locked out without the house keys.
More info on our blogpost: https://www.hackster.io/memento-team/memento-keys-reminder-system-07ff93
and our Github: https://github.com/memento-iot-final-project-2018-2019
2. Ever forgot to
lock your door?
MEmento is here to help you
avoid such unpleasant
situations!
Or to take the keys?
3. Finally a Twitter notification reminds
the user to lock the door
In order to stop the alert, the user has
to bring the FOB on his keyring near
the RFID reader next to the keyhole
If he is actually leaving,
a sound alert starts playing (emulated
via led)
A keys-reminder system
Through a magnetic switch, we are
able to detect if the user is leaving
4. Powered by
● STM DISCO-L475VG-IOT01A
○ One of STM’s finest pieces of hardware
○ Enabled with low-power wireless, BLE, NFC, SubGHz, Wi-Fi
○ Perfect for developing cloud-based IoT applications
● ARM Mbed OS
○ Provides API preventing IoT developers from reinventing the wheel
● AWS IoT Core
○ Easily integrated with our STM board
● Twitter
○ Used to notify the user on his mobile devices
5. Hardware components
We have to connect to our STM board a magnetic switch, used
to detect if the door is open or closed (it simply checks whether
the electric current passes or not), and an MFRC522 RFID
reader.
The MFRC522 also comes with a keyholder tag, which was
simply perfect for the user experience we designed.
6. Why not NFC?
Currently ARM Mbed hasn’t implemented any API to support its use as an
initiator in the NFC protocol. All it can do as of now is to emulate a tag, or to act
as an EEPROM, so it’s not viable for our use case.
Source: Mbed Office Hours with Donatien Garnier
7. AWS IoT Core MQTT connection (1/3)
pc.printf("Connecting to host %s:%d ...rn", MQTT_SERVER_HOST_NAME, MQTT_SERVER_PORT);
{
mqttNetwork = new MQTTNetwork(network);
int rc = mqttNetwork->connect(MQTT_SERVER_HOST_NAME, MQTT_SERVER_PORT, SSL_CA_PEM,
SSL_CLIENT_CERT_PEM, SSL_CLIENT_PRIVATE_KEY_PEM);
if (rc != MQTT::SUCCESS){
const int MAX_TLS_ERROR_CODE = -0x1000;
// Network error
if((MAX_TLS_ERROR_CODE < rc) && (rc < 0)) {
pc.printf("ERROR from MQTTNetwork connect is %d.", rc);
}
// TLS error - mbedTLS error codes starts from -0x1000 to -0x8000.
9. AWS IoT Core MQTT connection (3/3)
pc.printf("MQTT client is trying to connect the server ...rn");
{
MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
data.MQTTVersion = 3;
data.clientID.cstring = (char *)MQTT_CLIENT_ID;
data.username.cstring = (char *)MQTT_USERNAME;
data.password.cstring = (char *)MQTT_PASSWORD;
mqttClient = new MQTT::Client<MQTTNetwork, Countdown>(*mqttNetwork);
int rc = mqttClient->connect(data);
if (rc != MQTT::SUCCESS) {
pc.printf("ERROR: rc from MQTT connect is %drn", rc);
return -1;
}
}
pc.printf("Client connected.rn");
pc.printf("rn");
10. Door checking, starting alert and firing MQTT message
// IF DOOR IS OPEN
if (doorSensor.read() == 1) {
static unsigned short id = 0;
char payload[] = "{ "payload": TWITTER-ID-GOES-HERE }";
//START LED ALERT (A SOUND ALERT COULD BE IMPLEMENTED AS WELL)
led = 1;
MQTT::Message message;
message.retained = false;
message.dup = false;
const size_t buf_size = 100;
char *buf = new char[buf_size];
message.payload = (void*)buf;
message.qos = MQTT::QOS0;
message.id = id++;
int ret = snprintf(buf, buf_size, "%s", payload);
if(ret < 0) {
pc.printf("ERROR: snprintf() returns %d.", ret);
continue;
}
message.payloadlen = ret;
11. Shutting down the alert with MFRC 522
// Wait for the RFID tag to stop the alert
pc.printf("Wait alert to stoprn");
while(! (RfChip.PICC_IsNewCardPresent() || stopAlarm)) {
wait(0.5);
}
pc.printf("Alert stoppedrn");
// Reset led to off state and stopAlarm to false
led = 0;
stopAlarm = false;
// Wait until the door is closed before restarting the cycle
pc.printf("Wait for door to be closed againrn");
while(doorSensor.read() == 1) {
wait(0.5);
}
12. Send Twitter message with AWS Lambda
The MQTT message publishing acts as a trigger to an AWS
Lambda function.
We choose to use AWS Lambda because it allows us to run
the “lambda_handler” function when the MQTT request is
received and take is payload, without configuring any server.
For our purposes AWS services are provided for free and we
were able to write our function in Python, using a Twitter API
library.