I have a problem with ESP8266 12E and 12F series about write commands. When I need to write data to the flash in ESP8266 it only allows to around 6800 times with (w+) command. I am using both integer and float and lastest and previous firmwares but nothing changes. An example simple code is below. With ESPlorer I run the codes and when both test1 lua and test2 lua reaches to 3400 file system starts to reset the module. I only activate module by formatting it. If I use just one file it reaches around 6800 cycle of writing. With (a+) command and 2 files I only managed to write up to total 13600 number somehow. Then again a format is needed. I do not how to erase and where to erase flash form lua file.
Any help would be appreciated.
test=0
tmr.alarm(6, 100, 1, function()
file.open("test1.lua","w+")
file.writeline(test)
file.close()
file.open("test2.lua","w+")
file.writeline(test)
file.close()
test=test+1
end)
Related
I have a ZTurn board that mounts a Zynq 7020. In the PL part I have a programmed code in AXI4-Lite slave that contains the programming code of the part of interest that I need (VHDL).
In this block, when I send "start" in the PS I write '1' to slv_reg0(0) and I tell it to start capturing data; it would be capturing 32-bit data (1 every 2 MHz) that I want it to store in DDR memory from the PL part.
At the end of the capture process, when I send "stop" in the PS (writting '0' in slv_reg0(0)), what I want is to stop saving data in DDR memory and then begin the process of reading the data from the entire written memory in the main.c file
I know that to do this I need to implement some kind of DMA connection but I would like to know how to do it. My level of knowledge in this field is very limited and I can't find any tutorial that fits my exact needs.
What I want to know is what I have to change from my AXI4-Lite slave and where to put the VHDL code and how to write the data to the DMA block in different addess positions.
Thank you.
I have Openwrt router with Arduino connected via USB FTDI adapter.
Serial port is /dev/ttyUSB0
Arduino code prints some data:
First part of data printed with delay via command print(), for example:
Serial.begin(9600);
Serial.print(var1);
delay(1000);
Serial.print(var2);
delay(1000);
Serial.print(var3);
delay(1000);
And second part printed with println() command:
Serial.println("");
Serial.println(var4);
Serial.println(var5);
Serial.println(var6);
So when I open Serial port in terminal I can see something like this:
1
then timeout in 1 sec, then
1 2
next timeout. and then
1 2 3
last timeout and
1 2 3
4
5
6
It works in Terminal program and in console in OpenWRT, for example screen /dev/ttyUSB0
I need make a Lua script that will read Serial port and print the data in the same way. I have a simple script, but it doesn't work as expected.
rserial=io.open("/dev/ttyUSB0","r")
while true do
chain = nil
while chain==nil do
chain=rserial:read();
print(chain)
end
end
it shows all data at once.
it doesn't show first 3 vars one by one with delays.
Seems it is because of rserial:read() - it will read until it receives a newline character.
It stated in similar question:
How to read from a serial port in lua
I tried to run this command as was advised there:
stty -F /dev/ttyUSB0 -icanon
but it doesn't help and I don't understand why.
Is it the way to fix this behavior via stty?
or I definitely need to use another Serial libs for Lua script?
All of these libs seems pretty outdated for now and I don't want to use outdated stuff..
From the Lua Reference Manual:
When called without formats, it uses a default format that reads the
next line (see below).
A new line is anything in the buffer until the next newline character.
So as long as you don't send a newline character Lua will wait one as it has been told by calling read()
Once a newline character is received you will be prompted any other character in that line.
Terminal programs usually update every byte to show what they receive in "real-time".
So if you want to have the same behaviour you may not use read() without any arguments.
Use read(1) to read every single byte without waiting for anything else.
I'm trying to use this 'advanced lua obfuscator' named XFuscator to obfuscate some code I created. However, I am not sure about how to go about using this. Could you guys give me a brief explanation? Here's the github link: https://github.com/mlnlover11/XFuscator
Thanks in advance.
Download XFuscator source code to your computer.
Fix error in the file XFuscator\Step2.lua (see below)
Open console and cd to XFuscator root directory (where README.txt is located)
Run lua XFuscator.lua "path\to\your_program.lua" (lua should be in your PATH)
See the result (obfuscated program) is in path\to\your_program [Obfuscated].lua
Please note that obfuscated program can run only on the same OS and on the same Lua version (obfuscated program is heavily depends on math.random() and math.randomseed() behavior, these functions are OS-dependent and Lua-dependent).
You can play with option -uglify and levels of obfuscation (see usage message inside XFuscator.lua)
About the error:
In the file XFuscator/Step2.lua the logic of lines #5,#6,#12 is incorrect:
Line #12 of Step2.lua uses the number intact (double has 17 digits precision), while only 14 digits (that's the default Lua number format) are saved into obfuscated file on line #6. This inconsistency sometimes leads to different pseudorandom sequence and you see error message attempt to call a nil value when trying to execute your obfuscated program.
Not all Lua implementations are sensitive to fractional part of a number given as an argument to math.randomseed(); for example, PUC Lua simply ignores fractional part, only low 32-bits of integer part are accepted as seed (unfortunately, Lua manual keeps silence about that). So, it is better for the seed to be an integer.
How to fix the error:
Replace line #5
local __X = math.random()
with the following line:
local __X = math.random(1, 9^9)
I'm wondering if it's possible to add timestamps to the journal file?
It appears that a date & time are recorded when SPSS is started, but if you have the program open for longer periods of time (i.e. days) it doesn't break it up if the program isn't closed.
Having timestamps would make it much easier to find what I'm looking for the times I look back to find things.
This is what I use to insert timestamps into my output:
HOST COMMAND=['echo %time%'].
However the journal file only shows the syntax.
The journal file is kept flushed and closed by Statistics, so you can probably write to it from another process. I don't think the suggestion above will work, because it will write the code but not the output to the journal. However, using Python you could do something like this.
begin program.
import time
open(r"full path to your journal file", "a").write("* " + time.asctime() + "\n")
end program
I can't see why it shouldn't work, unless you are not using a windows operating system.
On Unix-like system like Linux or Mac which run the bash (shell) you would rather use
HOST COMMAND =['date'].
If you have the Python extension installed you could also use Python code to to print the date and time (which would be a platform independent solution).
BEGIN PROGRAM.
import time
print time.ctime()
END PROGRAM.
I have a cluster app that uses a distributed Redis back-end, with dynamically generated Lua scripts dispatched to the redis instances. The Lua component scripts can get fairly complex and have a significant runtime, and I'd like to be able to profile them to find the hot spots.
SLOWLOG is useful for telling me that my scripts are slow, and exactly how slow they are, but that's not my problem. I know how slow they are, I'd like to figure out which parts of them are slow.
The redis EVAL docs are clear that redis does not export any timekeeping functions to lua, which makes it seem like this might be a lost cause.
So, short a custom fork of Redis, is there any way to tell which parts of my Lua script are slower than others?
EDIT
I took Doug's suggestion and used debug.sethook - here's the hook routine I inserted at the top of my script:
redis.call('del', 'line_sample_count')
local function profile()
local line = debug.getinfo(2)['currentline']
redis.call('zincrby', 'line_sample_count', 1, line)
end
debug.sethook(profile, '', 100)
Then, to see the hottest 10 lines of my script:
ZREVRANGE line_sample_count 0 9 WITHSCORES
If your scripts are processing bound (not I/O bound), then you may be able to use the debug.sethook function with a count hook:
The count hook: is called after the interpreter executes every
count instructions. (This event only happens while Lua is executing a
Lua function.)
You'll have to build a profiler based on the counts you receive in your callback.
The PepperfishProfiler would be a good place to start. It uses os.clock which you don't have, but you could just use hook counts for a very crude approximation.
This is also covered in PiL 23.3 – Profiles
In standard Lua C, you can't. It's not a built-in function - it only returns seconds. So, there are two options available: You either write your own Lua extension DLL to return the time in msec, or:
You can do a basic benchmark using a millisecond-resolution time. You can access the current millisecond time with LuaSocket. Though this adds a dependency to your project, it's an effective way to do trivial benchmarking.
require "socket"
t = socket.gettime();