logo elektroda
logo elektroda
X
logo elektroda

Extracting the value of a program variable and sending it via UDP (LUA language)

lukasz94w 501 5
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18177960
    lukasz94w
    Level 7  
    Hi. I am controlling an ESP8266 + NodeMCU v2 WiFi module (communication via UART) from an XMEGA processor. I send commands in LUA language to the module in this way. An example can be seen below:

    Code: C / C++
    Log in, to see the code
    .

    When I connect, I want to send the value of a software variable indicating the currently measured voltage on one of the processor peripherals (let's call it working name bat_lvl). The problem is that I don't know how to "extract" and send such a variable. So far, all I send is "static" text:

    Code: C / C++
    Log in, to see the code
    .

    Extracting the value of a program variable and sending it via UDP (LUA language) .

    Trying to send the value of the variable doesn't work (I can't see anything reaching the terminal I'm tapping on):

    Code: C / C++
    Log in, to see the code
    .

    Does anyone perhaps know the solution to my problem? I have looked on the internet for a solution but cannot find any example that answers my question.
  • ADVERTISEMENT
  • #2 18180726
    lukasz94w
    Level 7  
    Is there really no one who can help me?
  • ADVERTISEMENT
  • Helpful post
    #3 18180978
    mpier
    Level 29  
    Judging by the name of the function and the way it is called, it is used to send data from the microcontroller's flash memory. You need to send a variable from ram.
  • ADVERTISEMENT
  • Helpful post
    #4 18181130
    ex-or
    Level 28  
    As a colleague above rightly pointed out, you need a function that operates on RAM. I'm guessing that you are using the example codes from the book "AVR. Practical projects"? There is no buffered UART function reading the string placed in RAM, so you need to add such a function (you can also modify the existing one using the so-called named address spaces). I don't know which example you are using, for the interrupt version the function could look like this (yes, the buf parameter is not used, but that's how it is in the original codes :-/):
    Code: C / C++
    Log in, to see the code
    .
    Case 2.
    socket:send takes a string in the parameter, so the value of the variable has to be converted to a string and only then the whole command is sent via the UART to the NodeMCU.
    Code: C / C++
    Log in, to see the code
    .
  • ADVERTISEMENT
  • #5 18181255
    lukasz94w
    Level 7  
    I understand thank you for your hints. I will follow your advice, as soon as I achieve the desired effect I will present the solution for posterity :) .

    EDIT: Yes ex-or I am using the code from the book you mentioned.
  • #6 18182585
    lukasz94w
    Level 7  
    After applying the code suggested by you ex-or I obtained the intended effect. Professional help , thank you :) .

    Extracting the value of a program variable and sending it via UDP (LUA language)
ADVERTISEMENT