GroveStreams

ESP8266 PUT method doesn't work492

The_Doctor private msg quote post Address this user
Hello,

I have problem with uploading data with ESP8266 (with ThingSpeak it works, but GS is a better solution for my application). I don't use Arduino HW or SW, but my own library (but this is probably not a problem).

In a web browser, this command works
http://grovestreams.com/api/feed?api_key=secretKEY&compId=bath&data=29&data=66


but when I do this with ESP8266
ESP8266_SendCmd("AT+CIPSTART="TCP","grovestreams.com",80");
ESP8266_SendData("PUT /api/feed?api_key=secretKEY&compId=bath&data=29&data=66 HTTP/1.1");

The ESP sends data to grovestreams
AT+CIPSTART="TCP","grovestreams.com",80
CONNECT
 
OK
AT+CIPSEND=95
 
OK
> 
busy s...
 
Recv 95 bytes
 
SEND OK

but nothing happen (values will not show on server).
I also tried this
ESP8266_SendCmd("AT+CIPSTART="TCP","grovestreams.com",80");
ESP8266_SendData("PUT /api/feed?api_key=secretKEY&compId=bath&data=29&data=66 HTTP/1.1\r\nHost: \r\nConnection: close\r\nContent-Type: application/json");

then I get answer from server
+IPD,487:HTTP/1.1 408 Request Time-out
Date: Sat, 05 May 2018 00:48:23 GMT
Server: Apache
Vary: Accept-Encoding
Content-Length: 293
Connection: close
Content-Type: text/html; charset=iso-8859-1
 
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>408 Request Time-out</title></head><body><h1>Request Time-out</h1><p>Server timeout waiting for the HTTP request from the client.</p><hr><address>Apache Server at www style="color: #339933;">.grovestreams.com Port 80</address></body></html>


Please, what am I doing wrong?
Post 1 IP   flag post
seckford private msg quote post Address this user
The following works in NodeMCU, and might be translateable:
 
--
-- s t a t e _ j
--
-- Transmit the sensor data via HTTP.
--
function state_j()
 
    -- The HTTP/1.1 string is added by the NodeMCU HTTP library.
    -- Adding it to the URL doesn't show up on a Grovestreams API
    -- check, but the last data value is dropped without warning.
    -- The HTTP library also adds a "Connection: close" header.
 
    local url = {
        "http://grovestreams.com/api/feed?",
        "&compTmplId=temp",
        "&compId=" .. GS_ID,
        "&org=" .. GS_UUID,
        "&api_key=" .. GS_PUT_KEY,
        "",
        "",
        "",
        ""
        }
    --  " HTTP/1.1\r\n"
 
    local headers = {
        "Accept-Encoding: identityrn",
        "Content-Length: 0rn",
        "Host: grovestreams.comrn",
        "Connection: closern",
        "rnrn"
        }
 
    -- There are at most four sensors.
    -- local t = string.format("&therm%d=%s%u.%02u", id, s, b, c)
    for idx = 1, #Sensors
    do
        local t = Sensors[idx].gettherm()
        if t ~= nil
        then
            url[idx + 5] = t
        end
    end
 
    -- Send the data to GroveStreams.
    http.put(table.concat(url), table.concat(headers), "",
        function(code, data)
            -- Check the network and HTTP return codes.
            -- Recovery from network errors is rare.
            if code < 0
            then
                set_led(Red)
                print("Network error: " .. code)
            elseif code ~= 200
            then
                set_led(Red)
                print("HTTP error code: " .. code)
            else
                set_led(Green)
                print("HTTP code: " .. code)
            end
 
        end)
end


I had to use Wireshark to find out exactly what NodeMCU was transmitting, and set it up the way GroveStreams expects.

Will
Post 2 IP   flag post
The_Doctor private msg quote post Address this user
Thanks! It already works. The problem was with the missing two "nn" at the end of the PUT command. This code string below is working example.
ESP8266_SendData("PUT /api/feed?api_key=secretKEY&compId=bath&data=29&data=66 HTTP/1.1nHost: nConnection: closenContent-Type: application/jsonnn");


Hope it helps another programmers which don't use 3rd party libraries.
Post 3 IP   flag post
sfm private msg quote post Address this user
can I have the code for uploading data with ESP8266, please?
Post 4 IP   flag post
3015 4 4
Log in or sign up to compose a reply.