Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用php get将数据发送到firebase_Javascript_Php_Function_Firebase_Arduino - Fatal编程技术网

Javascript 使用php get将数据发送到firebase

Javascript 使用php get将数据发送到firebase,javascript,php,function,firebase,arduino,Javascript,Php,Function,Firebase,Arduino,我正在尝试将数据发送到firebase,但由于某些原因,当我尝试使用get方法从Arduino发送数据时,如果我使用web浏览器,它将无法工作。此代码可以正常工作。但是,当我通过Arduino运行它时,它根本不起作用。使用gprs模块将数据从Arduino发送到firebase的最佳方式是什么 <?php // some php stuff $mapId = $_GET['mapId']; //username $bike = $_G

我正在尝试将数据发送到firebase,但由于某些原因,当我尝试使用get方法从Arduino发送数据时,如果我使用web浏览器,它将无法工作。此代码可以正常工作。但是,当我通过Arduino运行它时,它根本不起作用。使用gprs模块将数据从Arduino发送到firebase的最佳方式是什么

   <?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

    ?>

那么,您使用的是PHP生成的JavaScript

让我们考虑一下流量:

  • 客户端将数据发送到服务器页面
  • 服务器使用该数据生成带有JavaScript的页面
  • 客户端接收该页面
  • 客户端在页面上运行JavaScript,因此将数据发送到firebase
现在记住——Arduino是非常简单的硬件,没有JS解释

因此,您基本上只有一个选择—直接从PHP(不使用JavaScript)将数据保存到firebase,因为在Arduino上运行一些复杂的JavaScript脚本是不可能的。

相关:
  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());