-1

My project consists of passing some data read by some sensors to a server with an Arduino Uno board and an ESP8266 module. I have managed to send data using thingspeak.com but when I try using my own server the connection fails. I think the mistake is somewhere in the URLs. The server works fine, tried with PostMan.

At the moment I am just trying to pass 1 as a value.

The whole URL is: http://arduino.otherperceptions.com/api/statistic/store?product_id=1&sensor_humidity=1&sensor_temperature=1&sensor_pressure=1&sensor_audio=1&sensor_vibration=1

AT+CIPSTART=4,"TCP","arduino.otherperceptions.com",80

    4,CONNE
    AT+CIPSEND=4,143


    OK
    > 
    Recv 143 bytes

    SEND OK

    +IPD,AT+CIPMUX=1

The code:

#include <SoftwareSerial.h>
#include <dht.h>

dht DHT;
#define DHT22_PIN 2
double temp;
double hum;

#define RX 10
#define TX 11
String AP = "***";       // CHANGE ME
String PASS = "****"; // CHANGE ME
String PORT = "80";
nt countTrueCommand;
int countTimeCommand; 
boolean found = false; 
double valSensor = 1;
SoftwareSerial esp8266(RX,TX); 

void setup() {
  Serial.begin(9600);
  esp8266.begin(9600);

}
void loop() {

 getTempAndHum();


 valSensor = temp;

 esp8266.println("AT+CIPMUX=1");

    printResponse();

    esp8266.println("AT+CIPSTART=4,\"TCP\",\"arduino.otherperceptions.com\",80");
    delay(1000);
    printResponse();

    String cmd = "GET /api/statistic/store?product_id=1&sensor_humidity=1&sensor_temperature=100&sensor_pressure=1&sensor_audio=1&sensor_vibration=1 HTTP/1.1";
    esp8266.println("AT+CIPSEND=4," + String(cmd.length() + 4));
    delay(1000);

    esp8266.println(cmd);
    delay(1000);
    esp8266.println(""); 
     delay(3000);
}


void printResponse() {
  while (esp8266.available()) {
    Serial.println(esp8266.readString()); 
  }
}

void sendCommand(String command, int maxTime, char readReplay[]) {
  Serial.print(countTrueCommand);
  Serial.print(". at command => ");
  Serial.print(command);
  Serial.print(" ");
  while(countTimeCommand < (maxTime*1))
  {
    esp8266.println(command);//at+cipsend
    if(esp8266.find(readReplay))//ok
    {
      found = true;
      break;
    }

    countTimeCommand++;
  }

  if(found == true)
  {
    Serial.println("OYI");
    countTrueCommand++;
    countTimeCommand = 0;
  }

  if(found == false)
  {
    Serial.println("Fail");
    countTrueCommand = 0;
    countTimeCommand = 0;
  }

  found = false;
 }


 void getTempAndHum(){
 DHT.read22(DHT22_PIN);


 temp =  DHT.temperature;
 hum = DHT.humidity;
}
  • you must send at least a Host header with GET request. add \r\nHost: arduino.otherperceptions.com\r\n after HTTP/1.1 – Juraj Dec 21 '18 at 14:26

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.