logo elektroda
logo elektroda
X
logo elektroda

[Solved] [ESP8266] How to format and process strings in LUA on ESP8266?

piterek-23 6285 52
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #31 15719633
    piterek-23
    Level 33  
    I found a STRONE where you can build your firmware for the ESP.
    What should be in the firmware for my target to come up with this minimum?
    [ESP8266] How to format and process strings in LUA on ESP8266?
  • ADVERTISEMENT
  • #32 15720078
    piotr411
    Level 22  
    Again, use text, avoid this because it kills your memory. Assign sensor names to numeric values. LUA ESP has limited. space for global variables. After that, you can make each sensor in different files, and write the data into one common one.

    Casotome firmware is very unpredictable, on top of that it is bizarre to load and handle. You don't have to tick anything because these are just modules extending the capabilities of standard or new functions. For example, you use Uart, the 2015 version you currently have won. you can only set the speed and the number of bits, you cannot set the parity and the stop bit. Only selecting the uart module will give you such possibilities. And so with almost every function, something is improved there.
  • #33 15720207
    piterek-23
    Level 33  
    What else can I change here?
    init.lua
    Code: Lua
    Log in, to see the code

    With such a file I have an error in line 39 that is here:
    Code: Bash
    Log in, to see the code
  • ADVERTISEMENT
  • #34 15720212
    piotr411
    Level 22  
    Sensor = (Ip0+"1") should be Sensor = (Ip0. "1")
    My mistake, I am writing in another language and an error crept in automatically, sorry

    Code: Lua
    Log in, to see the code
  • #35 15720228
    piterek-23
    Level 33  
    That is to say, I had previously done well :)

    I don't think any of this is going to happen...
    Code: Bash
    Log in, to see the code

    Code: Lua
    Log in, to see the code
  • #36 15720242
    piotr411
    Level 22  
    WhatSensor = "rainfall" What is this for when you have the sensor name already here: Sensor = (Ip0 .. "1")
    Don't use string variables !!!!!!!!, replace them with numbers.

    I will not check this program in its entirety bu I would have to collate everything you have connected, the search algorithm checked works.

    You can use local variables, and put each sensor in a different file, each subsequent file will refer to the next and add the sensor data to one file, simple file and string operations.
    Then you have at your disposal not 20kb, but the whole 4MB that are in the ESP 12E.
    I wrote earlier, the program is not well thought out and you produce too many unnecessary variables, you do not delete them when they are unnecessary. ESP has so much memory that it can not only show names, but also speak and sing. You just have to manage the memory rationally.

    One more note, LUA loads the program into memory uncompiled.
    That is, with all names, comments etc.... if you have a long variable name, it will also eat up memory by compile time. avoid this.

    You can do it like this:
    - program each sensor in a separate file on local variables, leave one variable as global and save this global to a common file.

    finally, you take the data from the files where you added the results and process it yourself.
    I also wrote that getting rid of the AVR will make the whole project much easier.

    And why do you persistently put a string into the program, when you already know that it massacres the memory?

    Every time I give you an example and remove string variables, they come back like a boomerang.

    Do you know the types of variables?
    - numeric, character
    - local, global?
    because this is probably where we have the biggest problem.
  • #37 15720261
    piterek-23
    Level 33  
    I have to send to NetTemp:
    - key
    - IP NetTemp
    - type
    - value
    - IP of the sensor/module
    - device

    1. "key" I have to set the same in the remote module and in Nettemp
    2. "IP NetTemp" is simply the IP of the Raspberry
    3. "type" is what kind of data I send, e.g:
    - "temp" is temperature
    - "humid" is humidity
    - "press" is pressure
    4. "value" is the reading from the sensor in question
    5. "ip" is the IP or module name from which I send data
    - from one IP I can send several different readings, but of different types
    - from one IP I cannot send several different data of the same type
    6. "device" here is actually "wireless", because everything is sent over WiFi
  • #38 15721148
    piterek-23
    Level 33  
    piotr411 wrote:
    WhatSensor = "rainfall" Why this when you have the sensor name already here: Sensor = (Ip0 .. "1")
    Don't use string variables !!!!!!!!, replace them with numbers.

    Is there any other way to do this?
    In post #37 I wrote what this "JakiSensor" is all about
    piotr411 wrote:
    You can use local variables, and put each sensor in a different file, each successive file will refer to the next one and add the sensor data to one file, the usual file and string operations.
    Then you have at your disposal not 20kb, but the whole 4MB that are in the ESP 12E.

    piotr411 wrote:
    finally, you take the data from the files where you added the results and process it for yourself.

    Can you suggest what should go where?

    init.lua
    - wiFi connection
    - uART settings
    avr.lua
    -neTemp global settings
    -receiving data from UART
    sensor1.lua
    -transferring data from array [1] to NetTemp
    (...)
    sensor20.lua
    -transferring data from array [20] to NetTemp

    Is it supposed to be something like this?
    piotr411 wrote:
    Why I wrote that getting rid of the AVR will make the whole project a lot easier.

    I'm getting more and more convinced, but with my knowledge it's unlikely to be any good, probably too many of these sensors for this tiny ESP :(

    Sorry to be straining your patience.
  • #39 15724391
    uzi18
    Level 24  
    People dear, how much work is needed on such a powerful proc in lua to make the code work ... and do more than 1 measurement.
    Probably it is better to write it in C and have peace of mind.
  • #40 15724409
    piterek-23
    Level 33  
    @uzi18 if you have time, you want to help then show how to do it in C
    Code: Lua
    Log in, to see the code
  • #41 15724430
    uzi18
    Level 24  
    I can only sit down to work on it later in the evening (although my last evenings are dominated by The Witcher - Blood and Wine),
    the problem with LUA is not the lack of Flash, but the lack of RAM in the processor (you can't extend it) and you have to write the program very sparingly, under Arduino it's already a bit better.
    The line that gets esp ends with CR or CR+LF?
  • #42 15724438
    piterek-23
    Level 33  
    uzi18 wrote:
    I can only sit at it later tonight

    I will wait and week :)
    I won't do it myself because I have no idea how to do it....
    uzi18 wrote:
    The line that gets esp ends with CR or CR+LF?

    With AVR I can send what I want. I will send you what you need ;)
  • ADVERTISEMENT
  • #43 15724442
    uzi18
    Level 24  
    So insert a program that sends data to esp.
    The guys on the nettemp forum are already waiting for some replacement programs in C for current lua, I have to finally squat.

    Something more about your weatherman can you write?
  • #44 15724454
    piterek-23
    Level 33  
    I write the program on the AVR in BASCOM and send the data there now like this:
    Code: VB.net
    Log in, to see the code


    Added after 1 [minute]:

    uzi18 wrote:
    Something more about your weatherman can you write?

    @uzi18 we know each other from the NetTemp forum, and there I have probably already described everything :)
    Generally speaking, the METEO project is just emerging.
  • ADVERTISEMENT
  • Helpful post
    #45 15724478
    uzi18
    Level 24  
    data1 = "a:10.0" ?

    Apparently I didn't read something, on the nettemp forum.
  • #46 15724502
    piterek-23
    Level 33  
    How about another way... how do I send the data? I don't care how I send it :)
  • #47 15724633
    piotr411
    Level 22  
    uzi18 wrote:
    Ladies and gentlemen, how much work must be done on such a powerful proc in lua to make the code work ... and do something more than 1 measurement.
    Probably it is actually better to rewrite it on C and have peace of mind.


    What do you have in mind? Because to the best of my knowledge and experience, almost every function in LUA has a shorter syntax, plus there are a lot of them, much more than C, not to mention the module testing environment that is Arduino.
    Out of curiosity, I rewrote the application(in the part of assigning global variables and calculations) to Arduino and the global variables alone take up 84% of the memory. Arduino ESP, it's a failure. You have to be an exceptional hardcore to write applications in this pseudo C language.

    The author of this, does not understand the importance of optimisation. The topic is about string operations and that is already a closed topic. As time went on, it became apparent that you had to help write an entire application, and that's a different topic.

    I suggested moving parts of the program into separate files and using local variables. 4MB of Flash is plenty of memory for hundreds of files, 20kb of RAM is also perfectly adequate, the Atmega8 has 10 times less is 16 times slower, and you can write large applications.

    Another issue is, repetitively after each of my deletions, exactly unnecessary text variables and this saved as global. Not breaking variables, not once in the program did I find NIL.

    It is possible to help, but not to write entire applications. Yes it is possible, but for a fee.

    LUA, or Arduino, reserves a nightmarish amount of memory for Global variables, and this is where you have to look for savings, and the whole application is written in such a way that by the time it starts working it is already running out of RAM.

    If I see some willingness to write an application, I can help, but I will not write entire fragments or even an entire application for someone.
  • Helpful post
    #48 15725057
    uzi18
    Level 24  
    Arduino ESP relies on a pre-compile from which there is no possibility of cutting out unused functionality, so some flash and ram are lost as a rule, here there is actually a zonk.

    But in C you know more or less how much memory the program has at its disposal, here lua can suddenly cough up and you don't really know why, what happened and why?

    I will write what is in the code under this pseudo C and see if I also get 84%.

    piterek-23: just confirm to me if the data comes in the format I specified? char(10) is LF, it can stay that way.
  • #49 15725201
    piterek-23
    Level 33  
    piotr411 wrote:
    The author does not understand the meaning of optimisation.

    The author doesn't understand because he doesn't know and that's why he asks :)
    piotr411 wrote:
    The topic is about string operations and that is already a closed topic.

    Fact, I asked about one thing, and a lot more stuff came up....
    piotr411 wrote:
    In time, it became apparent that I needed help writing the whole application, and that's a different topic.

    It would be pointless to start a new topic so I am "pulling" the topic further here.
    piotr411 wrote:
    I suggested moving parts of the program to separate files and using local variables. 4MB of Flash is plenty of memory for hundreds of files, 20kb of RAM is also completely sufficient,

    That's why I asked what to move where, because I just don't know what's going on.
    piotr411 wrote:
    Atmega8 has 10 times less is 16 times slower, and you can write large applications.
    Atmega8 is slower
    ATmega is smaller, slower, writes in a grandfathered language-BASCOM, and a lot more things it can do than ESP
    piotr411 wrote:
    Another issue is, nagging after each of my deletions, exactly unnecessary text variables, and those saved as global. Not breaking variables, not once in the program did I find NIL.

    Mate I know you meant well, you wanted to help. For which I thank you very much. There are few people who are willing to share their knowledge. Maybe it looks that way, but I am really not a person who just takes-wherever I can help I help....
    piotr411 wrote:
    It is possible to help, but not to write entire applications. Yes it is possible, but for a fee.

    As you can, write on PW how much such a pleasure would cost me.
    piotr411 wrote:
    If I see some willingness to write an app then I can help, but I won't write whole sections or even an entire app for someone.

    I understand as much as possible.
    uzi18 wrote:
    piterek-23: just confirm to me if the data comes in the format as I specified? char(10) is LF, it can stay that way.

    It really is indifferent how I send it:
    "a:10.0"
    "a:10.0 "
    ":10"
    "10 "
    i will adapt ;)
  • Helpful post
    #50 15725423
    piotr411
    Level 22  
    1. Bascom is a very good language, much better than Arduino.
    2.
    Quote:
    "a:10.0"
    "a:10.0 "
    ":10"
    "10"

    This topic is closed, you got 2 examples. The first one I wrote to the syntax of the frame you gave in the first post, then you changed the construction of the framei then I wrote another example, you can as I counted well 9 more methods to use to extract information.

    Your problem is not the search, it is the amount of text variables you enter. I will refer to Bascom and give an example of what is involved:

    In Bascom you have a string declaration and it looks like this:
    Dim zmienna As String * 3   



    i.e. Bascom as a very good language will only take 3 bytes in memory
    in lua
    It is more twisted because:
    If you declare a variable in the main part of the program it is Global, i.e. carried "Function", every "For" loop etc....
    you declare it

    zmienna={} 


    As you can see you don't specify how many characters it has because by default it has 256 !!!
    In the program you have 20 such variables declared for the sensors which means that 256x20=5kb disappears already on the good day !!!
    then you enter 20 more variables for the sensor names, another 5kb
    and another and another until you reach the end, where you save a few bytes, and that's why you have the message, because you are simply out of memory.
    Deleting a variable, i.e. its value will be 0 if you put NIL into it
    that is
    czujnik1=NIL
    and it is already -256 bytes.

    LUA is a mix of Pascal and C, if you know these languages lua seems to be very easy and fun to program.

    LUA should also be distinguished from LUA ESP, just like Basic and Bascom

    In one of the posts you got a link to the LUA Reference, it only takes two evenings to write programs for ESP reasonably correctly and save RAM, after reading it.

    As for Flash memory, you can expand it 1GB with an ESP 12E or F, for example by plugging in a memory card. The ESP13 even has 32MB already to itself, your project is simple enough that it won't even take up 2% of the Flash memory that the ESP12 has.

    I wrote about splitting into smaller program files, this will certainly save RAM and you can reference a selected sensor, not all at once because you don't need to. I wrote about this stating that you have not thought through the design of the program and you would basically have to write everything from scratch.

    Forget about something like that, it won't work:

    JakiSensor={"rainfall","speed","wind","temp","temp","temp","temp","temp","temp","temp","humid","vcc","vcc","vcc","ppm","uv","lux","storm","lightning","press"}
    Sensor={"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20"}
    
    
  • #51 15725667
    piterek-23
    Level 33  
    I've sat up half the night and I don't get it normally....
    I did something like this:
    init.lua
    Code: Lua
    Log in, to see the code

    avr.lua
    Code: Lua
    Log in, to see the code

    and I get:
    Code: Bash
    Log in, to see the code

    Is there any LUA simulator so I can run my program virtually?
    @piotr411
    - what program are you writing in?
    - how do you check how much code takes up RAM etc?

    piotr411 wrote:
    Forget something like that, it won't work:

    JakSensor={"rainfall", "speed", "wind", "temp", "temp", "temp", "temp", "temp", "temp", "temp", "humid", "vcc", "vcc", "vcc", "ppm", "uv", "lux", "storm", "lightning", "press"}
    Sensor={"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20"}

    If I discard the "count" countdown from the program and leave just "count=1" it takes data from something like this
    Code: Lua
    Log in, to see the code

    and even LUA doesn't scream that its wrong.... :D
    Only how to deduct it here now? I.e. the program goes to "function SendData()" does this 20x "count" (from 1 to 20)
    Some kind of loop or something?

    I'm slowly starting to get fed up with this ESP, LUA....
  • Helpful post
    #52 15726598
    uzi18
    Level 24  
    Wait quietly, when I have sewn up my sample programme for the lcd I will convert it to what you need.

    Then I will propose something else in exchange for the ready-made I would ask for some board for ESP for nettop if it is possible :P
  • #53 17253404
    piterek-23
    Level 33  
    Electrode has asked to close the topic so I am closing ;)
ADVERTISEMENT