Ir ao conteúdo
  • Cadastre-se

Arduino arduino - get - php - mysql


Posts recomendados

Bom Dia, queria uma foça para quem puder ajudar aqui:

Estou tentando fazer o Arduino gravar um valor em um banco de dados num servidor via método GET. O arduino apenas precisa enviar uma URL devidamente preenchida e o Script PHP que tá no servidor faz o trabalho.

Se eu executo direto no Browser, tudo da certo, o valor vai para a Tabela no Banco de Dados, mas o arduino não consegue enviar.

 

Se eu executar isso no navegador da certo (também da certo sem o https://)

https://www.charllesrocha.com.br/lucas_testes/inserir.php?temp=77

 

Segue o código do Arduino:

Testei vários códigos e exemplos da internet, acho que estou fazendo certo, lá nos exemplos disponibilizados são iguais, testei o SERVER tanto com a url do servidor quanto com o IP.

Também tentei via POST e não deu certo.

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

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 100, 23);
IPAddress myDns(192, 168, 100, 1);

EthernetClient client;

//char server[] = "www.charllesrocha.com.br";  // also change the Host line in httpRequest()
IPAddress server(195,154,33,96);

unsigned long lastConnectionTime = 0;           // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10*1000;  // delay between updates, in milliseconds

void setup() {
  Serial.begin(9600);
  while (!Serial) {
  }

  Serial.println("Initialize Ethernet with DHCP:");
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    if (Ethernet.hardwareStatus() == EthernetNoHardware) {
      Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
      while (true) {
        delay(1); // do nothing, no point running without Ethernet hardware
      }
    }
    if (Ethernet.linkStatus() == LinkOFF) {
      Serial.println("Ethernet cable is not connected.");
    }
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip, myDns);
    Serial.print("My IP address: ");
    Serial.println(Ethernet.localIP());
  } else {
    Serial.print("  DHCP assigned IP ");
    Serial.println(Ethernet.localIP());
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
}

void loop() {
   if (client.available()) { 
    char c = client.read(); 
    Serial.write(c); 
    }

  if (millis() - lastConnectionTime > postingInterval) { 
    httpRequest();
    }

}

void httpRequest() {
  client.stop();
  if (client.connect(server, 80)) {
    Serial.println("OK");
    client.print("GET https://www.charllesrocha.com.br/lucas_testes/inserir.php?temp=555");
    client.println(" HTTP/1.0");
    client.println("Host: www.charllesrocha.com.br");
    client.println("Connection: close");
    client.println();
    lastConnectionTime = millis();
  }
  else {
    Serial.println("connection failed");
  }
}

 

SEGUE LOG QUE VEM PELA SERIAL:

Initialize Ethernet with DHCP:
  DHCP assigned IP 192.168.100.20
OK

HTTP/1.1 301 Moved Permanently
Date: Sat, 18 Aug 2018 11:57:21 GMT
Server: Apache
Location: https://www.charllesrocha.com.br/lucas_testes/inserir.php?temp=555
Content-Length: 274
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://www.charllesrocha.com.br/lucas_testes/inserir.php?temp=555">here</a>.</p>
</body></html>

 

Link para o comentário
Compartilhar em outros sites

  • 1 ano depois...

Crie uma conta ou entre para comentar

Você precisa ser um usuário para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...