Articles Hierarchy

Articles Home » RPI » PICO W advanced webserver 2

PICO W advanced webserver 2

we come from end of here


still not happy with the OSCI speed i asked forum for help
and `anecdata` send me to bufio
nu bench

while now in my big code see 327680.1 Hz
the above bench suggests even more is possible???

but when i check with PICO puls 1/10 ON/OFF ?1ms signal?
i see

to keep it with the rest i need to change the ULTRA RANGE 4096 to * 16



PICO_W PMS1W ULTRA

# new speed buttons: | ULTRA | FAST | >>> | >> | > | SLOW | DEAD |
# 320 samples in 0.98 millis, that is 0.003 millis sample time or 327680.1 Hz using delay -1 loops
# 320 samples in 5.86 millis, that is 0.018 millis sample time or 54613.3 Hz using delay 0 loops,
# 320 samples in 17.58 millis, that is 0.055 millis sample time or 18204.5 Hz using delay 10 loops,
# 320 samples in 59.57 millis, that is 0.186 millis sample time or 5371.8 Hz using delay 45 loops,
# 320 samples in 306.64 millis, that is 0.958 millis sample time or 1043.6 Hz using delay 255 loops,
# 320 samples in 1187.50 millis, that is 3.711 millis sample time or 269.5 Hz using delay 1000 loops,
# 320 samples in 5912.11 millis, that is 18.475 millis sample time or 54.1 Hz using delay 5000 loops,



but now i get from forum info that this call might work:
#adcbuf = analogbufio.BufferedIn(board.GP26, osciH, rate) # TypeError: extra positional arguments given
#adcbuf = analogbufio.BufferedIn(board.GP26, osciH) # good
adcbuf = analogbufio.BufferedIn(board.GP26, osciH, sample_rate=rate) # thanks 'anecdata'

good, with this i can rewrite the whole sampling


#osci startt 5555507812500, stopt 5555508789062 ns, 320 samples in 0.98 millis, that is 0.003 millis sample time or 327680.1 Hz, called rate 500000 Hz
#osci startt 5586831054687, stopt 5586833984375 ns, 320 samples in 2.93 millis, that is 0.009 millis sample time or 109226.7 Hz, called rate 100000 Hz
#osci startt 5597339843750, stopt 5597346679687 ns, 320 samples in 6.84 millis, that is 0.021 millis sample time or 46811.4 Hz, called rate 50000 Hz
#osci startt 5606213867187, stopt 5606246093750 ns, 320 samples in 32.23 millis, that is 0.101 millis sample time or 9929.7 Hz, called rate 10000 Hz
#osci startt 5614054687500, stopt 5614119140625 ns, 320 samples in 64.45 millis, that is 0.201 millis sample time or 4964.9 Hz, called rate 5000 Hz
#osci startt 5620358398437, stopt 5620678710937 ns, 320 samples in 320.31 millis, that is 1.001 millis sample time or 999.0 Hz, called rate 1000 Hz





OSCI_ULTRA_bufio.zip



ok, that is a nice one-channel 6$ OSCI: "PMS1W"
and at home can call the view / operation interface / web server from mobile / PC / TV
but what you do when you are ?on the road?
this web server should have a "AP MODE" ( not only "STA" )
( or like the home devices SonOff / Tasmota / from AP to STA installation procedure )
so no need to login to a router.. just call it phone / wifi / AP ssid /

try to find a AP web server example



that is the problem with that MEGA projects,
you never know how far you can go..
and i had it with Arduino and ESP, you got erratic behavior, where a bigger code fails more often..
but you had to try..


to push this on the limit i will try to also build in MQTT

