I have spent the whole day trying to get my head around how to achieve a proof of principle example for a university project I am working on. (I’m a Product Design Ba student so i’m not familiar with the coding environment)
I am using a Node MCU esp12e module coded via the arduino IDE.
So far I have managed to use provided examples to send push notifications to my Ipad when the device goes offline, and have used the button widget to turn an LED off and on.
What I would like to do is use a physical button to trigger a notification/email to show the user an image or document containing the broken down instructions for the activity they are trying to achieve such as brushing their teeth.
At the very least for the proof of principle I would like to press the physical button and get a push notification to my ipad saying “image of target activity”
Below is what I have so far: (apologies is this is not the correct format.)
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SPI.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "ceb6327ec******82060f0e4f889f";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "TP-LI******CB1A";
char pass[] = "01*****635";
WidgetLED led1(V1);
void checkPin()
{
// Invert state, since button is "Active LOW"
if (digitalRead(2)) {
led1.off();
} else {
led1.on();
}
}
void notifyOnButtonPress()
{
// Invert state, since button is "Active LOW"
int isButtonPressed = !digitalRead(2);
if (isButtonPressed) {
Serial.println("Button is pressed.");
// Note:
// We allow 1 notification per 15 seconds for now.
Blynk.notify("Yaaay... button is pressed!");
}
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// Make pin 2 HIGH by default
pinMode(2, INPUT_PULLUP);
// Setup notification button on pin 2
pinMode(2, INPUT_PULLUP);
// Attach pin 2 interrupt to our handler
attachInterrupt(digitalPinToInterrupt(2), notifyOnButtonPress, CHANGE);
}
void loop()
{
Blynk.run();
}
You can send images via Blynk but neither are straightforward.
A. Set up a separate server with the images and get Blynk to send them to you.
or
B. Use something like a Raspberry Pi rather than an ESP and send the images via a simple shell command via the Blynk node client. Requires some knowledge of javascript and basic Linux commands.
We have used both systems but we were actually taking snapshots via Blynk and emailing the snapshot to ourselves. Easier for you as you have static images.
With A it would be possible to store the images in SPIFFS on the ESP but I can’t think of an easy way of actually emailing them on request.
One could try and fiddle with the Video widget. I think it should be possible to stream a static image instead of a video I guess.
I’m just not sure how to work that in practice since I’ve never used the video widget before. You could setup some sort of VLC streaming server streaming a couple of pictures and send those to the App.
Yeah this is exactly what I’m looking to do, where low cost buttons with an icon could be placed at ‘pressure’ points. I’d seen the amazon dash buttons and assumed it would be easy to do an iot trigger button to open an image on an iPad, but forgot that I don’t know how to code :P.
here is the example render of how I image the scene
Ok, i’m making progress, i had been forgetting that the NODE MCU dev board has the pins labelled differently on the board than in the arduino IDE… now that thats sorted I am using the email service to send an email when the button is pressed.
is there a way of embedding an image in the email or will i have to use a link to an image hosted on a url or similar.
also i seem to be getting a notification saying the device is offline when i press the button which is a little confusing since it sends the email correctly and I can’t see anything in the IDE code???
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "ceb6327ecd8144*****f0e4f889f";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "TP-LI***CB1A";
char pass[] = "01****35";
void emailOnButtonPress()
{
// *** WARNING: You are limited to send ONLY ONE E-MAIL PER 15 SECONDS! ***
// Let's send an e-mail when you press the button
// connected to digital pin 2 on your Arduino
int isButtonPressed = !digitalRead(2); // Invert state, since button is "Active LOW"
if (isButtonPressed) // You can write any condition to trigger e-mail sending
{
Serial.println("Button is pressed."); // This can be seen in the Serial Monitor
Blynk.email("danieljrock@me.com", "Subject: Button Logger", "You just pushed the button...");
// Or, if you want to use the email specified in the App (like for App Export):
//Blynk.email("Subject: Button Logger", "You just pushed the button...");
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
// Send e-mail when your hardware gets connected to Blynk Server
// Just put the recepient's "e-mail address", "Subject" and the "message body"
Blynk.email("your_email@mail.com", "Subject", "My Blynk project is online.");
// Setting the button
pinMode(2, INPUT_PULLUP);
// Attach pin 2 interrupt to our handler
attachInterrupt(digitalPinToInterrupt(2), emailOnButtonPress, CHANGE);
}
void loop()
{
Blynk.run();
Because ESP boards seem particularly sensitive to communication timing, my guess is that your physical button on an interrupt might be experiencing contact bounce… thus causing the interruption just long enough for the communication error.
I was thinking of a more elegant solution in the form of streaming, like a regular webcam, but with stills. That way you don’t have to build a moving thing
What? VLC is so 2016, we need to blynkify a zoetrope, like right now!
I agree… I think an image widget (or a modification of the video widget) that can easily display common image formats is not a bad idea. Previously mentioned security snaps when a sensor goes off, pictograms or other custom messages that a person may wish to display instead of basic text (as in this case), even mini maps showing a floor plan location of a tripped sensor, etc… basicly if you can find it, draw it or capture a still frame of it, then when triggered, the widget can display the chosen image file from a dropbox, SD card or even a folder on the server itself.
I have been making progress with the project and have now got the notification being triggered by a button press. I am hosting an example an image in drop box. The link is showing up in the notification but is not acting like a hyperlink. is there a way to make this happen do i need to add some symbols in the code?