appzer / pushsafer-arduino-library

Arduino library for Pushsafer.com
23 stars 9 forks source link

Not working again(?) #4

Closed bphick closed 5 years ago

bphick commented 5 years ago

Hi, I tried the script through an ESP32 programmed from the Arduino IDE (1.8.9) sending to a Samsung Galaxy S8 Android phone.
The text portions do come through to the phone only if the App is open. Additionally no notifications come in, and if any parameters such as the r or p are changed to a value, the script yields no result at the phone at all. I also tried from the on-line dashboard to send a message, and the phone responds PERFECTLY. Notifications work, sound works, etc. So I am left to conclude that the problem lies with the script. I'm a very newbie, so I really don't know where to begin to troubleshoot. I'm hoping a fully workable version with notifications and sound could be made with a bit of tweaking by a knowledgeable person.

appzer commented 5 years ago

Hi,

can you post your arduino script!

to understand

bphick commented 5 years ago

// Using an ESP-WROOM-32 version of a NODEMCU

include

include

include // gray, not red color in the Arduino IDE

include

/#include /

include

include // gray, not red color in the Arduino IDE

// Initialize Wifi connection to the router char ssid[] = "My_SSID"; // your network SSID (name) char password[] = "My_Password"; // your network key

// Pushsafer private or alias key

define PushsaferKey "My_PushsaferKey"

/WiFiClientSecure client;/ WiFiClient client; Pushsafer pushsafer(PushsaferKey, client);

void setup() { Serial.begin(115200);

// Set WiFi to station mode and disconnect from an AP if it was Previously // connected WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(100);

// Attempt to connect to Wifi network: Serial.print("Connecting Wifi: "); Serial.println(ssid); WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); }

Serial.println(""); Serial.println("WiFi connected"); Serial.print("IP address: "); Serial.println(WiFi.localIP());

pushsafer.debug = true;

// Take a look at the Pushsafer.com API at // https://www.pushsafer.com/en/pushapi

struct PushSaferInput input; input.message = "This is a test message From ESP32"; input.title = "Hello Bryan!"; input.sound = "8"; input.vibration = "2"; input.icon = "149"; input.iconcolor = "#66ffff"; input.priority = "2"; input.device = "a"; input.url = "https://www.pushsafer.com"; input.urlTitle = "Open Pushsafer.com"; input.picture = ""; input.picture2 = ""; input.picture3 = ""; input.time2live = ""; input.retry = ""; input.expire = ""; input.answer = "";

Serial.println(pushsafer.sendEvent(input));

Serial.println("Sent"); }

void loop() { }

bphick commented 5 years ago

Thank you for looking into this! It is very much appreciated. "My" code is above. Other than library changes to get it to compile for the ESP-WROOM-32 version of a NodeMCU, it is virtually unchanged from the example code.

bphick commented 5 years ago

Also, the phone is on Android V9.

appzer commented 5 years ago

can you take a look in the arduino debug log and post the response! Please take a look at the faq for Android 8+ devices https://www.pushsafer.com/en/faq#answer27

Kevin

bphick commented 5 years ago

Correct. I have all of the notifications On. One difference, is that once a custom sound is selected, the App provided sound disappears and is no longer available. I have setup a custom sound and was not able to return the App to the original state. Custom sounds do trigger from the Web. I had tried to reinstall the App, but it kept the state from the previous load.

bphick commented 5 years ago

Debug log as of just now, this does not always show up:

C:\Users\Owner\Documents\Arduino\libraries\pushsafer-arduino-library-master\src\Pushsafer.cpp: In member function 'String Pushsafer::sendEvent(PushSaferInput)':

C:\Users\Owner\Documents\Arduino\libraries\pushsafer-arduino-library-master\src\Pushsafer.cpp:133:10: warning: unused variable 'c' [-Wunused-variable]

 char c;

      ^

Sketch uses 658950 bytes (50%) of program storage space. Maximum is 1310720 bytes. Global variables use 38352 bytes (11%) of dynamic memory, leaving 289328 bytes for local variables. Maximum is 327680 bytes.

bphick commented 5 years ago

I just ran it again, and no such message appears... But I have seen the message before.

bphick commented 5 years ago

The message appears upon any new full debug / compile; anytime the debug option changes.

bphick commented 5 years ago

I cleared all data from the phone as well as the cache regarding Pushsafer. That did allow me to return to the default sound as "App provided sound." However, it still will not push Notifications unless the App is up, and still no sound or Icon ever shows outside of the App.