JOB5 MQTT send ( means every 60 sec publish set of ( Volt Amp Watt ) data )
to a local broker RPI3 [192.168.1.103] ( what also has a Node-Red trend dash board
and a Sqlite3 historic data-collection



with the multi file structure add just a timer job is tricky already, esp about the en / disable of it by USB menu
hm.. i should build one EMPTY JOB6 USER spare ?
even the 1Mloop is at 70 sec already ( with all JOBs disabled ) ( 0.07 milli sec per loop but better as blocking... )



so: the timed JOB5 calls from file mqtt.py
send_MQTT()
what makes a counter and a JSON ( like string but use ' instead good " ) 'mqtts' to send.
for that string it needs the measuring data like from
* JOB1 PICOW_io A0 as volt and A1 as amp
or
* JOB3 INA volt amp watt
( only one should be enabled, default is board IO as i not know you have a INA )

at boot web_wifi.py
setup_webserver()
asks mqtt.py if useMQTT is True
so it also connects to broker, make topic, sends a 'hello' to broker..
see new details in '.env'

in
run_webserver() ( called by JOB0 and checks on web clients )
and when useMQTT is True
it gets the MQTT_count from mqtt.py
and if that increased it gets the new 'mqtts'
and publish it to broker..

i used RPI3 ( with ethernet cable ) at [192.168.1.103]
as broker and with mqttsub
alias mqttsub='mosquitto_sub -h localhost -u "u213" -P "p213" -v -t "P213/#"'
mqttsub
# P213 Hello Broker: i am a PICO W
# P213/P01 { 'id': 0, 'dev':'P01', 'Volt': 0.00, 'Amp': 0.00, 'Watt': 0.00 }
# P213/P01 { 'id': 1, 'dev':'P01', 'Volt': 0.34, 'Amp': 0.40, 'Watt': 0.14 }
# P213/P01 { 'id': 2, 'dev':'P01', 'Volt': 0.32, 'Amp': 0.40, 'Watt': 0.13 }


so again, mqtt.py does not measure or send data, just prepares a string, the above {...}



looks good so far, but when i call OSCI i get memory allocation error again.
( right where i make the string for html after i add the SVG code string)

well i should have seen that b4 already,
i did a
svg ="{"
( 320 lines .. of ) svg += "...."

htmldata += svg


so that means the svg needs double memory, first as svg string and them inside htmldata string.
so that was a easy clean up



the modularity with the many *.py files is something good,
but as each job calls just the main function ( from its own file.. picow_io, dht, ina, ads, mqtt ) and its under 15 lines,
now i go backward and pack all 'jobx.py' into one 'jobs.py'

also there each jobs 'update_' sec is defined,
import and shown at console (REPL )

and read by code from menu for the job execution



no what i copied already is the Node-Red dashboard operation to TUNE the
+ filter
+ change the mqtt data publish rate
when that is working ( again ) i can zip all user config of this project.



in the old project i used it to filter the INA_Volt, INA_Amp, INA_Watt
and adjusted a faster/fix sample rate to INA job3

-a- it normally not makes sense to filter Watt ( just filter Volt and Amp before you multiply )
BUT if Watt is coming from a sensor ( INA ) it needs filter too.

-b- i want to move the filter from INA to short before MQTT
+ + so in webpage you see the original readings,
+ + in MQTT send filtered values
+ + + from MQTT can remote adjust filter and MQTT sample rate ( not hardware sample rate )

( note: currently i check on a google workspace mqtt store and graph with remote data from a island ( a friends professional project ), much more professional as
this here, my node-red tools .. default NR trend...
but see that filter is missing...
and for a startup / test work a faster data rate as 1min might be nice )


ok, for the filter:
there is ( like for Volt ) a ( Va = 0.8 .. 0.9 ) and a ( Vb = 1.0 - Va )
and the filter math is:
vf = Va * vf + Vb * v
that is a recursive filter first order
with Va = 0.8 means we allow a 20% change of the filtered value
by a change in 'v', the new sensor value
as that would always start from 0 there is a firstrun setting ( vf = v ) as better init

and a MQTT ( remote ) operation of
* MQTT publish rate
Volt Amp Watt:
* Filter enable
* V A W filter tuning
- - the regarding code is unreadable, as my Python is poor, and i have to see / change values ( like update5 aka MQTT job timer )
over several .py files.. so mixing import values, get_ and set_ values across the involved .py files




just to show what i mean with using RPI3 ( as broker and Node-Red dashboard )
first setup a new OS drive ( this RPI3 can boot from USB )

RPI3 Install log
try to follow it for your own setup



current version of
Multi_Task_Ains_Temp_DHT22_INA_ADS_USB_MENU_dynamicWebserver_OSCI_ULTRA_bufio_MQTT_RPI3work
PICO_W-PMS1W_pp.zip
were you find:
* * code ( /lib/ ,env *.py )
* * cp800b4 ( pico pico_w uf2 and bundle and nuke )
* * NRflows ( Node-Red flow export ( Flow1, Flow2, Flow3 ) )
* * python_tools ( to test your broker / Node-Red without a active client )