Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

UDP Broadcast Receiving


Pflug

Question

Hi.

 

After reading and trying a lot I still have not managed to get the lua code right ?

 

Does someone have some instruction/sample code on how to read UTP Broadcast messages?

 

At last I have tried this code:

----------------------------------------------

local rxmsg = nil
local IPorErrorMsg = ""
 

local UDPsocket = Net.FUdpSocket()


UDPsocket = Net.FUdpSocket("192.168.1.13",50222)
 

local rxmsg, IPorErrorMsg = UDPsocket:settimeout(1)
local rxmsg, IPorErrorMsg = UDPsocket:receive()

 

fibaro.debug( "Received : " .. rxmsg )

 

-------------------------------------------------

 

But I do not even get an output from

fibaro.debug( "Received : " .. rxmsg )

 

Any help is highly appreciated!!

 

Thanks

 

 

Edited by Pflug
UTP should be UDP
Link to comment
Share on other sites

Recommended Posts

  • 0
  • Inquirer
  • Hi and thank you very much for your reply ;-)

     

    I am trying to understand what you are doing there and as usual I do not really get it ;-(

    So I have a few questions here:
    1. Do we need to broadcast something before receiving? 

    2. Where did you find the documentation for the: Net.FUdpSocket() ?? like:

    Please login or register to see this code.

    Please login or register to see this code.

    etc.
    The FIBARO_System_Lua_API.pdf did not give me any answers :-(

     

    I am googling for days now and I could only find this:

    Please login or register to see this link.

    and non of the functions work as discribed :-(

     

    Maybe I should specify what I am trying to do here.

    The WeatherFlow Smart Weather Station's hub broadcasts UDP messages over port 50222 on the local network.

    the Weatherflow UDP reference ( can be found here: 

    Please login or register to see this link.

     )

    specifies all broadcasted messages.

     

    I have also verified with Wireshark that the station is indeed broadcasting via the published port (50222)  and I can see messages like this: 

    ÿÿÿÿÿÿ°8)L#E$ÿuÀ¨ ÿÿÿÿÄ.Ä.l¤{"serial_number":"SK-000xxxxx","type":"rapid_wind","hub_sn":"HB-000xxxxx","ob":[1570779681,3.17,55]}

    Decoding this and placing it into a table will be the next challenge :-)
     

    Thanks for helping
    Jürgen

    Link to comment
    Share on other sites

    • 0
    9 minutes ago, Pflug said:

    WeatherFlow Smart Weather Station's

    WOW!

    Measured variables & features:

    • Outdoor temp, humidity, dew point, feels like temp.
    • Station pressure & sea-level pressure
    • Wind speed, wind direction, average & gusts
    • Lightning activity (approx. strikes and distance)
    • Rain onset, intensity, duration and approx. accumulation
    • Wind chill, wet bulb temp, DeltaT, Air Density
    • UV index, brightness, solar radiation

    i have Qubino Weather Station 

    Please login or register to see this link.

     but now this device not support yet. it's pain

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • The WeatherFlow station is indeed very cool.
    It detects raindrops!

    .. and yesterday it detected lightning in the area :-)

    ...and hopefully we will soon see some rain after 6 month without rain!

     

    I know that 

    Please login or register to see this link.

     has already intergrated the WeatherFlow  into his UHAS system.
    He seems to be very busy and but unfortunately he has not published it yet.

     

    I need the Weatherflow station to mainly read out the "Solar radiation per m^2"
    I need that information to calculate what power output I can expect from my solar system.
     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Sorry but I have to ask again:

     

    1. Do we need to broadcast something via UDP before receiving??? 

    2. Where did you find the documentation for the: Net.FUdpSocket() ??

    Link to comment
    Share on other sites

    • 0
    6 minutes ago, Pflug said:

    Do we need to broadcast something via UDP before receiving??? 

    1st send  packet

    2nd read (waiting) packets some time 

     

    7 minutes ago, Pflug said:

    . Where did you find the documentation for the: Net.FUdpSocket() ??

    idk. maybe nowhere.

    Link to comment
    Share on other sites

    • 0
    On 10/10/2019 at 12:37 PM, Pflug said:

    Does someone have some instruction/sample code on how to read UTP Broadcast messages?

     

    Did you ever get UDP receive of broadcast packets working into HC ?

    Edited by xAPPO
    Link to comment
    Share on other sites

    • 0
    12 hours ago, xAPPO said:

     

    Did you ever get UDP receive of broadcast packets working into HC ?

    Unfortunately NO!
    I could not find any docu about UDP receiving. So I gave up after weeks of No success
    It looks like UDP receive is NOT avilable in HC2 :-(

     

    ..but with an raspberry pi acting as UDP receiver and MQTT-Broker it is possible to retrieve MQTT  messages.

     

    The very clever "10der" has provided an MQTTY receiver code for HC2 and after some adjustments I am now retrieving my WeatherFlow messages via MQTT?
     

    Link to comment
    Share on other sites

    • 0
    33 minutes ago, pflugj said:

    It looks like UDP receive is NOT avilable in HC2 :-(

     

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    • 0

    Thanks for this:-)

    I do not get it .

    The messages from the Wetherflow Hub are broadcast
    from IP: 192.168.1.31 and port:50222

     

    so I changed 

    local ip = '192.168.1.31'
    local port = 50222

    ..but where do I find the received messages?

     

     

     

    Link to comment
    Share on other sites

    • 0
    9 minutes ago, pflugj said:

    Thanks for this:-)

    I do not get it .

    The messages from the Wetherflow Hub are broadcast
    from IP: 192.168.1.31 and port:50222

     

    so I changed 

    local ip = '192.168.1.31'
    local port = 50222

    ..but where do I find the received messages?

     

     

     

    Please login or register to see this code.

    Link to comment
    Share on other sites

    • 0

    I did put the code here:

    local selfId = fibaro:getSelfId()
    local socket = Net.FUdpSocket()
    -- with ip and port directly it does works as well
    -- socket = Net.FUdpSocket(ip, port)
    socket:setBroadcast(true)

    local ip   = '192.168.1.31'
    local port = 50222

     

    Output:

     

    [DEBUG] 10:22:58: false


     

    Link to comment
    Share on other sites

    • 0

    @pflugj idk how work your meteostation!

    1) it broadcasting periodicaly?

    2) it can response on req?

    3) if 2 than do you know req pacage format?!

    Edited by 10der
    Link to comment
    Share on other sites

    • 0

    1. The station is reporting periodically!

     

    I receive the messages on a local Raspberry Pi and then via MQTT Broker on the HC2


     

    UDP & API Data Access are dicribed here.
    I believe you can "NOT Request" data via UDP only via RESTful API ... butt this requires Internet Connection!

    the link:

    Please login or register to see this link.

    Link to comment
    Share on other sites

    • 0

    @pflugj I havnt HC2

    so i have edit code in notepad

     

    local udp = Net.FUdpSocket() -- create socket

    udp:setBroadcast(true) -- enable broadcating
    udp:setReadTimeout(0)  -- infinity

    udp:write("test","255.255.255.255", 50222) -- magic here!

     

    -- waiting message

    local rxMsg = nil
        local ipOrErrorMsg = ""
        -- repeat until the queue of all the device responses has been processed
        repeat
            rxMsg, ipOrErrorMsg = udp:read()
            if (rxMsg and string.len(rxMsg) > 0) then
                fibaro:debug(ipOrErrorMsg)

            end
            fibaro:sleep(1000)
        until (not rxMsg or string.len(rxMsg) <= 0)
     

    Link to comment
    Share on other sites

    • 0

    ... Sorry

    still nothing in the debug windows :-(

    fibaro:debug(ipOrErrorMsg)   - NO output 

    Link to comment
    Share on other sites

    • 0

    @pflugj as i can understand station broadcat periodicaly.

    you can catch packet when you running, 

    so script should hang here

    rxMsg, ipOrErrorMsg = udp:read()

    and waiting when somethig exists.

     

    so just run this

     

     

    local udp = Net.FUdpSocket() -- create socket

    udp:setBroadcast(true) -- enable broadcating
    udp:setReadTimeout(0)  -- infinity

    udp:write("test","255.255.255.255", 50222) -- magic here!

    local rxMsg, ipOrErrorMsg = udp:read()

    fibaro.debug(rxMsg)

    fibaro.debug(ipOrErrorMsg )

     

    when station send broadcast  VD shloud continue to running and print two chars

    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...