Notificator

Introduction: Notificator

About: Hello, I'm working on project https://remoteme.org whcih helps You link your devices together and control them throught internet

The device can be connected for example to the IFTTT system and react when a new mail appears. At app.remoteme.org we will generate a link after calling which bytes will be sent to Arduino, and Arduino will display some light effect and play some mp3 from SDcard

Step 1: What Is Needed

  • NodeMCU, WemOS or something similar
  • Two LED rings with WS2812B diodes ( I’ve used 16th leds rings )
  • DFRobotDFPlayerMini – this is mp3 player. It plays mp3 from SDcard, and communicate with Arduino by RX/TX
  • Speaker
  • SDcard
  • Logic converter -I’ve used this one, the mp3 player uses 5V and Arduino 3.3 that’s why we need this converter
  • Knowledge and skills to make simple PCB by our selfs

The tower:

  • cardboard – two different thicknesses
  • Tracing paper
  • aluminum foil

Step 2: Tower Building

Above the plan of the tower in side view (my adventure with the technical drawing ended in primary school), all dimensions in millimeters.

Principle of operation

  1. ring of LEDs shedding light on
  2. Tracing paper
  3. The truncated cone, made of cardboard and covered with aluminum foil, so it reflects lights from led rings, in figure 3 ‘ = the cut-out mesh
  4. carton tube – holds the towers vertically, inside the tube are cables for leds
  5. The height depends on you I have 85mm
  6. The Stand inside all electronics parts

All horizontal elements should be made of thicker cardboard.

Step 3: Wiring Diagram

The mp3 player is supplied with 5V voltage and communicates with Arduino via TX / RX, a logic converter is needed because the Arduino itself works on 3.3V voltage. The control of rings is also connected to Arduino (D5, D6) through the logic converter.

At repository, You will find eagle files with PCB plans

I suggest not to solder permanently Arduino and the mp3 player only to use female goldpins

Step 4: Principle of Operation

Our Arduino connects to the app.remoteme.org system using WebSockets (there are ready libraries) through this connection 5-byte messages are sent:

  • the first byte of the light effect for the upper LED ring
  • second byte light effect for the bottom LED ring
  • the number of the mp3 file to be played
  • the number of seconds how long the light effect and the mp3 will be played
  • whether mp3 should be played once or in a loop

source code

Whole source code You can find here

in the SingleRing.cpp and SingleRing.h files there is a class to control the effects of LED rings. I suggest you start by looking at the setMode(int m) function:

void SingleRing::setMode(int m) {
switch (m) { case 0:setConfiguration(0, 0, 50, 0, 5, 1); break;//off =0 case 1:setConfiguration(6, 0, 50, 0, 0, 20); break;//solid standard green case 2:setConfiguration(6, 0, 0, 50, 0, 20); break;//solid standard blue case 3:setConfiguration(6, 50, 0, 0, 0, 20); break;//solid standard red case 4:setConfiguration(6, 50, 10, 0, 0, 20); break;//solid standard orange case 5:setConfiguration(1, 0, 100, 0, 5, 2); break;//police clockwise green case 6:setConfiguration(1, 0, 100, 0, 5, -2); break;// police revert green case 7:setConfiguration(1, 0, 0, 100, 5, 2); break;//police clockwise blue case 8:setConfiguration(1, 0, 0, 100, 5, -2); break;// police revert blue case 9:setConfiguration(1, 100, 0, 0, 5, 2); break;//police standard red case 10:setConfiguration(1, 100, 0, 0, 5, -2); break;// police revert red case 11:setConfiguration(1, 100, 20, 0, 5, 2); break;//police standard orange case 12:setConfiguration(1, 100, 20, 0, 5, -2); break;// police revert orange case 13:setConfiguration(2, 0, 0, 50, 8, 10); break;//cross standard blue case 14:setConfiguration(2, 0, 0, 50, 8, -10); break;// cross revert blue case 15:setConfiguration(5, 0, 50, 0, 0, 20); break;//blink standard green case 16:setConfiguration(5, 0, 50, 0, 0, -20); break;// blink odwyrtka green case 17:setConfiguration(5, 0, 0, 50, 0, 20); break;//blink standard blue case 18:setConfiguration(5, 0, 0, 50, 0, -20); break;// blink revert blue case 19:setConfiguration(5, 50, 0, 0, 0, 20); break;//blink standard red case 20:setConfiguration(5, 50, 0, 0, 0, -20); break;// blink revert red case 21:setConfiguration(5, 50, 10, 0, 0, 20); break;//blink standard orange case 22:setConfiguration(5, 50, 10, 0, 0, -20); break;// blink revert orange default: setConfiguration(0, 0, 50, 0, 5, 1); break;//off =0 } }

depending on the given parameter, the ring will display the effect. You can add your own effect by calling function setConfiguration with new parameters (change of color, display speed) by adding a new mode, or adding a completely new effect – or let me know in the comments if I like it I will add new effect

arduino.ino:

#include "Arduino.h"
#include "SoftwareSerial.h" #include "DFRobotDFPlayerMini.h"

#include #include #include #include "SingleRing.h"

#include #include #include

#include

#define WIFI_NAME "" #define WIFI_PASSWORD "" #define DEVICE_ID 205 #define DEVICE_NAME "siren" #define TOKEN ""

#define DIODES_COUNT 16

SingleRing top = SingleRing(DIODES_COUNT, D5); SingleRing bottom = SingleRing(DIODES_COUNT, D6);

SoftwareSerial mySoftwareSerial(D4, D3); // RX, TX DFRobotDFPlayerMini myDFPlayer; RemoteMe& remoteMe = RemoteMe::getInstance(TOKEN, DEVICE_ID);

ESP8266WiFiMulti WiFiMulti; void setup() { mySoftwareSerial.begin(9600); Serial.begin(115200);

if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3. Serial.println(F("Unable to begin:")); Serial.println(F("1.Please recheck the connection!")); Serial.println(F("2.Please insert the SD card!")); while (true); } Serial.println(F("DFPlayer Mini online."));

myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms

myDFPlayer.volume(30);

myDFPlayer.EQ(DFPLAYER_EQ_NORMAL); myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD); WiFiMulti.addAP(WIFI_NAME, WIFI_PASSWORD); while (WiFiMulti.run() != WL_CONNECTED) { delay(100); }

remoteMe.setUserMessageListener(onUserMessage);

remoteMe.setupTwoWayCommunication(); remoteMe.sendRegisterDeviceMessage(DEVICE_NAME);

top.setup(); bottom.setup(); top.clear(); bottom.clear(); }

