Getting data from an online API stored as Json

Hi

I've been developing an automation code by using Arduino UNO and an ethernet shield. The basic code works pretty and basically from a computer I can control some relays. You can find all my code at the end of this topic.

I have an API key from the site http://openweathermap.org that generates data stored as Json. The link: http://api.openweathermap.org/data/2.5/weather?id=3873544&mode=json&APPID=7f347ff86d3239c4ef3dbb894f76ea29. I'd like to get only the "temp" data, the temperature in Kelvin, in order to use the value as a double variable. So, I will create a code to perform some calculation (for example, to calculate and display the temperature in Celsius).

How to do that, please?

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
IPAddress ip(192,168,1,10);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255, 255, 255, 0);
EthernetServer server(80);

int chave=A2;
int motor=3;
int trava=4;
int luz=5;
int timer=0;
float lerchave=0;
char c = 0;
char command[2] = "\0";

void setup()
{
// put your setup code here, to run once:
Ethernet.begin(mac, ip);
server.begin();
pinMode(chave, INPUT);
pinMode(motor, OUTPUT);
pinMode(trava, OUTPUT);
pinMode(luz, OUTPUT);
}

void loop()
{
EthernetClient client = server.available();
if (client)
{
// an http request ends with a blank line
boolean current_line_is_blank = true;
boolean current_line_is_first = true;
while (client.connected())
{
timer = 0;
if (client.available())
{
char c = client.read();
if (c == '\n' && current_line_is_blank)
{

client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<body background-color:#040300>");
client.println("

Bem-vindo!


");
client.println("");
client.println("Abre Portao");
client.println("Fecha Portao");
client.println("

"); client.println("Acende Luz "); client.println(" Apaga Luz "); client.println("

"); break; } if (c == '\n') { current_line_is_first = false; current_line_is_blank = true; } else if (c != '\r') { current_line_is_blank = false; } if (current_line_is_first && c == '=') { for (int i = 0; i < 1; i++) { c = client.read(); command = c; }

if (!strcmp(command, "1"))
{
if (lerchave<1020) //se a chave de curso está em NA
{
while (lerchave<1020 && timer<=10000) //o motor será acionado e permenecerá até a chave de curso ir para NF. Tal operação deve ser realizada em até 10 s, caso contrário indicará que o portão está trancado.
{
lerchave = analogRead(chave);
digitalWrite(motor,HIGH);
delay(100);
timer=timer+100; //conta o tempo de acionamento do motor
if(timer>10000 && lerchave<1020)
{
digitalWrite(motor,LOW);
delay(120000); // caso a chave de curso não foi acionada em 10 s, o que indica que o portão estava trancado, será necessário esperar 2 min para ativar o motor.
}
}
if(timer<=10000) //se em até 10 segundos a chave de curso passa para NF, a trava é acionada e 2 s após o motor é deligado.
{
digitalWrite(trava,HIGH);
delay(2000);
digitalWrite(motor,LOW);
}
}
}
else if (!strcmp(command, "2"))
{
lerchave = analogRead(chave);
if (lerchave > 1020)
{
digitalWrite(trava,LOW);
delay(3000);
digitalWrite(motor,HIGH);
delay(1500);
digitalWrite(motor,LOW);
}
}
if (!strcmp(command, "3"))
{
digitalWrite(luz,HIGH);
}
else if (!strcmp(command, "4"))
{
digitalWrite(luz,LOW);
}
}
}
}
delay(1000);
client.stop();
}
client.println("");
}

Welcome to the forum!

Its much easier to read your code if you put the code tags </> around it

Like this

This stackexchange thread has some options to parse JSON.