I'm a new user. I'm not that familiar with Arduino like programming as I've been using MikrobasicPro for Pic32. My main reason for purchasing the core/Photon, is to find a way to send a notification email from my projects. (A surprisingly hard thing to do)
I've tried the different PushingBox examples found on the forum with disappointment.
My core is connected, breathing cyan and I'm able to flash the programs both from Spark Dev and from the Web.
I'm able to connect the serial window in SparkDev to debug this program:
/*
kid-summoner.ino
On pressing a button, a tweet is sent via Pushingbox
Written for the Spark Core
*/
int inputPin = D1; //push-button pin
int val = 0; //variable for push-button status
int state = 1; //variable for on/off state
const char * DEVID = "vC1efg12334567"; // Scenario: "Tweet"
const char * serverName = "[api.pushingbox.com](http://api.pushingbox.com)"; // Pushingbox API URL
TCPClient client;
void setup() {
pinMode(inputPin, INPUT);
Serial.begin(9600);
}
void loop() {
val = digitalRead(inputPin); //read the state of the push-button
if (val == LOW) { //if push-button pressed
state = !state; //reverse on/off state
delay(250); //primitive button debounce
Serial.println("button pushed!");
sendToPushingBox(DEVID);
}
}
void sendToPushingBox(const char * devid)
{
client.stop();
if (client.connect(serverName, 80)) {
client.print("GET /pushingbox?devid=");
client.print(devid);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(serverName);
client.println("User-Agent: Spark");
client.println();
client.flush();
}
else{
Serial.println("connection failed");
}
}
No solution to the current issue, but definitely an alternative worth looking into: IFTTT. Recently Spark OS started supporting IFTTT, opening a lot more possibilities. You can use this to send mails for you on a certain trigger. You can also use it to trigger one of many other triggers. Pushing box officially isn’t one of them, but you can use it regardless. Follow this guide, provided by pushingbox, and you should be able to use it with IFTTT. If you’re only goal is to send an email, you can skip the pushingbox part, and have it mail you directly.
If using IFTTT, the code on your Core can also be simplified quite a bit, since you’d only need a Spark.publish, and no external libraries.
Anyhow, give it a try, and let me know if that worked for you. Perhaps some other folks can take a look at your current code so see why it might not be working.
at the suggestion of @Hootie81, I have been using these functions to handle the return of an HTTP call and it works to send to PushingBox. I have it like this:
int inputPin = D1; //push-button pin
int val = 0; //variable for push-button status
int state = 1; //variable for on/off state
int led = D7; // integrated LED
void setup() {
pinMode(inputPin, INPUT);
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop() {
val = digitalRead(inputPin); //read the state of the push-button
if (val == LOW) { //if push-button pressed
state = !state; //reverse on/off state
delay(250); //primitive button debounce
Serial.println("button pushed!");
digitalWrite(led, HIGH); // Turn ON the LED pins
notification();
}
}
void notification()
{
delay(1000);
Spark.publish("button1",NULL, 60, PRIVATE);
//
Serial.println("Complete");
//
digitalWrite(led, LOW); // Blink LED
delay(250);
digitalWrite(led, HIGH);
delay(250);
digitalWrite(led, LOW);
}
Out of curiosity,
how does one detect if an IFTTT request does not get published?
Thanks very much,
Stuart
I’ve edited your post to properly format the code. Please check out this post, so you know how to do this yourself in the future. Thanks in advance! ~Jordy