PICO W: retrieving data w/o need of using database

I received my PICO W yesterday and I directly started to do different anvil tests.
So sending data to the PICO W is OK and I understand how it works.

I saw a YT video from Tom’s Hardware where Meredydd showed some possibilities of Anvil with the PICO W. Very interesting.

Meredydd, at a certain moment you connected a DHT22 to te the PICO W and connected to Anvil. Here you directly saved the data in the database and readied the database out to display the data in graphs for temperature and humidity. So far OK.
My question is now when I want read the data from the sensor like you did, can I do it without the need of using the database ? I just want to display the temperature and humidity on a page and refresh it at a certain rate with a timer. How can I do that?
Here my Pico side, which works correctly.


Just to test if I can retrieve the data on the Anvil side, I included print functions on the Anvil server side.
CleanShot 2022-08-18 at 18.29.15@2x
Then I noticed that the print function, printed the values on the Thony IDE output, just like Meredydd already told.

How can retrieve the data on the client side of Anvil to show the data on label of a page?

I still have not got to work with my picoW and anvil yet, is there an equivalent to
anvil.server.wait_forever()

in the pico library?

If so you should just be able to make a function on your pico that returns the results of the sensor measurement, and then decorate that function to make it callable.

You can call the function directly from the client if you wish, I think @Meredydd s example was more in-line with how a web page would use the data.

In his example it would be possible to have thousands of users reading the data from a table that was “pushed” to that table from the pico.

In the configuration that you are describing, every client who requests a reading from the pico will trigger a response from the device. If only you or a few people are using your app then this is fine, if it is open on the internet and you have lots of users your pico is going to have a bad time.

2 Likes

Perhaps you don’t want to store ALL the values, because all you need is the latest?

If that’s the case, then you can first get the row, then either update it or create it.

row = app_tables.measurement.get() or app_tables.measurement.add_row()
row['value'] = value

Thank you, that is how I succeeded now. I added only the first 5 rows and then started to update the first row and refresh the database. This is ok, but the real question was if it was possible to see the data on the client side without any use of the database, just to know if it is possible.

The pi reading the value and the browser showing it are two independent events happening at different times.

Websites always have a database for this reason: collect information so it can be reused.

If you are using the Anvil server and have the persistent server option on your plan, then you could keep the value in memory, but it will fail whenever the server restarts.

If the server is running on the pi itself, then you could keep it in memory and it should work.

Ok thank you again, now I understand.
The reason I asked because I build already this kind of project in the past with a Teensy (like an Arduino) and and ESP8266. The ESP8266 was configured as an access point and some Italian friend build MiuPanel. He modified a little bit the OEM soft of ESP8266 and he build a GUI, where you could build textfields, buttons, graphs etc… all written in compact html in the the Arduino C++ program and send the values to his MiuPanel app or receive the signal of a screen click back to activate something controlled by the micro. It worked fine, was very professional, but it was an intensive job to create the pages.

what is the reason when I get, when it worked correctly before and I didn’t change anything ?


and when I try to stop it I receive:
WARNING:root:Unexpected echo. Expected b’%Run -c $EDITOR_CONTENT\r\n’, got b’<CYW43 STA join 0.0.0.0>\r’

This has nothing to do with database.
You should ask a new question, with the correct subject.

1 Like