Left for archival purposes.

User avatar
By andrew melvin
#14022 That would be really awesome. This IDE has me making ESP modules doing 100x more than what I could with Node... and this is all with a total of 2w learning C...

I've never gone near a compiler before but this IDE is pretty groundbreaking!

Thank you!
User avatar
By Trilex
#14040 My Slow and Dirty Led Server. (shortened)

init.lua
Code: Select allprint(node.heap())
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","PASSWORD")
wifi.sta.setip({ip="192.168.178.111",netmask="255.255.255.0",gateway= "192.168.178.1"})
dofile("srv.lua")


srv.lua
Code: Select allfunction leds()
colors = ""
for key,rgbvalue in pairs(commando.options) do
    colors = colors .. string.char(rgbvalue.red, rgbvalue.green, rgbvalue.blue)
end     
ws2812.writergb(1, colors)
-- alarm deaktivate the leds because i only want a blink
 tmr.alarm(1,750,1,function()
    ws2812.writergb(1, string.char(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))               
    tmr.stop(1)
    end)
end

srv=net.createServer(net.TCP,10)
     srv:listen(80,function(conn)
         conn:on("receive",function(conn,payload)
         if string.find(payload, "RGB_LED") then
            payload = payload:gsub("%%22", '"')
            k, command = string.match(payload,"(text1)=(.+)")   
            command, k = string.match(command,"(.+)( HTTP/1.1)")   
            print(command)
            print(".....")
            print(k)
            commando = cjson.decode(command)
            print (teilstring)
            leds()
        end
        conn:send("<h1>hihodudidedu</h1>")
     end)
     conn:on("sent",function(conn)
          conn:close()
     end)
end)


use in browser with an adress like this:
Code: Select allhttp://192.168.178.111/?text1={"command":"RGB_LED","options":[{"red":255,"green":0,"blue":0},{"red":100,"green":200,"blue":100},{"red":0,"green":255,"blue":100},{"red":150,"green":100,"blue":255}]}


edit: I have NodeMCU 0.9.5 build 20150318

edit2: I am a lua noob... Can I do the two string.match in one line?
User avatar
By Speshal
#14078
Speshal wrote:
I need to be able to send the light values via an HTTP get ...

Code: Select allhttp://192.168.0.17/(0,255, 0):rep(10))'


Thanks in advance and Sorry for the n00b questions :)


Never mind - I fixed it myself :D

I sure have learnt a lot figuring it all out.

For anyone else that wants to be able to do it you just need to input the ip of your module and then the hex value of the colour you want preceded by a ~ symbol

e.g
Code: Select all192.168.4.1/~ffff00


:D
User avatar
By Markus Gritsch
#14100
andrew melvin wrote:That you guys might be able to provide a library for the new arduino ide...

I made a quick port of the C code here to the Sming framework. Complete example here:
viewtopic.php?f=6&t=2133&start=40#p14097

Attached below is the same code embedded in some self contained .ino file.

Have fun,
Markus
Attachments
(1.18 KiB) Downloaded 306 times