boolean turnedOff = true; unsigned long turnOffMillis = 0;

void onUserMessage(uint16_t senderDeviceId, uint16_t dataSize, uint8_t *data) { uint16_t pos = 0; uint8_t bottomMode = RemoteMeMessagesUtils::getUint8(data, pos); uint8_t topMode = RemoteMeMessagesUtils::getUint8(data, pos); uint8_t trackNumber = RemoteMeMessagesUtils::getUint8(data, pos); uint8_t time = RemoteMeMessagesUtils::getUint8(data, pos); uint8_t mode = RemoteMeMessagesUtils::getUint8(data, pos);

bottom.setMode(bottomMode); top.setMode(topMode); if (mode == 1) { myDFPlayer.loop(trackNumber); } else { myDFPlayer.play(trackNumber); } turnedOff = false; turnOffMillis = millis() + 1000 * time; }

void loop() { remoteMe.loop(); top.loop(); bottom.loop(); if (turnOffMillis

}

explanation:

#define WIFI_NAME ""
#define WIFI_PASSWORD "" #define DEVICE_ID 205 #define DEVICE_NAME "notificator" #define TOKEN ""

We need to provide above data, detailed instructions here at the link also I’ve shown how to register in remoteme.org and generate the token,

void onUserMessage(uint16_t senderDeviceId, uint16_t dataSize, uint8_t *data) {
uint16_t pos = 0; uint8_t bottomMode = RemoteMeMessagesUtils::getUint8(data, pos); uint8_t topMode = RemoteMeMessagesUtils::getUint8(data, pos); uint8_t trackNumber = RemoteMeMessagesUtils::getUint8(data, pos); uint8_t time = RemoteMeMessagesUtils::getUint8(data, pos); uint8_t mode = RemoteMeMessagesUtils::getUint8(data, pos);

bottom.setMode(bottomMode); top.setMode(topMode); if (mode == 1) { myDFPlayer.loop(trackNumber); } else { myDFPlayer.play(trackNumber); } turnedOff = false; turnOffMillis = millis() + 1000 * time; }

This function will be called when the message comes to Arduino and displays the notification. The code is so clear that it describes itself. I refer to the details of the classes to the documentation here and here

void loop()
{ remoteMe.loop(); top.loop(); bottom.loop(); if (turnOffMillis<millis()){

if (!turnedOff) {

top.clear(); bottom.clear(); myDFPlayer.stop(); turnedOff = true; } }

In the loop, we call the loop functions of the objects, and also if the display time of notifications has passed, we turn off the diodes and sound.

Step 5: Mp3 Player

It communicates with Arduino via TX / RX – Details of the player itself here, and the library here

We upload mp3 files to the SD card. Files on the card are sorted alphabetically and then by calling:

myDFPlayer.play(5);

We play the fifth file from the SD card from the root directory. That is why it is good to give files on the SD card prefixes 01, 02 etc. In my case it looks like at the above printscreen

To generate voice commands You can use this page.

Step 6: Uploading the Program to Arduino

Before upload sketch to Arduino, You have to download needed libraries here you will find detail instructions

additionally, we need to install the DFRobotDFPlayerMini library and Adafruit_NeoPixel

Step 7: Control

We send to our Arduino five bytes

  • the first byte of the light effect for the upper LED ring
  • second byte light effect for the bottom LED ring
  • the number of the mp3 file to be played
  • the number of seconds how long the light effect and the mp3 will be played
  • whether mp3 should be played once or in a loop (1 if it should be played in a loop)

By sending bytes

07 0F 01 05 01

Top ring will be showing the police lights (mode 6) bottom one blink green (mode 15) (check out setMode function at singleRing.cpp and comments next to it). The first file form the SDcard will be played for 5 seconds. And the file will be played in the loop (check function onUserMessage at arduino.ino )

Let’s send these bytes. Look at the screen above, and click icons in order written by 1,2,3. The window appears

Then look at second screen - and fill window as at the second screen

The window that appears is used to send messages to the device. In field 1, select the sender device – because we have only one device, we select it (this is a mandatory field and it does not matter that it is the same device to which we send a message) In field 2 we give bytes to send (in red the value we entered in 2 will be represented as a string) then click the Send button.

After sending the message, our notifier should react by displaying the appropriate lighting effects and playing the selected mp3. I encourage you to try different effects by giving the first two bytes of a number between 0 and 22 (see description in the setMode function).

Step 8: Sending Messages Using URLs

If we want to display notifications from an external application eg with IFTTT, we need to have a URL that will do exactly the same thing as we did in the window in the previous step. remoteme.org provides REST APi. Go to it by clicking on the swagger tab in the left (the last one). A page will be displayed, on this page we can also try our URLs.

At the first screen You have the function You need to expand, then fill data as at the second screen.

fill in the data as in the above screenshot. After clicking the execute we will send a message

070F010501

The receiver is the device with 205 id, the same device is also a sender. MessageId with the “No_RENEVAL” settings is irrelevant. And then click Execute.
Notificator will react in the same way as when sending messages from the application. After calling REST below is the URL that was called - look at the third screen. And copy and paste to browser URL was is marked with green border. At fourth screen my chrome browser after URL was pasted

In my case, the URL is:

https://app.remoteme.org/api/*/rest/v1/message/sendUserMessageHexString/205/1/NO_RENEWAL/1/070F010501/

Step 9: Anymous URL to Send Message

At previous step You have an URL which sends data to your device. Unfortunately, after logging out of app.remoteme.org, it stops working. This is because we did not provide the authentication token, and we are no longer logged in. Let’s get our token (or create a new one) and paste it into the URL instead of the star.

Look at the screen and replace * in URL with your token

in my case token is:

~267_ZxoWtJ)0ph&2c

so my final URL looks like:

https://app.remoteme.org/api/~267_ZxoWtJ)0ph&2c/rest/v1/message/sendUserMessageHexString/205/1/NO_RENEWAL/1/070F010501/

Now we can call it even if we are not logged in. And when it is called, a message will be sent to our device 205

Step 10: Integration With IFTTT 1/7

Url created in step above is suitable for execution by external applications. How to use it I will show on the IFTTT. I will configure it so that the notifier turns on when an email comes to the email address (Gmail account).

Log in to IFTTT.Then go to the My Applets tab and then “New Applet”- first screen

Step 11: Integration With IFTTT 2/7

Next click “+this”

Step 12: Integration With IFTTT 3/7

Then in field “Search services” write “Gmail”

Then "new email in inbox" (Some configuration could be needed).

Step 13: Integration With IFTTT 4/7

now we click on “+ that”

Step 14: Integration With IFTTT 5/7

find “Webhooks” and click it

Step 15: Integration With IFTTT 6/7

then “Make a web request”

Step 16: Integration With IFTTT 7/7

we complete the URL of our url with the token. Content type to application / json and click “create action” and Finish. Now we have our applet:

Step 17: Summary

In this tutorial, I showed how to send to our Arduino messages from external systems. We also integrate some other system then IFTTT in a similar way. It does not necessarily have to be a “notificator” I wanted to show in this example how to send messages from outside systems to our Arduino.

sourcecodes
FanPage at Facebook

Cheers,
Maciek

Share

    Recommendations

    • Fix It! Contest

      Fix It! Contest
    • Metalworking Contest

      Metalworking Contest
    • Audio Contest 2018

      Audio Contest 2018

    Discussions