B4R Question (SOLVED) B4R Firabase

RAFA BRAVO

Active Member
Licensed User
Longtime User
Hello Goodnight!! I would like to be able to send a request to firebase from B4R but I use an ARDUINO mega 2560 with ethernet shield w5500, and I have read in some thread that only works from a WIFI module like esp8266. somebody could help me? I have followed an example where the request to firebase is made from B4J and the notification arrives perfectly. Now I would like to do it from B4R. THANKS
 

RAFA BRAVO

Active Member
Licensed User
Longtime User
Good morning

I think the best option is the server . I have been trying to do it with B4J but still have not been able to communicate? could it be done with B4RSerializator? Is there an example in the forum where I can get my bearings? THANKS
 
Upvote 0

RAFA BRAVO

Active Member
Licensed User
Longtime User
Ok, using this example of yours. is working:
https://www.b4x.com/android/forum/threads/ethernet-network-tutorial.65664/#content


but my question is why the notification has no sound? And why can't I see it when the phone is locked,
Does it have to do with the code or the firabase configuration?





B4J Server:
Sub Process_Globals
    Private const API_KEY As String = ""
    Private server As ServerSocket
    Public connected As Boolean
    Private astream As AsyncStreams
End Sub

Sub AppStart (Args() As String)
    server.Initialize(51042, "server")
    server.Listen
    
    
    StartMessageLoop
End Sub

Sub server_NewConnection (Successful As Boolean, NewSocket As Socket)
    Log("new connection")
    astream.Initialize(NewSocket.InputStream, NewSocket.OutputStream, "Astream")
    server.Listen
End Sub

Sub Astream_NewData (Buffer() As Byte)
    If Buffer(0) = 0 Then
        Log("Button is down.")
    Else
        Log("Button is up.")
        SendMessage("general", "ATENCION", "paro de linea")
    End If
    astream.Write("Thank you for this useful information.".GetBytes("UTF8"))
End Sub

Private Sub SendMessage(Topic As String, Title As String, Body As String)
    Dim Job As HttpJob
    Job.Initialize("fcm", Me)
    Dim m As Map = CreateMap("to": $"/topics/${Topic}"$)
    Dim data As Map = CreateMap("title": Title, "body": Body)
    If Topic.StartsWith("ios_") Then
        Dim iosalert As Map =  CreateMap("title": Title, "body": Body, "sound": "default")
        m.Put("notification", iosalert)
        m.Put("priority", 10)
    End If
    m.Put("data", data)
    Dim jg As JSONGenerator
    jg.Initialize(m)
    Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
    Job.GetRequest.SetContentType("application/json;charset=UTF-8")
    Job.GetRequest.SetHeader("Authorization", "key=" & API_KEY)
End Sub


Sub JobDone(job As HttpJob)
   Log(job)
   If job.Success Then
     Log(job.GetString)
   End If
   job.Release
'   ExitApplication '!
End Sub
 
Upvote 0
Top