local host, port = "ulgrad.ru", 4999
local json = require('cjson.safe')
local base64 = require('base64')
local socket = require("socket")
local tcp = assert(socket.tcp())

tcp:connect(host, port);

   local pack = {}
    pack['id'] = 'test' 
    pack['bme'] = {['temp'] = 10,['press'] = 100,['alt'] = 300}    
    pack['dht'] = {['temp'] = 12,['humi'] = 67} 
    pack['uf'] = 5


-- eyJibWUiOnsiYWx0IjozMDAsInRlbXAiOjEwLCJwcmVzcyI6MTAwfSwiZGh0Ijp7Imh1bWkiOjY3LCJ0ZW1wIjoxMn0sInVmIjo1LCJpZCI6InRlc3QifQ==


tcp:send(base64.encode(json.encode(pack)))
print(base64.encode(json.encode(pack)))

while true do
    local s, status, partial = tcp:receive()
    print(s or partial)
    print(status)
    if status == "closed" then break end
end
tcp:close()
