Tutorial Arduino PHP Web JSON/XML En este tutorial aprendemos a interfaz entre servicios web como openweather.org y lenguajes como PHP para parse JSON o XML y alimentar la Arduino. Requisitos: Computadora (mac) Arduino UNO Servidor Linux/PHP Arduino IDE (https://www.arduino.cc/en/Main/Software) OpenWeather: http://api.openweathermap.org/data/2.5/weather?q=Amsterdam,NL&units=metric&appid=suID Resultado: {“coord”:{“lon”:4.89,”lat”:52.37},”weather”:[{“id”:801,”main”:”Clouds”,”description”:”few clouds”,”icon”:”02d”}],”base”:”cmc stations”,”main”:{“temp”:24.17,”pressure”:1013.79,”humidity”:39,”temp_min”:24.17,”temp_max”:24.17,”sea_level”:1013.72,”grnd_level”:1013.79},”wind”:{“speed”:8.56,”deg”:79.5083},”clouds”:{“all”:12},”dt”:1463065042,”sys”:{“message”:0.0123,”country”:”NL”,”sunrise”:1463024893,”sunset”:1463081183},”id”:2759794,”name”:”Amsterdam”,”cod”:200} PHP: [/code] <?php // retrieve the current weather in Amsterdam in degrees Celcius $json = file_get_contents(‘http://api.openweathermap.org/data/2.5/weather?q=Amsterdam,NL&units=metric&appid=suID’); // parse the JSON $data = json_decode($json); // show the city (and the country) echo ‘<h1>’, $data->name, ‘ (‘, $data->sys->country, ‘)</h1>’; // the general information about the weather echo ‘<h2>Temperature:</h2>’; echo ‘<p><strong>Current:</strong> ‘, $data->main->temp, ‘° C</p>’; echo ‘<p><strong>Min:</strong> ‘, $data->main->temp_min, ‘° C</p>’; echo ‘<p><strong>Max:</strong> ‘, $data->main->temp_max, ‘° C</p>’; // something… Read More
Continue Reading