Hi ciciocb,
now i am happy and here is the result of my work:
Code: [Local Link Removed for Guests]
LEDpin=33
pin.mode LEDpin, output
FLASHpin=4
pin.mode FLASHpin, output
pin(FLASHpin)=0
print
print
toggle 3
MIN_SPACE = 100000 'take pictures only if some space is left on flash or SD-card
wifi.connect "xx","xxxxxxxxxxx" ' ypur wifi access
print "connecting ";
While WIFI.STATUS <> 3
Print ".";
pause 500
wend
print
print "connected, ";
wmode=wifi.mode
if wmode=0 then print "wifi sleep moce"
if wmode=1 then print "wifi station mode"
if wmode=2 then print "wifi AP mode"
pause 2000
print
print ip$
print
rf=ramfree
ff=flashfree
print "RAM free:",rf
print "Flash free:",ff
print
ret=bas.device
print "Basic device:",ret
'if bas.device=202 then print "ESP32CAM detected"
OnUrlMessage received
'wait
z=0
do
z=z+1
option.wdtreset ' reset watchdog timer
loop
end
received:
wlog UrlMsgGet$()
a$=urlmsgget$("a")
print a$
r$=a$
kw$=ucase$(mid$(a$,1,3))
arg1$=mid$(a$,5,4)
arg2$=mid$(a$,10,4)
arg3$=mid$(a$,15,4)
arg1=val("&H"+arg1$)
arg2=val("&H"+arg2$)
arg3=val("&H"+arg3$)
if kw$="VER" then cmdVER ' VERsion
if kw$="RST" then cmdRST ' ReSeT
if kw$="CSU" then cmdCSU ' Camera SetUp
if kw$="FLH" then cmdFLH ' FLasH on/off
UrlMsgReturn r$
return
sub cmdVER
res1=1:res2=2:res3=3:n$="0000":n=0
hx res1
r1$=n$
hx res2
r2$=n$
hx res3
r3$=n$
r$="VER"+" "+r1$+" "+r2$+" "+r3$
end sub
sub cmdRST
res1=1:res2=2:res3=3:n$="0000":n=0
hx res1
r1$=n$
hx res2
r2$=n$
hx res3
r3$=n$
r$="RST"+" "+r1$+" "+r2$+" "+r3$
reboot
end sub
sub hx(n)
n$=hex$(n)
n$="0000"+n$
n$=right$(n$,4)
end sub
sub LEDon(LEDpin)
pin(LEDpin)=0
end sub
sub LEDoff(LEDpin)
pin(LEDpin)=1
end sub
sub toggle(n)
local i
print "Toggle ";n
LEDoff LEDpin
pause 1000
for i=1 to n
pause 300
LEDon LEDpin
pause 300
LEDoff LEDpin
next i
end sub
sub cmdFLH ' cmd flash
res1=1:res2=2:res3=3:n$="0000":n=0 ' setup default result
hx res1
r1$=n$ ' result 1
hx res2
r2$=n$ ' result 2
hx res3
r3$=n$ ' result 3
if arg1=0 then ' check arguments
pin(FLASHpin)=0 ' do the job
else
pin(FLASHpin)=1
end if
r$="FLH"+" "+r1$+" "+r2$+" "+r3$ ' setup return string
end sub
sub cmdCSU ' cmd camera setup
res1=1:res2=2:res3=3:n$="0000":n=0 ' setup default result
hx res1
r1$=n$ ' result 1
hx res2
r2$=n$ ' result 2
hx res3
r3$=n$ ' result 3
option.wdt 10000 'watchdog timer 10seconds
wifi.power 20 'maximize wifi-power
' variables with CAM parameters
quality = 10 : brightness = 0
contrast = 0 : saturation = 0
awb = 1 : awb_gain = 1
wb_mode = 0 : aec = 0
aec2 = 1 : ae_level = 0
agc = 0 : agc_gain = 0
gainceiling = 0
ret = camera.params("quality", quality)
ret = camera.params("brightness", brightness)
ret = camera.params("contrast", contrast)
ret = camera.params("saturation", saturation)
ret = camera.params("awb", awb)
ret = camera.params("awb_gain", awb_gain)
ret = camera.params("wb_mode", wb_mode)
ret = camera.params("aec", aec)
ret = camera.params("aec2", aec2)
ret = camera.params("ae_level", ae_level)
ret = camera.params("agc", agc)
ret = camera.params("agc_gain", agc_gain)
ret = camera.params("gainceiling", gainceiling)
option.wdtreset ' reset watchdog timer
if flashfree < MIN_SPACE then ' check memory
print "NO SPACE FOR FOTO!"
else
print "make Foto"
endif
ret=CAMERA.PICTURE("/PIC.jpg") ' set framesize
print
hx ret
r1$=n$
r$="FLH"+" "+r1$+" "+r2$+" "+r3$ ' setup return string
end sub
There are two minor problems:
1. To stop the programm i have to press the STOP butten in the IDE followed by
a reconnect. Then i must press again the STOP butten and the monitor will
answer "program finished". Why not on first STOP? Is this normal?
2. The responce time fpr this bidirctional HTTP communication is not very fast.
The TCP communication on my other modules with TCP commands is faster.
But at the moment i think it is fast enough.
For the next steps i will add:
1. commands for READ, WRITE and CLEAR EEprom.
2. Add data for mini windows on the captured picture (pos x,y, size x,y)
with 6? items.
3. Compare mini window pixels with the next captured pic and detect movement
of a modell locomotive. The result will be continous polled by the Host PC.
For example: On movement in square window 50,100,30,30 lok must stop
If this job is done, one camera for just 10 dollar can control a complete
central station. The Metallus Radio Train System (MRTS) is much cheaper
and has more possibiltys than the slow uncertain communnication over the tracks.
Thank you very much for your qualified and fast help!