appzer commented 5 years ago

Hello,

to check if the arduino script or your phone not work correctly. Please copy this script into a .html file and save it to your pc and open it in a browser of your choice.

<script>
var xhttp;
if (window.XMLHttpRequest) {
    xhttp = new XMLHttpRequest();
    } else {
    // code for IE6, IE5
    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

xhttp.open("POST", "https://www.pushsafer.com/api", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.onreadystatechange = ProcessRequest;
xhttp.send("t="+escape('TEST')+
           "&m="+escape('THIS IS A TEST')+
           "&d=[YourDeviceID]"+
           "&k=[YourPrivateKey]"+
           "&i=82"+
           "&s=8"+
           "&v=3"+
           "&u="+escape('https://www.google.de?q=test')+
           "&ut="+escape('Google Search')
          );

function ProcessRequest() {
    document.write('ReadyState: '+xhttp.readyState+'<br>');
    document.write('Status: '+xhttp.status+'<br>');
    document.write('ResponseText: '+xhttp.responseText+'<br>');
}
</script>

change the values in []

bphick commented 5 years ago

Running the above script yields the following in the browser window:

change the values in []

bphick commented 5 years ago

Oops, sorry. I probably need to fill in some values before it will work. Sorry. Let me try again.

bphick commented 5 years ago

Sorry, am I missing something? I filled out the &d, and &k parameters, still receive the same result: " change the values in []"

bphick commented 5 years ago

I ran it both in Chrome and IE (running on Windows7 machine). IE says: "Internet Explorer restricted this webpage from running scripts or ActiveX Controls." I clicked the popup "Allow Blocked Content" but no change.

bphick commented 5 years ago

OK, I manipulated the script a bit. Now I have a message! "ReadyState: 2"

bphick commented 5 years ago

It flashes: "ReadyState: 1 Status: 0 ResponseText: change the values in []"

Then clears the screen and says: "ReadyState: 2"

bphick commented 5 years ago

That was from my PC... I emailed the script to my phone and I get this response from the phone browser: "ReadyState: 2 Status: 250 ResponseText: ReadyState: 3 Status: 250 ResponseText: {"status":0,"error":"invalid key"} ReadyState: 4 Status: 250 ResponseText: {"status":0,"error":"invalid key"}"

appzer commented 5 years ago

invalid key = check it

bphick commented 5 years ago

ReadyState: 2 Status: 200 ResponseText: ReadyState: 3 Status: 200 ResponseText: {"status":1,"success":"message transmitted","available":984,"message_ids":"4076363:16216"} ReadyState: 4 Status: 200 ResponseText: {"status":1,"success":"message transmitted","available":984,"message_ids":"4076363:16216"}

bphick commented 5 years ago

Screenshot_20190515-090118_Settings

bphick commented 5 years ago

Screenshot_20190515-090105_Settings

bphick commented 5 years ago

Screenshot_20190515-090058_Settings

appzer commented 5 years ago

OK the push transmitted correctly to the google server!

What you can set under "Set as Default"?

Mostly battery managers prevent receiving push notifications correctly. Open System settings, then Advanced Settings, then Battery Manager, and finally Protected apps. Enable the toggle next to Pushsafer to allow it to keep running even after the screen is turned off.

For Samsung Devices Exclude the Pushsafer app from any of the battery optimization features on your device. You'll find these in Settings, then Battery. You'll need to disable battery optimization for the Pushsafer app, as well as checking to make sure the Restrict background data setting is disabled.

Here is a really good blog post to fix broken push notifications https://www.forbes.com/sites/bensin/2017/05/05/samsungs-battery-paranoia-broke-the-galaxy-s8s-push-notifications-just-like-chinese-smartphones/#4926bb1e7a91

Please leave a feedback

bphick commented 5 years ago

Screenshot_20190515-112629_Settings

bphick commented 5 years ago

Sorry, while it was off, that does not appear to be the problem. Still no change.

bphick commented 5 years ago

Screenshot_20190515-113635_Settings

bphick commented 5 years ago

OK, after further testing, what the Forbes article actually does makes it so that the full App doesn't stop running in the background... until you click "Close All' or swipe the App off of the active list. Still, no Icon or light notification works even then. Sound comes through. If one hits the "Close All Apps" or swipes the App off (closing it in Android 9), then nothing at all works again. Still, under no circumstances does anything appear as an Icon, no status light blinks, no notification in the upper bar.

appzer commented 5 years ago

please try the following

Send the notifications out of your pushsafer dashboard (website) https://www.pushsafer.com/en/dashboard#anchorsend

  1. send a push notification while the app is in front
  2. send a push notification while the app is in background
  3. send a push notification while the app fully closed

i credited you some extra api calls for testing!

appzer commented 5 years ago

i think the app should run in background, here a post https://updato.com/how-to/manage-android-apps-running-background

bphick commented 5 years ago

I looked at" set under "Set as Default". While most Apps on the phone are listed, Pushsafer is not.

bphick commented 5 years ago

Case - Results: 1) send a push notification while the app is in front - Message visible, sound and nearly immediate response in window. 2) send a push notification while the app is in background - Message visible, sound and nearly immediate response in window. 3) send a push notification while the app fully closed - Nothing.

