ESP8266 send data to emoncms

Hello,

with AT commands I try to send data to the server emoncms.org.
The data on the server side are not accepted. The database is left without a record.
Maybe someone can tell what's wrong here?
( To thingspeak.com server data are received correctly)

AT+CIPSTART="TCP","emoncms.org",80
CONNECT

OK
AT+CIPSEND=82
> GET /input/post.json?json={power:220}&apikey=5f95184d8fafxx***xx1e0fd9aad868 HTTP/1.0\r\nbusy s...

SEND OK

+IPD,315:<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /input/post.json was not found on this server.</p>
<hr>
<address>Apache/2.2.22 (Ubuntu) Server at h80-243-190-58.host.redstation.co.uk Port 80</address>
</body></html>

OK
CLOSED

-------- ESP8266 Firmware --------------------

AT+GMR
00200.9.5(b1)
compiled @ Dec 25 2014 21:40:28
AI-THINKER Dec 25 2014

 

 

 

Alvydas001's picture

Re: ESP8266 send data to emoncms

Sending to the server emoncms.org with AT commands:

AT+CIPSTART="TCP","80.243.190.58",80
CONNECT

OK
AT+CIPSEND=90
> GET /emoncms/input/post.json?json={power:210}&apikey=5f95184d8faf*-*-*-*-*-*-0fd9aad868 HTTP/1.0\r\nbusy s...

SEND OK

+IPD,2:ok
OK
CLOSED

The Arduino code (correct version):

#include <SoftwareSerial.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define SSID "xxx"
#define PASS "xxx"
#define MODULE_ID "ESP-01"
#define ONE_WIRE_BUS A2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

//*-- Hardware Serial
#define _baudrate 115200

//*-- Software Serial
//
#define _rxpin      2
#define _txpin      4
SoftwareSerial debug( _rxpin, _txpin ); // RX, TX

#define IP "80.243.190.58" // emonsms
//#define IP "api.thingspeak.com"
String GET = "GET /emoncms/input/post.json?apikey=5f95-x-x-x-x-x-x-x-x-ad868&json={boiler:";


void setup()
{
  Serial.begin(_baudrate);
  debug.begin( _baudrate );
  sensors.begin();
  Serial.println("AT");
  delay(5000);
  if(Serial.find("OK")){
    connectWiFi();
    debug.println("prisijungta");
  }
}

void loop(){
  sensors.requestTemperatures();
  float tempC = sensors.getTempCByIndex(0);
//  tempC = DallasTemperature::toFahrenheit(tempC);
debug.println(tempC);
  char buffer[10];
  String tempF = dtostrf(tempC, 4, 1, buffer);
  updateTemp(tempF);
  delay(10000);
}

void updateTemp(String tenmpF){
  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += IP;
  cmd += "\",80";
  debug.println(cmd);
  Serial.println(cmd);
  delay(2000);
  if(Serial.find("Error")){
    return;
  }
  cmd = GET;
  cmd += tenmpF;
  cmd += "}\r\n";
  Serial.print("AT+CIPSEND=");
  Serial.println(cmd.length());
  debug.println("AT+CIPSEND=");
  debug.println(cmd.length());
  if(Serial.find(">")){
    Serial.print(cmd);
    debug.println(cmd);
  }else{
    Serial.println("AT+CIPCLOSE");
  }
}

 
boolean connectWiFi(){
  Serial.println("AT+CWMODE=1");
  delay(2000);
  String cmd="AT+CWJAP=\"";
  cmd+=SSID;
  cmd+="\",\"";
  cmd+=PASS;
  cmd+="\"";
  Serial.println(cmd);
  delay(5000);
  if(Serial.find("OK")){
    debug.println("OK");
    return true;
  }else{
    return false;
  }
}

rbreuss's picture

Re: ESP8266 send data to emoncms

Hi, 

do I understand correctly, you solved it and that code you shared is working now? If so, let me to ask you two questions to ensure myself, I understand it:

1) This code is for to be uploaded directly into ESP8266?

2) If so, HW serial is used for to send data to WiFi and SW serial for debug?

Or am I completely wrong and this code is for Arduino connected via HW serial to ESP module?

Radek

Alvydas001's picture

Re: ESP8266 send data to emoncms

1. - No!

2. - Yes, this code for Arduino connected via HW serial to ESP module.

rbreuss's picture

Re: ESP8266 send data to emoncms

Thanks, I got it in the meantime. I modified your code slightly and now it sends data measured but Arduino Due directly via WiFi into my Emoncms dataserver, It eliminates completely Raspi and Emonhub from landscape. Thats really a great piece of hardware !

mel's picture

Re: ESP8266 send data to emoncms

Hi Rbreuss,

Could you share your sketch?

Thanks

rbreuss's picture

Re: ESP8266 send data to emoncms

Sure, just give me a short time to remove unused rows and to some comments to used rows. Now it looks too messy. But Im surprised, how easy it works.

Radek 

rbreuss's picture

Re: ESP8266 send data to emoncms

So here is that sketch promised. It works on Arduino Due with ESP8266 (ESP01) powered from this Arduino (ATTENTION - powered from 3,3V pin !!!) and connected to Serial2 TX/RX. To get it working, ESP01 pin CH_PD has to be at high state (connected to 3,3V). You have to write there your WiFi SSID and passwd, your domain with emoncms (emoncms is installed in domain/emoncms folder) and you have to fill in your RW apikey. And when you connect real DS18B20 sensors, you have to comment out that hardwired temperature value at the end of sketch. Good luck and let me know your feedback.

Radek

arduino_man's picture

Re: ESP8266 send data to emoncms

I am a little bit stuck and I could REALLY use some help. So my friend and I are trying to send data through a server to a database (ESP8266 + Arduino, Apache Server and Mysql Database). When we send data, it says “send ok” and after that it says connection timeout. On apache it says 408 error. A few times we got 200 4961 (this is what we want) but that only happens when we send GET /HTTP/1.1 and when we send to GET/index.php?img=pngPlugIn HTTP/1.1. We try to send GET /pm/add_message.php?pmu=RAL005-07001-FL02-0030-2L Host:192.168……. but we get 408 320. Any suggestions? Do you know what we might be doing wrong? ((I have attached a list of the log in a word document in case anyone wants to view. Thank you!)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.