The use of the ESP8266 in the world of IoT

User avatar
By tytower
#20240 I see they have their own library too . There are .cpp files and examples in there that might give you a cluehttp://ubidots.com/docs/devices/arduino-wifi.html
About 1/3rd of the way down for the download.

It looks a bit different their way
User avatar
By joefly888
#20246 Ty, seems like ubidots is down right not, so can't test or access the page you suggested. But before it went down, I was able to test the post with new lines at each line. Still no go. Also I did have the var, I just did not paste it correctly. I edited my post with the new results with NL

I will update after looking at the wifi example.

FYI, I think it has to do something with the form-data post method. Still learning
User avatar
By joefly888
#20270 TY: got it!!

I believe you were right, it had to do with the "\n" at the appropriate places..... thanks for your help. Below is the code to post the readvdd33() voltage and post to ubidots..

I followed the format from this post http://forum.43oh.com/topic/5903-esp8266-iot-on-the-cheap/?p=55061&utm_content=13681891&utm_medium=social&utm_source=facebook



Code: Select all
wifi.setmode(wifi.STATION)
wifi.sta.config("your-SSID","your-PASSWORD")  -- need to wait for a few seconds to connect
print(wifi.sta.getip())  -- issue command to see local IP, may print nil prior to connection

idvariable = "your-ubidots-variableID"
token = "your-ubidots-token"


function postUbidots(level)
    connout = nil
    connout = net.createConnection(net.TCP, 0)
 
    connout:on("receive", function(connout, payloadout)
        if (string.find(payloadout, "201 CREATED") ~= nil) then
            print("GOOD POST");
        end
    end)
 
    connout:on("connection", function(connout, payloadout)
        local value = node.readvdd33() / 1000;   
        local var = '{"value": '..value..'}';
        local num = string.len(var);   
        local postval = "POST /api/v1.6/variables/"..idvariable.."/values HTTP/1.1\n"       
          .."Content-Type: application/json\n"
          .."Content-Length: "..num.."\n"
          .."X-Auth-Token: "..token .."\n"
          .."Host: things.ubidots.com\n\n"
          ..var.."\n\n";
        connout:send(postval)
    end)
 
    connout:on("disconnection", function(connout, payloadout)
        connout:close();
        collectgarbage();
    end)
 
    connout:connect(80,'things.ubidots.com')
end

tmr.alarm(1, 60000, 1, function() postUbidots(0) end)  -- post to ubicode every minute
Last edited by joefly888 on Sat Jun 13, 2015 7:48 am, edited 1 time in total.
User avatar
By aguspg
#20303 Hi guys,

We were updating our ESP tutorials so the ESP section was temporary taken down. Here they are:

- ESP8266 + Arduino: http://ubidots.com/docs/devices/ESP8266-arduino.html
- ESP8266 stand-alone: http://ubidots.com/docs/devices/ESP8266.html

Good to hear you posted with Lua. I've tested Lua from OpenWrt but not from the ESP. Btw here some Lua resources:

- a Lua example for the Arduino Yun: https://github.com/ubidots/ubidots-arduino-yun/tree/master/Content
- a Lua library a user did for OpenWRT in case you want to try it as well: https://github.com/ediy/Ubidots-Lua-OpenWRT-router-Ubidots-Real-time-data-monitoring