Page 2 of 2

Re: Pushafer Arduino error

Posted: 11. Nov 2021, 11:57
by norris2022
Hey.
After a lot of mucking around and half from the content in this thread, I have mine working.

viewtopic.php?f=24&t=3215

Please see the code below.

I am using an Arduino UNO with PoE Ethernet Shield

Code: Select all

/*
   Pushsafer.ino
   Pushsafer.com sketch by Appzer.de Kevin Siml 2016-08-08
   Send pushsafer.com messages from the arduino
*/
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {0xDE,0xAC,0xBF,0xEF,0xFE,0xAA};

// pushsafer settings
char privatekey[] = "your20characterPrivateKey";
int length;
EthernetClient client;

void setup()
{
  Serial.begin(9600);
  Serial.print(F("Starting ethernet..."));
  if(!Ethernet.begin(mac)) Serial.println("failed");
  else Serial.println(Ethernet.localIP());
  delay(5000);
  Serial.println("Ready");
}

void loop()
{
  pushsafer("It works!!!","Test","1","1","1","a");  
  delay(60000); 
}
byte pushsafer(char *pushsafermessage, char *pushsafertitle, char *pssound, char *psvibration, char *psicon, char *psdevice)
{
  String title = pushsafertitle;
  String message = pushsafermessage;
  String device = psdevice;
  String sound = pssound;
  String vibration = psvibration;
  String icon = psicon;

  length = 41 + message.length() + title.length() + sound.length() + vibration.length() + icon.length() + device.length() + privatekey.length();

  if(client.connect("pushsafer.com",80))
  {
    client.println("POST /api HTTP/1.1");
    client.println("Host: www.pushsafer.com");
    client.println("Connection: close\r\nContent-Type: application/x-www-form-urlencoded");
    client.print("Content-Length: ");
    client.print(length);
    client.println("\r\n");;
    client.print("k=");
    client.print(privatekey);
    client.print("&m=");
    client.print(message);
    client.print("&t=");
    client.print(title);  
    client.print("&s=");
    client.print(sound);
    client.print("&v=");
    client.print(vibration);  
    client.print("&i=");
    client.print(icon);
    client.print("&d=");
    client.print(device); 
    client.print("&retry=60");
    client.print("&expire=3600");
    while(client.connected())  
    {
      while(client.available())
      {
        char ch = client.read();
        Serial.write(ch);
      }
    }
    client.stop();
  }  
}

Re: Pushafer Arduino error

Posted: 11. Nov 2021, 13:18
by admin
thanks for sharing your code.

Kevin

Re: Pushafer Arduino error

Posted: 11. Nov 2021, 15:59
by norris2022
Hi Kevin
I'm now trying to get this code to be run when a button is pushed but I cant figure out how to run the code after an if statement is true, I keep getting the error of " 'push safer' was not declared in this scope."

Re: Pushafer Arduino error

Posted: 12. Nov 2021, 08:59
by admin
sorry, i cant help you.
It's better to ask your question in a arduino board.

Kevin