HTTP Post from Arduino to website

Hello,

I’ve been trying for while now to send data from an Arduino to my website with no success and I’m out of ideas of what the problem could be. Using Hurl.it the data is received perfectly by the website but when I try to send it from the Arduino it connects but I get a “SEND FAIL” message and it returns “RX_FINISHED_STR_NOT_RECV”.

Does anyone know what could be the issue?

Here’s some of the code I’m using.

PHP FIle


<?php
    include("connect.php");
    
    $link=Connection();

 $TEMP=$_POST["TEMPERATURA"];
 $UMID=$_POST["UMIDADE"];
 $TRAF=$_POST["TRAFEGO"];
 $CHUVA=$_POST["CHUVA"];
 $MQ4=$_POST["GASMQ4"];
 $MQ7=$_POST["GASMQ7"];
 date_default_timezone_set('America/Sao_Paulo');
 $TIMESTAMP=date("d/m/Y H:i");
 
 $query = "INSERT INTO `id2408464_dados`.`Dados` (`timeStamp`,`temp`,`umid`,`traffic`,`rain`,`gasMQ4`,`gasMQ7`) 
  VALUES ('".$TIMESTAMP."','".$TEMP."','".$UMID."','".$TRAF."','".$CHUVA."','".$MQ4."','".$MQ7."')"; 
   
    mysqli_query($link,$query);
 mysqli_close($link);
     
    header("Location: index.php");
?>

Arduino Snippet


void SubmitHttpRequest(){
	char temp_string[256];
	char msg[10];
	int numdata;
	if (inet.attachGPRS("timbrasil.br", "tim", "tim"))
	  Serial.println(F("status=Conectado..."));
	else Serial.println(F("status=Nao conectado !!"));
	delay(1000);
	String valor = generate_string();
	valor.toCharArray(temp_string, 256);
	Serial.println(temp_string);
	char path[] = "/add.php";
	char host[] = "posteinteligenteunb.000webhostapp.com";
	numdata = inet.httpPOST(host, 80, path, temp_string, msg, 10);
	Serial.println(msg);
	delay(5000);
}

We’re not specialised in arduino, I recommend you get help from stackoverflow.com

Thanks, so we can be sure that the issue isn’t in the server side code?

1 Like

Nope, It isn’t :slight_smile:

Well, it’s funny because i’ve been testing the arduino code using a GET request and it works perfectly for every single website tested, except for *.000webhostapp.com websites. So, if it isn’t the arduino code, and it isn’t the server code, would you know what else could it be?

@MarcusLeite Can you again after adding a domain(ex: test.com)?
As per Admin “it is possible to do POST/GET requests to a website and 000webhost supports post and get requests”. :slight_smile:

Sorry guys, but I’ll type in portuguese…

Olá Marcus.
Temos exatamente o mesmo problema no momento. Tenho pensado se o problema não é a porta que está no inet.hhtpPOST (no caso, a 80).
Você conseguiu algum progresso?
Ainda estou procurando uma maneira de resolver e, caso eu consiga, posto aqui pra você saber (caso ainda não tenha descoberto).

Explanation is depth please :smile:

Sorry.
In the program of the arduino we need to specify the port to connect and get/post to the server. When I use port 80, the connection isn’t established, nor when I put another values to the port.
Basicaly, I have this function:
“InetGSM::httpPOST(server, port, path, parameters, result, resultlength)”. An exemple is, in my code, “inet.httpPOST(“mgope.000webhostapp”, 80, “/add.php”, “cmd_texto=teste”, msg, 50)”, where I whant to post “teste” in the variable “cmd_texto” in the file add.php in my server “mgope.000webhostapp” by the port 80.
Another exemple is: “inet.httpGET(“google”, 80, “/”, msg, 50)” using the GET instead POST. In both, the port used is the 80.
Using the “$_SERVER[‘SERVER_PORT’]” php function on my websitepage, I’ve discovered the port (443) used when I acess the sit from my notebook, but when I tried to use this port, the error (fail to send data to the website page)is the same that when I use the port 80.
PS: there are no “.com” in the sites adress because I can only put 1 link in my reply
I’m sorry for any missunderstand by my english.

