GithubHelp home page GithubHelp logo

zouguo-eng / esparkle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cosmicmac/esparkle

0.0 1.0 0.0 688 KB

MQTT driven visual & audio notifier, based on ESP8266.

License: MIT License

C++ 73.37% C 2.57% PHP 24.06%

esparkle's Introduction

ESParkle

MQTT driven visual & audio notifier, based on ESP8266.

Features

Audio notifications:

  • Play MP3 or RTTTL, from SPIFFS or URL.
  • Play AWS Polly TTS via a PHP companion script.

Visual notifications:

  • Display blink, pulse, sine, rainbow,... effects using a NeoPixel module.
  • When in standby mode, slowly cycle through colors.

Audio & visual notifications can be mixed.

Audio notification are fugitive, limited by the duration of the sound (i.e. won't loop), while visual notifications are persistent. This way, you can still be alerted of an event, even if you were not present during the audio notification.

And because not all events are equally important, you can affect them a different priority level: visual notifications with higher priority will persist if a lower priority notification occurs (sound notifications will always be played, whatever the priority level).

Hardware

  • ESP8266 - Wemos D1 module
  • MPU-6050 - Accelerometer and gyro module
  • NeoPixel ring (I use a basic 3 LEDs model)
  • MAX98357A - Adafruit I2S DAC module with 3W amplifier
  • 2-3W speaker
  • Eventually, 1n4148 diode*
  • Enclosure of your choice

*The NeoPixel data line voltage in logic-high state has to be at least 0.7ร— the NeoPixel power voltage (see https://ben.artins.org/electronics/glitchy-neopixels/)

Wiring

Wiring

Enclosure

A reclaimed deodorant stick makes a nifty enclosure... ;)
Enclosure

Software

ESParkle was tested with the 2.4.0 version of the Arduino libraries for ESP8266.
ESP8266 frequency must be set to 160MHz

  • In Arduino IDE, select Tools->CPU Frequency->160MHz
  • In PlatformIO, put board_f_cpu = 160000000L in your platformio.ini file

External libraries

See README of each library for specific installation instructions.

Settings

  • Rename config.h.SAMPLE into config.h and edit the settings to match your own configuration.

  • Depending on your needs, you may have to slightly tweak external libraries code.
    Here is a list of what I had to change:

    • Because JSON commands may grow fat (when mixing them, or sending RTTTL songs), you'd probably want to increase max MQTT packet size:
      In PubSubClient.h, replace
      #define MQTT_MAX_PACKET_SIZE 128 with
      #define MQTT_MAX_PACKET_SIZE 512.

    • Only if you plan to use RTTTL, and depending on your I2S DAC, you may have to decrease square wave signal amplitude to keep an acceptable volume, compared to MP3 files volume:
      In AudioGeneratorRTTTL.cpp, replace
      int16_t val = (rem > ttlSamplesPerWaveFP10/2) ? 8192:-8192; with
      int16_t val = (rem > ttlSamplesPerWaveFP10/2) ? 1024:-1024; (feel free to try different values).

Interfaces

MQTT commands

Notifications are triggered by simple JSON messages over MQTT.

Examples

- Play MP3 from URL, at reasonable volume, while displaying red pulses on NeoPixel:
  {"mp3":"http://www.dummyhost.net/esparkle/mp3/starwars.mp3","oncegain":0.4,"led":"Pulse","delay":5,"color":"0xff0000"}

- Play MP3 from SPIFFS, with a green slow sine visual effect:
  {"mp3":"/mp3/toad.mp3","led":"Sine","delay":20,"color":"0x00ff00"}

- Play RTTTL:
  {"rtttl":"starwars:d=4,o=5,b=180:8f,8f,8f,2a#.,2f.6,8d#6,8d6,8c6,2a#.6,f.6,8d#6,8d6,8c6,2a#.6,f.6,8d#6,8d6,8d#6,2c6"}

- Play TTS (via PHP companion script), with a fancy Disco visual effect and high priority:
  {"tts":"You look fantastic today","led":"Disco","priority":9}

- Blinks yellow, quite slowly, at low priority:
  {"led":"Blink","color":"0xffff00","delay":1500,"priority":1}

- Play random MP3 from online repository (via PHP companion script):
  {"mp3":"http://www.dummyhost.net/esparkle/esparkle_mp3.php?action=random"}

- Simple commands:
  {"cmd":"about"}   => display useful information about ESParkle
  {"cmd":"restart"} => restart ESP8266
  {"cmd":"break"}   => stop current notification
  {"cmd":"list"}    => list SPIFFS content
  {"gain":0.5}      => set default gain value
  {"oncegain":0.2}  => set once gain value (handy to adapt poorly encoded MP3 volume)

Tap sensor

  • 1 single tap stops current notification or, if no notification is running, plays predefined MP3 ("moo box" mode).
  • 5 taps restart ESP

Miscellaneous

To do...

  • Improve stability (ESParkle may crash/restart from time to time, when playing MP3 from URL).
  • Some code cleanup.

Tips & tricks

  • Define a MQTT retained message, with this simple command:

    {"mp3":"/mp3/bullfrog.mp3"}
    

    This way you'll get notified each time ESParkle will reconnect to the MQTTT server.

  • I created ESParkle essentially to get notified of really important events I don't want to miss at work. Incidentally, I had great success with my colleagues when I decided that the 1 tap action would randomly pick a MP3 file amongst my repository of famous movies dialogs. :)
    For kids, animals sounds should have some success as well.

Useful links

Thanks

Embedded MP3 files are courtesy of https://notificationsounds.com .

Many thanks to all the authors of above libraries, and more generally to all the generous people contributing to the ESP8266 ecosystem.

And a special thank to @earlephilhower for making ESParkle possible, including the essential RTTTL player! ;)

Disclaimer

Even if I try to improve myself, my C++ skills are very limited: I do programming like a Lego player, essentially by assembling bricks made by real programmers.
You've been warned...

For a real disclaimer, see the MIT license.

esparkle's People

Contributors

cosmicmac avatar momo90-2 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.