Page 1 of 3
arduino pushsafer can't compile
Posted: 7. Jan 2017, 17:54
by robomaniac
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
Re: arduino pushsafer can't compile
Posted: 8. Jan 2017, 11:10
by admin
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
Re: arduino pushsafer can't compile
Posted: 8. Jan 2017, 15:53
by robomaniac
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
Re: arduino pushsafer can't compile
Posted: 8. Jan 2017, 15:59
by robomaniac
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 />
Re: arduino pushsafer can't compile
Posted: 8. Jan 2017, 16:30
by admin
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
Re: arduino pushsafer can't compile
Posted: 8. Jan 2017, 18:09
by robomaniac
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.
Re: arduino pushsafer can't compile
Posted: 8. Jan 2017, 18:23
by robomaniac
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.
Re: arduino pushsafer can't compile
Posted: 8. Jan 2017, 18:30
by robomaniac
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'
Re: arduino pushsafer can't compile
Posted: 8. Jan 2017, 19:10
by admin
do you got it to work now?
must have the same length. The number of characters sent is given here.
Re: arduino pushsafer can't compile
Posted: 8. Jan 2017, 19:36
by robomaniac
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>