I’ll reply in both portuguese and english so anyone can understand it well.

Então, vou te falar que consegui resolver apenas mudando de servidor e contratando um VPS. O que acontece é que por ser um servidor gratuito e compartilhado existem alguns mecanismos de segurança implementados que acabam barrando a comunicação com o Arduino. Eu tentei utilizar o 000webhost, infinityFREE, e nenhum deles resolveu o problema. Precisei ir ao Hostinger.com e contratar a hospedagem para então descobrir que… também não liberavam o acesso do arduino por questões de segurança por se tratar de um servidor compartilhado. Assim, contratei um VPS (Virtual Private Server) com eles mesmo e finalmente consegui fazer funcionar adequadamente porém desembolsando 35 reais mensais.

So, I only got to make it work by hiring a VPS. The thing is that free and shared servers will always have security code to prevent any intrusion. and it won’t allow the requests using Arduino. I tried to use many different free hosts and the only way was to not only migrate to a paid one, but also had to pay for the VPS so it could be possible to make it work.

PT -> Entendi. Vou persistir aqui um pouco mais. Se não estou muito louco, um amigo conseguiu fazer enviar dados utilizando o GET, partindo de um arduino, porém numa comunicação WiFi. Creio que não haja difirença entre estar no wifi ou no gprs nesses casos, e também que, como eles conseguiram pelo GET, deve haver uma maneira de conseguir por POST.
De todas as formas, boa sorte com seu trabalho ai! Qualquer novidade que eu conseguir eu postarei aqui. Afinal, 35 por mês dá pra pagar o netflix já.

EN -> I see. I’ll keep my research. A friend of mine sayed that he sussefully send dada by a GET request from arduino. He used a wifi connection, but it may have no big diference between wifi and gprs, nor using POST instead GET. Any news I get, I’ll post here

PT -> Se conseguir, por favor, poste mesmo aqui porque passei um bom tempo tentando. Precisei apelar para recursos pagos porque o prazo do meu trabalho final tá chegando e sem funcionar não vou formar kkk Talvez tenha que adicionar alguma coisa no request relacionado à segurança.

EN -> Please let me know if you figure it out cause I spent a lot of time trying. I had to give in to paid options because that’s part of my senior design project and if it doesn’t work I won’t graduate lol Perhaps you need to add something in the request regarding security

PT -> Cá estou e trago boas novas! Descobri um site onde você realiza testes com POST e ele te mostra o que foi recebido de forma bem simples. Após tentar diversas coisas, consegui realizar um post nesse site utilizando a conexão GPRS, inclusive fazer posts seguidos sem precisar reiniciar a conexão. Foi triste ver o que estava atrapalhando, já que era algo tão simples. Agora trago outra questão: Eu consigo me conectar ao meu site do 000webhost, e consigo realizar um POST, mas o que recebo de volta inclui “X-Xss-Protection: 1; mode=block”, e não consigo fazer POSTs sequenciais, já que a conexão é cortada. Alguém sabe se é isso mesmo, ou se o erro está em algum outro lugar? PS: o que recebi está na logo abaixo.

EN (by Google Translate) -> Here I am and bring good news! I discovered a website where you perform tests with POST and it shows you what was received very simply. After trying several things, I was able to make a post on this site using the GPRS connection, including making posts in a row without having to restart the connection. It was sad to see what was upsetting, since it was something so simple. Now I bring another question: I can connect to my 000webhost website, and I can make a POST request, but what I get back includes “X-Xss-Protection: 1; mode = block”, and I can not do sequential POSTs anymore because connection is cut off. Does anyone know if this the reason, or is the error somewhere else? PS: What I received is in below.

HTTP/1.1 200 OK
Date: Fri, 04 May 2018 20:23:50
Done…
ATT: >
RIC: GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding:Z⸮⸮⸮⸮alive
Server: awex
X-Xss-Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Request-ID: df6a62ce428adb3ab392da51db0c38d