Javascript 使用php get将数据发送到firebase
我正在尝试将数据发送到firebase,但由于某些原因,当我尝试使用get方法从Arduino发送数据时,如果我使用web浏览器,它将无法工作。此代码可以正常工作。但是,当我通过Arduino运行它时,它根本不起作用。使用gprs模块将数据从Arduino发送到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
<?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
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());