logo elektroda
logo elektroda
X
logo elektroda

[ESP8266] ESP8266 LUA - Problem sending full data to server

piterek-23 4110 16
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 15870705
    piterek-23
    Level 33  
    Hi,
    I need help with the code for ESP-12 written in LUA....
    The ESP is supposed to work like this:
    - AVR does all the reads/counts
    - wakes up the ESP from sleep
    - sends data via UART
    - ESP sorts the data, sends it to the server and when it finishes it goes to sleep

    The problem is that ESP doesn't want to send all the data-maximum 17 (last four missing) and there are 21 data (possibly more)
    I don't know myself anymore if the ESP is too slow or if the code sucks?

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


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


    Thank you in advance for your help and best regards.
    Piotr
  • ADVERTISEMENT
  • #2 15872565
    piotr411
    Level 22  
    Is it the device you are sending data to that has the ability to receive individual data rather than the entire data set?

    If it has such a possibility, then the data, instead of being sent to an array, i.e. RAM, can be written to a flash and then it is just a simple operation on strings and files
  • #3 15872570
    piterek-23
    Level 33  
    piotr411 wrote:
    Does this device you are sending data to have the ability to receive individual data and not the entire data set?

    Unfortunately, but only single data can I send :(

    Added after 3 [minutes]:

    I don't know what's going on, but now it's like I only have a certain amount of time to send and then the ESP goes to sleep. It doesn't wait for all the data to be sent :(
    Just wondering... maybe the watchdog is interrupting my sending because the task is taking too long? But how to stop it? (as long as he is the culprit)
  • ADVERTISEMENT
  • #4 15872660
    piotr411
    Level 22  
    You probably have the TimeOut set to 30s and do not close the session after sending.
    Each session must be closed and reopened for the duration of the data send.

    They think writing to and reading from files would take care of things here, but get rid of the AVR and connections via UART and large text arrays in the first place.

    then instead of into an array
    Code: Lua
    Log in, to see the code


    write to a file, each sensor on the next line and read in a loop through readln

    Code: Lua
    Log in, to see the code
  • #5 15872669
    piterek-23
    Level 33  
    piotr411 wrote:
    You probably have the TimeOut set to 30s and do not close the session after sending.
    Each session must be closed and reopened for the duration of the data send.

    And can you suggest how to do this?
    piotr411 wrote:
    get rid of the AVR and the connections via the UART and the large text arrays first.

    I won't be able to get rid of it because it's supposed to do all the (rather large) work, and the ESP is supposed to sort and send the data on. PCB done, everything mastered, everything works just missing those last four data :(
  • #6 15872684
    piotr411
    Level 22  
    first check what you have set in

    node.dsleep()
    rtctime.dsleep()
    wifi.sleeptype()
  • #7 15872704
    piterek-23
    Level 33  
    Oh chickens... but you bombed with information :)
    piotr411 wrote:
    check first what you have set in the

    node.dsleep()
    rtctime.dsleep()
    wifi.sleeptype()

    I don't have anything because I don't have it in the code.

    I just use:
    Code: Lua
    Log in, to see the code

    so that ESP goes to eternal sleep-AVR wakes it up.
  • #8 15872737
    piotr411
    Level 22  
    You do not have the modules uploaded, but the functions are active all the time. I guess you have to compile new firmware for yourself
  • ADVERTISEMENT
  • #9 15872753
    piterek-23
    Level 33  
    piotr411 wrote:
    I guess you have to compose yourself a new firmware

    I use:
    nodemcu_float_0.9.6-dev_20150704.bin
  • Helpful post
    #10 15872759
    piotr411
    Level 22  
    Here you have a quick program I wrote to retrieve data from flash memory line by line

    This is how I retrieve the entire contents of the file that is in the ESP
    let me know if you understand this code:

    Code: Lua
    Log in, to see the code
  • #11 15872834
    piterek-23
    Level 33  
    piotr411 wrote:
    I guess you have to compose yourself a new firmware

    Somewhere I saw a page where you can "build" your firmware, but I can't find it now.
    piotr411 wrote:
    program to download data from flash memory line by line
    This is how I download the entire contents of the file as it is in the ESP

    Such a small, silly question. What is this code supposed to be used for and why do I need it?
    piotr411 wrote:
    let me know if you understand this code:

    Honestly not really :(
  • Helpful post
    #12 15872863
    piotr411
    Level 22  
    http://nodemcu-build.com/

    ESP has 12,12E,12F has 4MB of memory for data, a kind of "hard disk"
    Results can be stored there and fragments can be downloaded so as not to occupy RAM
    When there is not enough RAM, even the whole 4MB or 16MB for ESP 13 can be transferred with one variable and without occupying RAM

    The program takes the data from the file in the ESP line by line and sends it to the tablet or other devices

    Instead of creating an array as you have now done, write it to "disk"
    This is what the code above is for
  • #13 15872877
    piterek-23
    Level 33  
    piterek-23 wrote:
    Somewhere I saw a page where you can "build" your firmware, but now I can't find it.

    Got it... is HERE
    but what should I mark?
    [ESP8266] ESP8266 LUA - Problem sending full data to server
    piotr411 wrote:
    Instead of creating an array as you have now done, save it to "disk"
    This is what the code above is for

    This has already appealed to me, but I'm afraid I'm too thin for such "acrobatics" :(

    You are quick as lightning in your replies and read my mind :)
  • ADVERTISEMENT
  • Helpful post
    #14 15872883
    piotr411
    Level 22  
    SSL: false
    modules: file,gpio,http,i2c,net,node,rtcfifo,rtcmem,rtctime,tmr,uart,wifi

    in this configuration your program does not report problems after adding 10 variables, but every now and then it crashes for 2 minutes, something with the Timers you messed up

    File operations are child's play in LUA
    Almost identical to QBasic

    Here you have everything beautifully described about files, including simple examples

    http://nodemcu.readthedocs.io/en/master/en/modules/file/
  • #15 15872891
    piterek-23
    Level 33  
    piotr411 wrote:
    SSL: false
    modules: file,gpio,http,i2c,net,node,rtcfifo,rtcmem,rtctime,tmr,uart,wifi

    I will build, upload and check
    piotr411 wrote:
    in this configuration your program after adding 10 variables reports no problems, but every now and then it crashes for 2 minutes, something with Timers you messed up

    It only transmits 17 variables and doesn't want any more :(
    piotr411 wrote:
    File operations are child's play in LUA
    Almost identical to those in QBasic

    For me it's secret knowledge, black magic and voodoo
  • #16 15872899
    piotr411
    Level 22  
    piterek-23 wrote:

    piotr411 wrote:
    File operations are child's play in LUA
    Almost identical to those in QBasic

    For me it's secret knowledge, black magic and voodoo



    Big exaggeration:)

    it is really simple, no more complicated than the arrays you have already mastered

    Added after 12 [minutes]:

    See how simple it is:

    You start by saying that you should create "some" file
    let's call it TEST.txt

    Code: Lua
    Log in, to see the code


    This program writes "Moisture sensor 1:89%" on the first line as if it were a piece of paper

    Now the fun begins and what you need to know:)

    "r": read mode (the default)
    "w": write mode
    "a": append mode
    "r+": update mode, all previous data is preserved
    "w+": update mode, all previous data is erased
    "a+": append update mode, previous data is preserved, writing is only allowed at the end of file

    That is, we used the write function "w" write :)
    file.open("TEST.txt", "w" )

    Now if you want to read 1 line in the TEST.txt file
    then this is enough:

    Code: Lua
    Log in, to see the code


    The variable a will contain the string Moisture sensor 1:89%

    simple?

    The next step is to add another line, delete the contents, set the cursor, etc......... ;)
  • #17 15892693
    piterek-23
    Level 33  
    @piotr411 thanks for all the tips ;)

    Topic exhausted, closing.
ADVERTISEMENT