Anvil App + RaspberryPi + Database

Hello,

Thanks to this tutorials:
1 - https://github.com/anvil-works/anvil-runtime/blob/master/doc/getting-started.md
2 - https://github.com/anvil-works/anvil-runtime
3 - https://anvil.works/blog/open-source

I can create my web app in RaspberryPi (Thats great :smiley:)
https://anvil.works/build#clone:3NJCBG2T75UPVLXG=4PAG7VAKQK6ETQ3RSMFO2SKV

However, in Anvil IDE I add a Data Table, but when I open my app in my RaspberryPi, I dont have the Data Table.

I install psql command-line client.
I follow the topic : ā€œAcessing the databaseā€ in the tutorial 2 above, and then this:

Can someone tell me what I miss ?
Thank you

You can take a look at your

anvil.yaml

file. There should be a section called

db_schema:

There you should find the definitions of your tables. Are they there?

yes :slight_smile:

Then you should be able to start the app server with

anvil-app-server --app <app_dir> --auto-migrate

But the tables will be empty as it is a separate database. Just with the same schema.

I can start the server look:

the question is: i cant have acess to database like i have in Anvil IDE. I think i have install some more things but i dont know what

I fetching to the database strings to fill the drop down.

Should I have to install postgresql and create the table like I create in Anvil IDE ?

Sorry and never do this, i new in Anvil.

Postgres is already built in. From https://anvil.works/blog/open-source:

Wait, don’t I need to set up a database?

Nope! The App Server comes with Postgres built in, and by default will set up a new, private database in the .anvil-data/ directory.

1 Like

What I miss ?

I follow this, from Meredydd

I dont understand. :expressionless:

How did you populate your data tables in the anvil ide?

As @Matthias mentions.
The anvil run time will create datatables according to the same schema but they will be empty. You have to repopulate the data…

1 Like

Ah Ok … basically I wrote their manually … thanks i will try

1 Like

Hi @marcosandretavaresfe,
hope that worked for you. However, before you go further down this route, could you explain a bit, what you intend to achieve?
For instance, why do you intend to host the whole Anvil app server on your raspi? You can do this, of course, but why would you?
I am just asking cause you write that you are new to Anvil. And managing the whole app server on your raspi yourself is not really what I’d consider a beginner’s topic.

Im doing my final projet at University.
What Im trying to do is:

In my work (yes, Im studying and working at the same time) i have to many different PCBs that need to be tested.
What I’m trying to do is to create a box, inside it will have a RaspberryPi runnig a app (at first I think in PyQt5), and a touchscreen to control the app.
For each PCB (for start I choose 4) I create one python file to test if this PCB is good or not, and its working.

Now I want to create this app with Anvil. This app it will have to run this python files i create.
Thats what i want.

Of course, in future i will add more PCBs, so i need a database, i will need to have acess in my PC, so open the app on the network, and much more stuff that anvil has and its great. :slight_smile:

Alright, I do not really understand why you need to run Anvil locally on your raspi, but you surely have your reasons.
As far as I understand it, you could just run all the PCB testing code with a python script on the raspi, send the results via Anvil uplink to the database, use this database for your app which is running under domain ā€œwhatever-appname.anvil.appā€ and access this from anywhere you want.

A Web app will give ā€œmore pointsā€ in the final evaluation :slight_smile: its much better I have a app running in a browser, with a touchscrenn, thats it.

I will try to do that :slight_smile: and you all people will help :slight_smile: (i think)

PS: i forgot to say, that my box will need to be portable, so this is the main reason i need the Anvil app server … control it in local

1 Like

Hi @marcosandretavaresfe,
I understand, but the decision criterion for deciding whether you need to run Anvil locally is whether your box has an internet connection or not. It can be portable and still have internet connection. In that case their is no need to run it locally.
Another argument would be if you’d have huge amount of data that you would send to the DB. Then it might be as well be advisible to run locally.

I dont have internet connection … this is for a factory, and there i have intranet not internet like i have in my home … the Pi cant have acess to internet