-->
Page 1 of 1

Read data from UART and send to server

PostPosted: Fri Oct 20, 2017 5:32 am
by mariusz84pl
Hi,
I'm trying to read data from UART and send them to server via TCP connection but stored data in variable is empty? But when printing this variable it is not empty.
How to resolve this?
Code: Select alluart.setup( 0,  57600, 8,    0,   1,    0    )

    uart.on("data", "{", function(raw)
        raw1 = raw1 .. raw
        if string.find(raw1, "}") then
        print("Recived: " .. raw1 .. "END")
        local raw2 = 'fffff' .. tostring(raw1) --test to see if something is sended, to server is sended only 'fffff'
        print("Sending to RPi")
        Send(raw2)
        uart.on("data")       
        end
      end, 0)

     
function Send(data)
print("Sending to RPi")
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end)
conn:connect(80,"192.168.1.12")
conn:send("GET /piec/dane.php?json="..data.." HTTP/1.1\r\n")
conn:send("Host: 192.168.1.12\r\n")
conn:send("Connection: keep-alive\r\nAccept: */*\r\n")
conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")
conn:send("\r\n")
conn:on("sent",function(conn)
                      print("Closing connection")
                      conn:close()
                  end)
conn:on("disconnection", function(conn)
          print("Got disconnection...")
          print(node.heap())
  end)
end


In Rpi i have php file to get var and store it in file. in file i only get "fffff" bot there is no raw2.
In file should be writen this:
Code: Select all{"DevId":"TASI7 S8","DevPin":"TASI7 OKN","Token":"DZWMW","FrameType":"SkzpData","TimeStamp":"18-34-54","BoilerTempAct":"5822","CH1ReturnTempAct":"5424","CH1ReturnTempCmd":"3000","CH1ReturnProtAct":"Off","BoilerTempCmd":"6000","DevStatus":"MOD09803101110","Alarms":"000000000000000000","DHWTempAct":"3867","DHWTempCmd":"4500","DHWHist":"500","DHWMode":"Timer","DHWPriority":"Off","DHWOverH":"1000","UpTime":"4d5h50m9s","CH1MixTempAct":"3802","CH1MixTempCmd":"3800","CH1MixTempBase":"3800","CH1MixTempMin":"2500","CH1MixTempMax":"5000","CH1MixValueAct":"33","CH1MixValueMin":"5","CH1MixValueMax":"100","CH1MixGain":"10","CH1MixPeriod":"10","CH1MixActive":"On","CH1RoomTempAct":"2286","CH1RoomTempCmd":"9999","CH1RoomTempEco":"1900","CH1RoomTempCom":"2100","CH1RoomHist":"50","CH1Mode":"Active","CH1RoomMode":"Off","CH2Mode":"Active","ExhaustTempAct":"10390","ExhaustTempMax":"25000","WeaTempAct":"1451","WeaTempStopCH1":"3500","WeaTempStopCH2":"3500","WeaCorr":"0","WeaObjCorr":"Mixer","BuTempAct":"4885","BuTotalFuel":"55266","Bu24hFuel":"1824","BuActualFuel":"106","BuModulMin":"15","BuModulMax":"100","BuTimeAboveMax":"30","BuAirMin":"10","BuAirMax":"31","BuAditAir":"16","BuFuelCaloric":"78","BuFuelCorr":"-30","BuMode":"Auto","BuSbyPeriod":"20","BuSbyAirTime":"15","BuSbyAirPwr":"30","BuSbyFeedTime":"5","BuIntFeedTime":"8","BuIntBreakTime":"70","BuIntAirPwr":"25","BuIntHist":"500","BuOptNoFireTime":"120","BuOptPwr":"12","BuOptFdrEff":"1960","BuOptFdrFTime":"4","DHWDays":"1111101000001000000000000000","DHWHours":"000000000333330000000000000000222233333333000000","DHWCDays":"0000000000000000000000000000","DHWCHours":"000000000000000000000000000000000000000000000000","CH1RDays":"0000000000000000000000000000","CH1RHours":"000000000000000000000000000000000000000000000000","CH2Days":"0000000000000000000000000000","CH2Hours":"000000000000000000000000000000000000000000000000","DHWCMode":"Stop","DHWCAlwaysON":"On","DHWCTempON":"4000","DHWCWork":"5","DHWCBrake":"0","DevType":"SKZP-02S V2.03 2017-07-17"}