Skip to content

Instantly share code, notes, and snippets.

@dnavarrom
Created July 16, 2018 21:39
Show Gist options
  • Save dnavarrom/f43985c06b351062cfbfee56cfa46a6b to your computer and use it in GitHub Desktop.
Save dnavarrom/f43985c06b351062cfbfee56cfa46a6b to your computer and use it in GitHub Desktop.
Pushover Message API sample using Arduino Yun and Curl
/*********************************************************************************
PUSHOVER ARDUINO YUN SAMPLE
Tested on: Arduino Uno + Arduino Yun Shield (iduino)
Written by Diego Navarro M
***********************************************************************************/
#include <Bridge.h>
#include <Console.h>
#include <Process.h>
const String PUSHOVER_API_URL = "https://api.pushover.net/1/messages.json";
const String PUSHOVER_USERKEY = "KEY";
const String PUSHOVER_TOKEN ="TOKEN";
Process process;
void setup() {
Bridge.begin();
Console.begin();
}
void loop() {
// processut your main code here, to run reprocesseatedly:
callApi(10);
wait();
response();
delay(5000);
//Serial.flush();
}
void callApi(int _value) {
Console.println("API Call " + _value);
/*
curl -s \
--form-string "token=APP_TOKEN" \
--form-string "user=USER_KEY" \
--form-string "message=here is an image attachment" \
-F "attachment=@/path/to/your/image.jpg" \
https://api.pushover.net/1/messages.json
*/
process.begin("curl");
process.addParameter("-k");
process.addParameter("--form-string");
process.addParameter("token="+String(PUSHOVER_TOKEN));
process.addParameter("--form-string");
process.addParameter("user="+String(PUSHOVER_USERKEY));
/* data */
process.addParameter("--form-string");
process.addParameter("message=valor enviado : "+String(_value));
process.addParameter(PUSHOVER_API_URL);
//process.runAsynchronously();
process.run();
}
void response() {
/* Response from the request, if needed */
while (process.available()>0) {
char c = process.read();
Console.print(c);
}
}
void wait()
{
// periodically check curl process
while( !process.available() )
{
delay( 100 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment