arduino pushsafer can't compile

Pushsafer make it easy and safe to get push-notifications in real time on your Android or Windows mobile device, iPhone, iPad and Desktop!

Mit Pushsafer kann man in Echtzeit, einfach und sicher, Push-Benachrichtigungen auf sein iPhone, iPad, Android oder Windows Gerät sowie auf den Desktop senden lassen!

======================
Google Play
App Store
Windows Store
Homepage
robomaniac

arduino pushsafer can't compile

Postby robomaniac » 7. Jan 2017, 17:54

Hey Kevin

I have a hard time to compile your code on github for the arduino example.
Ok if I compile on "arduino ethernet" I get difference error then when I compile for "ESP8266 thing" from sparkfun.

github.com/appzer/arduino-pushsafer/blob/master/Pushsafer.ino

but before I start, should line #46 have the /api in the url?

Code: Select all

client.println("Host: https://www.pushsafer.com");
be

Code: Select all

client.println("Host: https://www.pushsafer.com/api"); <---- adding /API at the end of the URL?
the compile error I have are with the length.
is the length important? Can I not send it?

Code: Select all

length = 30 + message.length() + title.length() + sound.length() + vibration.length() + icon.length() + device.length() + url.length() + urltitle.length() + time2live.length() + privatekey.length();
I use this instead

Code: Select all

length = 30 + sizeof(message) + sizeof(title) + sizeof(sound) + sizeof(vibration) + sizeof(icon) + sizeof(device) + sizeof(url) + sizeof(urltitle) + sizeof(time2live) + sizeof(privatekey);
basically, I need to generate this link to then send it.

Code: Select all

https://www.pushsafer.com/api?k=your20characterPrivateKey&d=a&i=3&v=3&t=Sub&m=Message
This is where it's done.

Code: Select all

