logo elektroda
logo elektroda
X
logo elektroda

[Solved] [Air200] How to write a temperature string to an array in Lua on Air200?

czasnagli 1344 8
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 16917006
    czasnagli
    Level 17  
    Welcome!

    In a lua script I have a function stop() that reads the temperature from the DS3231. The temperature is returned in the form
    Code: Lua
    Log in, to see the code
    .
    I want to save the above string to an array to call (use) it in another function. How can this be done?
  • ADVERTISEMENT
  • #3 16917424
    czasnagli
    Level 17  
    I am already explaining.
    I have connected a DS3231 to the Air200 gsm module from which I read the temperature via I2C. The temperature reading is realised by a function.
    Code: Lua
    Log in, to see the code
    .

    Calling the above function in the script returns the read temperature as (console preview).

    [Air200] How to write a temperature string to an array in Lua on Air200? .

    I want to send the read temperature string by sms. A function is used to send sms messages.
    Code: Lua
    Log in, to see the code
    .

    The problem is that if I make a notation
    Code: Lua
    Log in, to see the code
    .
    then the temperature text message is not sent.

    However, if I assign the value "test" to the variable "a"
    Code: Lua
    Log in, to see the code
    .
    then the sms is sent with the message "test".

    So I thought of storing the temperature read from the stop() function into an array, and then reading it in the function that sends the sms message. E.g.
    Code: Lua
    Log in, to see the code
    .

    The whole script looks like this.

    Code: Lua
    Log in, to see the code
  • ADVERTISEMENT
  • Helpful post
    #4 16917657
    JacekCz
    Level 42  
    Code: Lua
    Log in, to see the code
    .

    First of all, in the description you state that stop() RETURNS .... well, it doesn't return anything (it just prints), only after this correction.
    The two dots are the string concatenation (concatenation) operator. I won't swear that I transferred your expression perfectly, I tried.

    See if it gets you closer to the result (not tested in the real world)
  • #5 16917983
    czasnagli
    Level 17  
    JacekCz wrote:
    Let's see if this gets you closer to the result (not tested in real life)
    .
    After your fix, the sms with the temperature reading is sent in the format as above. Thank you for your help :) .
  • #6 16926209
    czasnagli
    Level 17  
    Let me ask you about another case with which I have a problem.

    Example I. - works fine.

    In the script there is a function time() which sends a command ril.request("AT+CCLK?") , and in response I get +CCLK: "12/06/01,10:15:45-00" .

    [Air200] How to write a temperature string to an array in Lua on Air200? .

    Example II. - works correctly.

    In this case, the command ril.request("AT+CCLK?") is assigned to the variable "a" and sent to the module by the function print(a) . The module response is +CCLK: "12/06/01,10:40:38-00" .

    [Air200] How to write a temperature string to an array in Lua on Air200? .

    Example III. - does not work correctly.

    In this example I used the function io.write(a, "a" ) , which sends to the module the string assigned to the variable "a" . As can be seen below the string ril.request("AT+CCLK?") is printed, but the module does not return a response +CCLK: with date and time.

    [Air200] How to write a temperature string to an array in Lua on Air200? .

    Script from the third example
    Code: Lua
    Log in, to see the code
  • ADVERTISEMENT
  • #7 16926238
    JacekCz
    Level 42  
    czasnagli wrote:
    I will ask about another case I have a problem with.


    Example III. - does not work properly.

    ...

    Script from the third example
    Code: Lua
    Log in, to see the code
    .

    I don't know what you expected from this code. A string is the ONLY string.
    As if you wrote io.write "flightNaMarsa()" it would not print the flight report.

    You could speculate that you confused what's inside the string and what's outside, but you've put in too much work for a case of .... i don't understand
    Added after 3 [minutes]:
    Trying to guess what you might have meant.
    Even the electrode syntax window shows what is inside the string and what is outside.

    Code: Lua
    Log in, to see the code
  • ADVERTISEMENT
  • #8 16928531
    czasnagli
    Level 17  
    JacekCz wrote:
    I don't know what you expected from this code. A string is the ONLY string.
    As if you wrote io.write "flightNaMarsa()" it would not print the flight report.
    .

    Good point. I now know where I made the mistake. Thanks for your help.
  • #9 17794025
    czasnagli
    Level 17  
    Thanks for your help.

Topic summary

The discussion addresses how to capture and store a temperature reading string from a DS3231 sensor connected via I2C to an Air200 GSM module using Lua scripting. The original function, stop(), printed the temperature but did not return it, preventing reuse in other functions such as sending SMS messages. A corrected Lua function was provided that concatenates the temperature bytes into a formatted string, assigns it to a variable, and returns it for further use. This enables sending the temperature reading via SMS by passing the returned string. Additional discussion touched on handling AT command responses (e.g., AT+CCLK?) and the distinction between sending command strings and processing their responses in Lua on the Air200 platform.
Summary generated by the language model.
ADVERTISEMENT