bphick commented 5 years ago

Screenshot_20190515-121308_Settings

bphick commented 5 years ago

Wondering why you are not listed here in the default choices.

bphick commented 5 years ago

Now it seems that we are going backward. Now it does not notify with an icon, etc. even from the Web interface... it originally did.

appzer commented 5 years ago

set as default you can set up with which app an file type should open. not interesting for pushsafer The app should run in background! This is very important!

Try to set the priority to 2 and also choose a sound in the web interface!

appzer commented 5 years ago

can you send a screenshot of the notification channels set up

bphick commented 5 years ago

I am unable to find that path in Android 9. Let me understand. The above path should be on my phone or somewhere else?

appzer commented 5 years ago

the path is from android 9 > i think on Samsung devices its little different Please take a look at your first screenshot, normally you should see notification channels Sound 0-60 for the pushsafer app

appzer commented 5 years ago

https://www.pushsafer.com/en/faq#answer27

bphick commented 5 years ago

Screenshot_20190515-170437_Settings

bphick commented 5 years ago

Screenshot_20190515-123214_Settings

bphick commented 5 years ago

Screenshot_20190515-171033_Settings

bphick commented 5 years ago

Are these the spot?

appzer commented 5 years ago

notification categories is right there must be categories called from Sound 1 - Sound 60 do you see different categories for pushsafer app?

If not i think channel not correctly installed while insalling the app! Please delete all app data frpm pushsafer, deinstall pushsafer, reboot your device and install again! After that take a look at the notification prefs, if you see theses 60 channels / categories

btw you need to check sound & pop-up

bphick commented 5 years ago

I have completed that two times before today and once prior to this today. Out celebrating my birthday today. Will do a major App scrubbing and complete reload in the morning and let you know how it turns out. I am very, very appreciative of the work you are doing to help me set this up! Thank you!

appzer commented 5 years ago

happy birthday - what a coincidence - today i have my 40. birthday

bphick commented 5 years ago

Happy Birthday!! I am now 59... getting old. ;-)

bphick commented 5 years ago

Yesterday night, after all had left my home, I purged my device from the web account. Then purged the cache and data from my phone and uninstalled the App. Then reinstalled a squeaky-clean version of the App. Now, from the Web interface Pictures to follow this message:

Case - Results:

1) Send a push notification while the app is in front - Message visible, sound and nearly immediate response in window. No Icon. 2) Send a push notification while the app is in background, sound selected - No sound. No Icon. 2a) Send a push notification while the app is in background, no sound selected - NO sound and nearly immediate response in window Icon in bar. 3) Send a push notification while the app fully closed - Nothing. Until booting the App. 4) Send from ESP32 with App Closed - Nothing. Until booting the App. 4a) Remove sound variable from Arduino Code - Send from ESP32 - App in background - receive Icon. 4b) Turn OFF the App in the background - Send form ESP32 - App NOT running in background - RECEIVED ICON! ;-) No colors, no sound. but 2 vibes and the bell icon appeared.... surprise result!

Arduino code: struct PushSaferInput input; input.message = "This is a test message From ESP32"; input.title = "Hello Bryan!"; input.sound = ""; input.vibration = "2"; input.icon = "73"; //149 is a spigot icon, 73 is a flooding house icon input.iconcolor = "#66ffff"; input.priority = "2"; input.device = "a"; input.url = "https://www.pushsafer.com"; input.urlTitle = "Open Pushsafer.com"; input.picture = ""; input.picture2 = ""; input.picture3 = ""; input.time2live = ""; input.retry = ""; input.expire = ""; input.answer = "";

bphick commented 5 years ago

Screenshot_20190516-075731_Message+