if(client.connect("pushsafer.com",80))
  {
    client.println("POST /api HTTP/1.1");
    client.println("Host: https://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("&u=");
    client.print(url);
    client.print("&ut=");
    client.print(urltitle);
    client.print("&l=");
    client.print(time2live);
In my case, I wanted to get this to work so I just made global variable like this:

Code: Select all

// pushsafer settings
char privatekey[] = "my code";
char message[] = "3D printer done printing";
char title[] = "title";
int sound = 1;
int vibration = 2;
int icon = 1;
char device[] = "a";
char url[] = "http://www.pushsafer.com";
char urltitle[] = "cest le site";
int time2live = 60;
I always get this

Code: Select all

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
Have any tips?

thanks!!


I am on Arduino 1.8.0

User avatar
admin
Site Admin
Posts: 943
Joined: 1. Dec 2014, 12:41
Location: Germany

Re: arduino pushsafer can't compile

Postby admin » 8. Jan 2017, 11:10

Hi,

line 46 is only the host. Line 45 the path (/api)

Code: Select all

45    client.println("POST /api HTTP/1.1");
46    client.println("Host: https://www.pushsafer.com");
Thats correct. The issue is in the integer variables, i think. Currently i could not test it by my self.

Please change line 35 from

Code: Select all

byte pushsafer(char *pushsafermessage, char *pushsafertitle, int sound, int vibration, int icon, char *psdevice, char url, char urltitle, int time2live)
to

Code: Select all

byte pushsafer(char *pushsafermessage, char *pushsafertitle, char sound, char vibration, char icon, char psdevice, char url, char urltitle, char time2live)
Can you give me a feedback.

Thanks Kevin
Pushsafer DE: Dir gefällt Service und Support! Dann freuen wir uns auf deine Bewertung!
Pushsafer EN: You like Service and Support! Then we look forward to your review!

Pushsafer.com Website - iOS - Android - Windows 10

robomaniac

Re: arduino pushsafer can't compile

Postby robomaniac » 8. Jan 2017, 15:53

if I compile original code from github using "ethernet" has a board and arduino 1.8.0

Code: Select all

C:\sketch_jan07a.ino: In function 'byte pushsafer(char*, char*, int, int, int, char*, char, char, int)':

sketch_jan07a:43: error: request for member 'length' in 'sound', which is of non-class type 'int'

   length = 30 + message.length() + title.length() + sound.length() + vibration.length() + icon.length() + device.length() + url.length() + urltitle.length() + time2live.length() + privatekey.length();

                                                           ^

sketch_jan07a:43: error: request for member 'length' in 'vibration', which is of non-class type 'int'

   length = 30 + message.length() + title.length() + sound.length() + vibration.length() + icon.length() + device.length() + url.length() + urltitle.length() + time2live.length() + privatekey.length();

                                                                                ^

sketch_jan07a:43: error: request for member 'length' in 'icon', which is of non-class type 'int'

   length = 30 + message.length() + title.length() + sound.length() + vibration.length() + icon.length() + device.length() + url.length() + urltitle.length() + time2live.length() + privatekey.length();

                                                                                                ^

sketch_jan07a:43: error: request for member 'length' in 'url', which is of non-class type 'char'

   length = 30 + message.length() + title.length() + sound.length() + vibration.length() + icon.length() + device.length() + url.length() + urltitle.length() + time2live.length() + privatekey.length();

                                                                                                                                 ^

sketch_jan07a:43: error: request for member 'length' in 'urltitle', which is of non-class type 'char'

   length = 30 + message.length() + title.length() + sound.length() + vibration.length() + icon.length() + device.length() + url.length() + urltitle.length() + time2live.length() + privatekey.length();

                                                                                                                                                     ^

sketch_jan07a:43: error: request for member 'length' in 'time2live', which is of non-class type 'int'

   length = 30 + message.length() + title.length() + sound.length() + vibration.length() + icon.length() + device.length() + url.length() + urltitle.length() + time2live.length() + privatekey.length();

                                                                                                                                                                          ^

sketch_jan07a:43: error: request for member 'length' in 'privatekey', which is of non-class type 'char [26]'

   length = 30 + message.length() + title.length() + sound.length() + vibration.length() + icon.length() + device.length() + url.length() + urltitle.length() + time2live.length() + privatekey.length();

                                                                                                                                                                                                ^

exit status 1
request for member 'length' in 'sound', which is of non-class type 'int'


if I compile with the line of code you told me

Code: Select all

byte pushsafer(char *pushsafermessage, char *pushsafertitle, char sound, char vibration, char icon, char psdevice, char url, char urltitle, char time2live)
I get this

Code: Select all

C:\sketch_jan06c.ino: In function 'byte pushsafer(char*, char*, char, char, char, char, char, char, char)':

sketch_jan06c:41: error: conversion from 'char' to 'String' is ambiguous

   String device = psdevice;

                   ^

C:\sketch_jan06c.ino:37:106: note: candidates are:

 byte pushsafer(char *pushsafermessage, char *pushsafertitle, char sound, char vibration, char icon, char psdevice, char url, char urltitle, char time2live)

                                                                                                          ^

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:231:0,

                 from sketch\sketch_jan06c.ino.cpp:1:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:61:2: note: String::String(const __FlashStringHelper*) <near match>

  String(const __FlashStringHelper *str);

  ^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:61:2: note:   no known conversion for argument 1 from 'char' to 'const __FlashStringHelper*'

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:59:2: note: String::String(const char*) <near match>

  String(const char *cstr = "");

  ^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:59:2: note:   no known conversion for argument 1 from 'char' to 'const char*'

sketch_jan06c:43: error: request for member 'length' in 'sound', which is of non-class type 'char'

   length = 30 + message.length() + title.length() + sound.length() + vibration.length() + icon.length() + device.length() + url.length() + urltitle.length() + time2live.length() + privatekey.length();

                                                           ^

sketch_jan06c:43: error: request for member 'length' in 'vibration', which is of non-class type 'char'

   length = 30 + message.length() + title.length() + sound.length() + vibration.length() + icon.length() + device.length() + url.length() + urltitle.length() + time2live.length() + privatekey.length();

                                                                                ^

sketch_jan06c:43: error: request for member 'length' in 'icon', which is of non-class type 'char'

   length = 30 + message.length() + title.length() + sound.length() + vibration.length() + icon.length() + device.length() + url.length() + urltitle.length() + time2live.length() + privatekey.length();

                                                                                                ^

sketch_jan06c:43: error: request for member 'length' in 'url', which is of non-class type 'char'

   length = 30 + message.length() + title.length() + sound.length() + vibration.length() + icon.length() + device.length() + url.length() + urltitle.length() + time2live.length() + privatekey.length();

                                                                                                                                 ^

sketch_jan06c:43: error: request for member 'length' in 'urltitle', which is of non-class type 'char'

   length = 30 + message.length() + title.length() + sound.length() + vibration.length() + icon.length() + device.length() + url.length() + urltitle.length() + time2live.length() + privatekey.length();

                                                                                                                                                     ^

sketch_jan06c:43: error: request for member 'length' in 'time2live', which is of non-class type 'char'

   length = 30 + message.length() + title.length() + sound.length() + vibration.length() + icon.length() + device.length() + url.length() + urltitle.length() + time2live.length() + privatekey.length();

                                                                                                                                                                          ^

sketch_jan06c:43: error: request for member 'length' in 'privatekey', which is of non-class type 'char [26]'

   length = 30 + message.length() + title.length() + sound.length() + vibration.length() + icon.length() + device.length() + url.length() + urltitle.length() + time2live.length() + privatekey.length();

                                                                                                                                                                                                ^

exit status 1
conversion from 'char' to 'String' is ambiguous

robomaniac

Re: arduino pushsafer can't compile

Postby robomaniac » 8. Jan 2017, 15:59

one of my question is: If I don't send the right length in the message, will I get an error message from your server?

Will I get this

Code: Select all

<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />

User avatar
admin
Site Admin
Posts: 943
Joined: 1. Dec 2014, 12:41
Location: Germany

Re: arduino pushsafer can't compile

Postby admin » 8. Jan 2017, 16:30

length is important to validate the request.

Please try these lines of code:

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(String pushsafermessage, String pushsafertitle, String sound, String vibration, String icon, String psdevice, String url, String urltitle, String time2live)
{
  String title = pushsafertitle;
  String message = pushsafermessage;
  String device = psdevice;

  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: https://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();
  }  
}
by calling the function like

Code: Select all

pushsafer(Text,Title,"12","3","62","a");
Hope this works
Pushsafer DE: Dir gefällt Service und Support! Dann freuen wir uns auf deine Bewertung!
Pushsafer EN: You like Service and Support! Then we look forward to your review!

Pushsafer.com Website - iOS - Android - Windows 10

robomaniac

Re: arduino pushsafer can't compile

Postby robomaniac » 8. Jan 2017, 18:09

I had to change the code a little bit but privatekey is a char. So the line "privatekey.length();" does not work.

The parameters of length needs to be string: a variable of type String
https://www.arduino.cc/en/Reference/StringLength

Code: Select all

sketch_jan08a:45: error: request for member 'length' in 'privatekey', which is of non-class type 'char [21]'

   length = 41 + message.length() + title.length() + sound.length() + vibration.length() + icon.length() + device.length() + privatekey.length();
why do you add 41 and not 30 like other code? It's like a header with other info?
OH! we remove the URL, title and time2live, that's it.

robomaniac

Re: arduino pushsafer can't compile

Postby robomaniac » 8. Jan 2017, 18:23

this code here compiles using "arduino ethernet" and 1.8.0

BUT I use 'sizeof' instead of 'length()'

I don't have ethernet board so I can not test it.


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[] = "my key";

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("Text","Title","12","3","62","a");
  delay(60000); 
}


