Hey guys,
I have a little question. How can i get data from a server to the arduino using the http protocol and the sim808 module?
The idea behind this is basically the arduino uses a http get request to push the data on the server.
the server then calculates some stuff and then the state is changed on the server. the arduino needs then to get the actual state on the server.
the reason why the arduino sends the state to the server in this example is only for verifikation.
What I think i need is this code:
state = sendATcommand("AT+HTTPREAD", "OK", 300);
but how do i implement it?
thx for any help
p.s.: the code is too long so i uploaded the whole programm here:
http://textuploader.com/5ypz4
Return the needed state data on receiving the Arduino GET.
Could you be a bit more Precise?
I know, if I keep the URL the same i have to change the state on the server side but then still how can I make with in the GET request an update of the state on the Arduino?
I'm stuck at that point. Cause I first load it to the server and after I want to read what's on the server.
What do you return now when you receive the GET?
Replace with or add state data.
Leave the client a client and the server a server, no need to switch roles.
renedlog:
Hey guys,
I have a little question. How can i get data from a server to the arduino using the http protocol and the sim808 module?
The idea behind this is basically the arduino uses a http get request to push the data on the server.
the server then calculates some stuff and then the state is changed on the server. the arduino needs then to get the actual state on the server.
the reason why the arduino sends the state to the server in this example is only for verifikation.
What I think i need is this code:
state = sendATcommand("AT+HTTPREAD", "OK", 300);
but how do i implement it?
thx for any help
p.s.: the code is too long so i uploaded the whole programm here:
http://textuploader.com/5ypz4
Consider reading on HTTP https://www.ntu.edu.sg/home/ehchua/programming/webprogramming/HTTP_Basics.html
So I should change the response Code from the server?
Atm. I don't have anything like this implemented in the PHP file.
The goal is basically to switch off the relay as soon as it is out of a gps boundary.
I'm a total Newbie in Http communication and PHP.
I read your Link but can't really figure out how to solve my Problem.
According the SIM808 documentation there is always the standard HTTP response expected, means 200 OK.
<?php
if (!empty($_GET['latitude']) && !empty($_GET['longitude']) &&
!empty($_GET['time']) && !empty($_GET['satellites']) &&
!empty($_GET['speedOTG']) && !empty($_GET['course'])) {
function getParameter($par, $default = null){
if (isset($_GET[$par]) && strlen($_GET[$par])) return $_GET[$par];
elseif (isset($_POST[$par]) && strlen($_POST[$par]))
return $_POST[$par];
else return $default;
}
$file = 'gps.txt';
$lat = getParameter("latitude");
$lon = getParameter("longitude");
$time = getParameter("time");
$sat = getParameter("satellites");
$speed = getParameter("speedOTG");
$course = getParameter("course");
$person = $lat.",".$lon.",".$time.",".$sat.",".$speed.",".$course."\n";
echo "
DATA:\n
Latitude: ".$lat."\n
Longitude: ".$lon."\n
Time: ".$time."\n
Satellites: ".$sat."\n
Speed OTG: ".$speed."\n
Course: ".$course;
if (!file_put_contents($file, $person, FILE_APPEND | LOCK_EX))
echo "\n\t Error saving Data\n";
else echo "\n\t Data Save\n";
}
else {
?>
<!DOCTYPE html>
<html>
<head>
<!-- Load Jquery -->
<script language="JavaScript" type="text/javascript" src="jquery-1.10.1.min.js"></script>
<!-- Load Google Maps Api -->
<!-- IMPORTANT: change the API v3 key -->
<script src="http://maps.googleapis.com/maps/api/js?key=your_key&sensor=false"></script>
<!-- Initialize Map and markers -->
<script type="text/javascript">
var myCenter=new google.maps.LatLng(41.669578,-0.907495);
var marker;
var map;
var mapProp;
function initialize()
{
mapProp = {
center:myCenter,
zoom:15,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
setInterval('mark()',5000);
}
function mark()
{
map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
var file = "gps.txt";
$.get(file, function(txt) {
var lines = txt.split("\n");
for (var i=0;i<lines.length;i++){
console.log(lines[i]);
var words=lines[i].split(",");
if ((words[0]!="")&&(words[1]!=""))
{
marker=new google.maps.Marker({
position:new google.maps.LatLng(words[0],words[1]),
});
marker.setMap(map);
map.setCenter(new google.maps.LatLng(words[0],words[1]));
document.getElementById('sat').innerHTML=words[3];
document.getElementById('speed').innerHTML=words[4];
document.getElementById('course').innerHTML=words[5];
}
}
marker.setAnimation(google.maps.Animation.BOUNCE);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<?php
echo '
<!-- Draw information table and Google Maps div -->
<div>
<center>
<b> SIM908 GPS position DEMO </b>
<div id="superior" style="width:800px;border:1px solid">
<table style="width:100%">
<tr>
<td>Time</td>
<td>Satellites</td>
<td>Speed OTG</td>
<td>Course</td>
</tr>
<tr>
<td id="time">'. date("Y M d - H:m") .'</td>
<td id="sat"></td>
<td id="speed"></td>
<td id="course"></td>
</tr>
</table>
</div>
<div id="googleMap" style="width:800px;height:700px;"></div>
</center>
</div>';
?>
</body>
</html>
<?php } ?>