B4J Question firebase messages running on raspberry

MbedAndroid

Well-Known Member
Licensed User
Longtime User
I took the example code for server side (b4j) and integrated in my homemanagement. Running the b4j code on the laptop it works: i can send a notification to the app on my phone. But the same code running on the rasberry gives this message from google:
{
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "CREDENTIALS_MISSING",
"domain": "googleapis.com",
"metadata": {
"method": "google.firebase.fcm.v1.FcmService.SendMessage",
"service": "fcm.googleapis.com"
}
}
]
}
}
So next i filled the requested Credentials and got a ClientID for a device. But where should i store this in the example code? The projectID and the API key are there (and working as the program runs on my laptop). But how to proceed to get this working server side running on a raspberry Pi?
Someone solved this problem?
 
Check if you have put the json file in the correct folder, where the application jar file is:
B4X: Copy
    Private ServiceAccountFilePath As String = "/home/pi/tempjars/xxxxx.json"
 
Upvote 0
Are you running the B4J program on the RPi?

The exact same code should work.
result running on PC, same code:

{
"message": {
"data": {
"title": "TEST!",
"body": "testknop aangeklikt"
},
"android": {
"priority": "high"
},
"topic": "general"
}

resultaat van firebase:{
"name": "projects/domotica-b8569/messages/7142496539144587259"
}
running code on Rpi (Zero)
{
"message": {
"data": {
"title": "TEST!",
"body": "testknop aangeklikt"
},
"android": {
"priority": "high"
},
"topic": "general"
}
}

{
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "CREDENTIALS_MISSING",
"domain": "googleapis.com",
"metadata": {
"method": "google.firebase.fcm.v1.FcmService.SendMessage",
"service": "fcm.googleapis.com"
}
}
]
}
}
Note: running non-ui on the PC, in debug mode. Make that the difference?
 
Upvote 0
Try to run the B4J sending code example without any changes.
Done....
results:
Testexample working Rpi ánd PC
Same code works also in application when inserted just before startmessageloop (Rpi and pc)
B4X: Copy
    SendNotificatie("general", "this is the title", "And this is the body")
    StartMessageLoop

When starting the code from a button in AMBMaterial it works on the PC, not on the Rpi.Throws the error
B4X: Copy
Sub tbl1_Clicked(PassedRowsAndColumns As List)

    Private lbl=tbl.GetString(tblCellInfo.row, 1) As String
    Select  Case tbl.GetString(tblCellInfo.row,0)

    Select  Case tbl.GetString(tblCellInfo.row,0)
            Case "TestNotificatie"
            Main.SendNotificatie("general","TEST!","testknop aangeklikt")
            Return
        end select
    end sub

also tried Callsub3
B4X: Copy
        Case "TestNotificatie"
            CallSub3(Main,"SendNotificatie","TEST!","testknop aangeklikt")
'            Main.SendNotificatie("general","TEST!","testknop aangeklikt")
            Return
same results:
{
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "CREDENTIALS_MISSING",
"domain": "googleapis.com",
"metadata": {
"service": "fcm.googleapis.com",
"method": "google.firebase.fcm.v1.FcmService.SendMessage"
}
}
]
}
}
When trying starting the code from a timer.... it works both pc ánd Rpi...
puzzling:eek:
 
Last edited:
Upvote 0
solved.... in a indirect way:
timer starts the notification. Timer resides in main. One shot
Anywhere in the program the timer can started.

B4X: Copy
public Sub StartNotification ( title As String, body As String)
    NotificationTimer.Enabled=True
End Sub
private Sub NotificationTimer_tick
    SendNotificatie( "this is the title", "And this is the body")
    NotificationTimer.Enabled=False
End Sub
result:
{
"message": {
"data": {
"title": "this is the title",
"body": "And this is the body"
},
"android": {
"priority": "high"
},
"topic": "general"
}
}


Notificatie send
 
Upvote 0
changed to CallSubDelayed3("main","SendNotificatie",topic,body)

more easy and result is the same. No timer needed.
 
Upvote 0
Back
Top