byte pushsafer(String pushsafermessage, String pushsafertitle, String sound, String vibration, String icon, String psdevice)
{
  String title = pushsafertitle;
  String message = pushsafermessage;
  String device = psdevice;

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

  if(client.connect("pushsafer.com",80))
  {
    client.println("POST /api HTTP/1.1");
    client.println("Host: https://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();
  }  
}

I am now checking to make it work on my WIFI ESP8266 dev board from Sparkfun.
(update) Does not work. I am 100% certain it's the actual length that I send that is not good.
In my case I have 'Content-Length: 301'
if I get that incorrect, it will not work.

robomaniac

Re: arduino pushsafer can't compile

Postby robomaniac » 8. Jan 2017, 18:30

OK!

just learn that length() function is in '#include <Ethernet.h>'

So in my Wifi ESP8266 code I added '#include <Ethernet.h>' and I can not use length() function.

My code is now

Code: Select all

 length = 41 + message.length() + title.length() + sound.length() + vibration.length() + icon.length() + device.length() + sizeof(privatekey);
I added 'sizeof()' for the privatekey since it does not work with length()

interesting enough, my length with the new code is the same
'Content-Length: 301'

User avatar
admin
Site Admin
Posts: 943
Joined: 1. Dec 2014, 12:41
Location: Germany

Re: arduino pushsafer can't compile

Postby admin » 8. Jan 2017, 19:10

do you got it to work now?

Code: Select all

Content-Length: 301
must have the same length. The number of characters sent is given here.
Pushsafer DE: Dir gefällt Service und Support! Dann freuen wir uns auf deine Bewertung!
Pushsafer EN: You like Service and Support! Then we look forward to your review!

Pushsafer.com Website - iOS - Android - Windows 10

robomaniac

Re: arduino pushsafer can't compile

Postby robomaniac » 8. Jan 2017, 19:36

ok so your system return this, the Content-Length is always 301.



Code: Select all

HTTP/1.1 400 Bad Request
Date: Sun, 08 Jan 2017 19:13:54 GMT
Server: Apache
Content-Length: 301
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache Server at https://www.pushsafer.com Port 80</address>
</body></html>


Who is online

Users browsing this forum: Bing [Bot] and 33 guests