Hi,
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 http request 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
#include <SoftwareSerial.h>
#include <dht.h>
dht DHT;
#define DHT22_PIN 2
double temp;
double hum;
//int soundSensor = 2;
#define RX 10
#define TX 11
String AP = "****"; //
String PASS = "****"; //
String HOST = "arduino.otherperceptions.com";
String PORT = "80";
String field = "field1";
int countTrueCommand;
int countTimeCommand;
boolean found = false;
double valSensor = 1;
SoftwareSerial esp8266(RX,TX);
void setup() {
Serial.begin(9600);
esp8266.begin(9600);
sendCommand("AT",5,"OK");
sendCommand("AT+CWMODE=1",5,"OK");
sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK");
}
void loop() {
getTempAndHum();
valSensor = temp;
String getData = "GET /api/statistic/store?product_id=1&sensor_humidity=1&sensor_temperature="+String(valSensor)+"&sensor_pressure=1&sensor_audio=1&sensor_vibration=1";
sendCommand("AT+CIPMUX=1",5,"OK");
sendCommand("AT+CIPSTART=0,\"TCP\",\""+ HOST +"\","+ PORT,16,"OK");
sendCommand("AT+CIPSEND=0," +String(getData.length()+4),4,">");
esp8266.println(getData);
delay(4000);
countTrueCommand++;
sendCommand("AT+CIPCLOSE=0",5,"OK");
}
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);
Serial.println("Temperature = " + String(temp));
Serial.println("Humidity = " + String(hum));
temp = DHT.temperature;
hum = DHT.humidity;
}