1

I am trying to send data to firebase but for some reason when I try to send the data from my Arduino using get method it will not work if I go through web browser this code works no problem. but when I run it through Arduino it does not work at all what is the best way to send data from the Arduino to firebase using a gprs module

   <?php
        // some php stuff
        $mapId = $_GET['mapId']; //username
        $bike  = $_GET['bike'];
        $lat   = $_GET['lat'];
        $lng   = $_GET['lng'];
        $ori   = $_GET['ori'];

    ?>
    <script src='https://cdn.firebase.com/js/client/2.3.1/firebase.js'></script>
    <script type="text/javascript">

        var mapId = '<?php echo $mapId ?>';
        var bike  = '<?php echo $bike ?>';
        var lat   = '<?php echo $lat ?>';
        var lng   = '<?php echo $lng ?>';
        var ori   = '<?php echo $ori ?>';

        var ref = new Firebase('https://granted-7cdeb.firebaseio.com/maps/'+ mapId);
        var usersRef = ref.child(bike);

        function now() {
        return Math.floor(Date.now() / 1000);
        }

        function saveData()
            {
            usersRef.set({
              coords: {
              latitude: lat,
              longitude: lng
              },
              orientation: ori,
              timestamp: now()
            });
            }

    window.onload = saveData;
    </script>
    <?php

    ?>

Arduino code this code send the request to the php file that on my server

  GPRS.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");//setting the SAPBR, the connection type is using gprs
  delay(300);
  GPRS.println("AT+SAPBR=3,1,\"APN\",\"WHOLESALE\"");//setting the APN, the second need you fill in your local apn server
  delay(300); 
  GPRS.println("AT+SAPBR=1,1");//setting the SAPBR, for detail you can refer to the AT command mamual
  delay(300); 
  GPRS.println("AT+HTTPINIT"); //init the HTTP request
  delay(300);  
  GPRS.println("AT+HTTPPARA=\"URL\",\"http://grantedsecurity.com/arduino/test.php?GET VARIABLES REQUEST BLAH BLAH\"");// setting the httppara, the second parameter is the website you want to access
  delay(300); 
  GPRS.println("AT+HTTPACTION=0");//submit the request 
  delay(300);//the delay is very important, the delay time is base on the return from the website, if the return datas are very large, the time required longer.
  //while(!mySerial.available());
Real Connect
  • 103
  • 3
  • 11
  • Relevant: [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – gre_gor Jun 23 '17 at 12:18

1 Answers1

2

So, you are using JavaScript generated in PHP?

Lets think about flow:

  • Client sends data to the server page
  • Server uses that data to generate page with JavaScript
  • Client receives the page
  • Client runs JavaScript on page and therefore sends data to the firebase

Now remember - Arduino is pretty simple hardware, there is no JS interpret.

So you have basically only option - Save the data to the firebase directly from PHP (without JavaScript), as running some complex script in JavaScript on Arduino would be impossible.

KIIV
  • 3,534
  • 2
  • 18
  • 23