2017-06-22 14 views
1

Firebaseにデータを送信しようとしていますが、何らかの理由でArduinoからgetメソッドを使用してデータを送信しようとすると、Webブラウザを経由しても問題ありません。私はアルドゥイーノを通してそれを実行すると、それはGPRSモジュールphpを使用して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 

    ?> 
を使用してfirebaseするためのArduinoからデータを送信するための最良の方法は何かまったく機能しません このコードはその上のPHPファイルへのリクエストを送信

Arduinoのコード私のサーバ

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()); 
+0

関連:[クライアント側とサーバー側のプログラミングの違いは何ですか?](https://stackoverflow.com/questions/13840429/what-is-the-difference- between-client-side-and-サーバー側プログラミング) –

答えて

1

PHPで生成されたJavaScriptを使用していますか?

流れを考えることができます:

  • クライアントサーバーページにデータを送信し
  • サーバは、クライアントがページ
  • クライアントは、ページ上でJavaScriptを実行し、受信
  • データではJavaScript
  • でページを生成することを使用していますしたがって、ファイアベースにデータを送信します

今思い出してください - ArduinoはかなりシンプルなハードウェアですJS解釈はありません。

あなたは基本的に唯一のオプションがあります - ArduinoのJavaScriptで複雑なスクリプトを実行するのが不可能であるため、PHPから直接Firebaseにデータを保存します(JavaScriptなし)。

関連する問題