GithubHelp home page GithubHelp logo

tgjohnst / crush-ping Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 539 KB

A cute little IoT device which receives and prints messages.

C++ 95.47% JavaScript 4.53%
arduino hardware iot particle printer twilio

crush-ping's Introduction

crush-ping

A cute little IoT device which receives and prints messages.

Designed as a gift, this was a nice exercise in expanding my Arduino and Twilio knowledge.

Crushping final form

What it does

The device sits idle, blinking every 15 seconds to let the user know it's working, until a message comes in (via text message). Upon receipt of a message, the button lights up solid red to let the user know something is waiting. When the button is pressed, the message is printed from the thermal printer.

Hardware

Firmware logic

Setup

The firmware (crushping.ino) establishes a cloud function that acts as a message listener. The cloud function exposes a webhook thanks to Particle's magic, which is targeted by the twilio function (crushping.js). The device sets up a string buffer of 145 characters (bytes) which will store the most recently received message (sorry, no message queue in this implementation). It also establishes a debounce() object attached to the button's input pin, which smooths out electrical noise and unambiguously detects actual button presses. It sets a hasMessage boolean so we don't have to keep checking every loop if the contents of the message buffer are empty.

Runtime

Message handling

When a message is received, we truncate it to 145 characters and place it in our buffer, set hasMessage to true, then send a message-received event to the cloud to log successful receipt.

Main loop

If a message is waiting, we simply keep the LED on until the button is pressed. If no message is waiting, we flash the LED every 15 seconds as a heartbeat. If the button is pressed, we log a button-pressed event to the cloud, but nothing else happens if no message is in the buffer.

Message printing

If a message is in the buffer when the button is pressed, we print the message (including XOXO lines above and below and some extra space to make the printout easy to tear off) and register a message-printed event to the cloud. We then clear the message buffer and set hasMessage back to false.

Dependencies

Twilio configuration

The twilio function is based on LoveNotes by Alex Swan. Thank you, Alex!

Function Configuration

Updated

Create a service called crushping.

Add the function in crushping.js to twilio's Functions list and save it.

The private assets PARTICLE_ACCESS_TOKEN and PARTICLE_DEVICE_ID must be added in Functions -> Configure -> Environment Variables. The access token has to be generated either through the CLI or via the web form at this particle docs link Your device ID can be retrieved via Particle IDE -> Devices -> {Device Name} .

Add a dependency, in addition to the defaults, request == 2.88.0. Others may also be automatically applied, including xmldom==0.1.27 and lodash==4.17.11.

Click Deploy All in the service console.

Configuring function routing

In Twilio, select your phone number (you probably configured a free one upon signup) at Phone Numbers -> Manage -> Active Numbers -> {Number}. Under Messaging, select your crushping service, select Function and apply the /crushping function when a message comes in. Save and exit.

image

References and inspirations

https://docs.particle.io/getting-started/integrations/webhooks/

https://docs.particle.io/reference/device-os/api/cloud-functions/particle-publish/

https://www.hackster.io/gatoninja236/2-way-particle-photon-communication-011f02

https://docs.particle.io/reference/device-os/api/string-class/reserve/

https://github.com/thomasfredericks/Bounce2

https://particle.hackster.io/middleca/sending-sound-over-the-internet-f097b4

crush-ping's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

simaerdem

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.