B4R Tutorial Using Firebase to send notifications to iOS and Android devices

Discussion in 'B4R Tutorials' started by Erel, Sep 29, 2016.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Inspired by this example: https://dzone.com/articles/iot-push-notifications-arduino I've created a similar solution in B4X.



    When the button is clicked, two http requests are sent to Firebase REST api. Any subscribed Android or iOS device will receive the push message. It is a very simple and powerful solution.
    It is simple as you don't need a server and it is powerful as the messages will arrive even when the apps are not running. The solution works over the internet, it is not limited to the local network.

    B4A app: https://www.b4x.com/android/forum/threads/67716/#content
    B4i app: FirebaseNotifications / Push Messages (server not required)

    The B4R code is attached. You need to update the API_KEY and the wifi related settings.
     

    Attached Files:

  2. BillMeyer

    BillMeyer Active Member Licensed User

    A Very BIG Thank you. This opens up a whole new world of possibilities.
     
    Erel likes this.
  3. Cableguy

    Cableguy Expert Licensed User

    is it possible to target individual devices from those subscribed in firebase?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Yes. You can subscribe each device to a unique topic id and then send the message to the specific topic. Note that you also need to update the content length field.
     
  5. ShaneG30

    ShaneG30 Well-Known Member Licensed User

    Very interesting code. Looks like a very easy way to use push notifications. I might try to build a library for the other platforms to enable easy notifications.
     
    Cableguy likes this.
  6. JMB

    JMB Active Member Licensed User

    How do you get an API_KEY?

    JMB
     
  7. JMB

    JMB Active Member Licensed User

    Thanks Peter. I will check that out.

    Do you have to register your devices with the Firebase service?

    JMB
     
  8. Erel

    Erel Administrator Staff Member Licensed User

  9. JMB

    JMB Active Member Licensed User

    Thanks Erel. Will check that out.

    It's been a LONG time, but am loving getting back into this stuff. Amazing set of software.

    JMB
     
  10. Julius B.

    Julius B. New Member

    Can you please guide me step by step in how to do this? Also, can I do this with Arduino Uno + ESP8266?
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    No and it is not needed. You should program the ESP8266 directly.

    I recommend you to start with B4A tutorials. There is also a tutorial about push notifications.

    https://www.b4x.com/etp.html
     
    Peter Simpson likes this.
  12. Julius B.

    Julius B. New Member

    If I only program the ESP8266, how will the button send the message?
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    You cannot send push messages without a native Android or iOS app that receives the messages.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice