To validate my year at school I need to make a automatic watering and write the data of all the sensors in a database with “particle photon”
And I have a problem I don’t know how how to write in a database…
Currently I have a lightsensor and a computer with WAMP Server and I can access to the database with an other computer on the same wireless connection.
I have already succeeded to show the data of the lightsensor in the particle dashboard, but how I can write this data on my own data base with wireless communication ?
Just a thought - a spreadsheet can be considered a database of sorts. With particle.publish, IFTTT, and Google drive it’s pretty trivial to log lots of data for visualization and interpretation.
Please disregard if you’re required to use a formal database.
int luminosite = A0; //Nome le pin A0 luminosite
int vLum = 0; //Initialise la valeur de vLum à 0
int Dw = A5; //Nome le pin A5 Dw
void setup() {
pinMode(Dw, OUTPUT); //Initialise le pin Dw (A5) en sortie
digitalWrite(Dw, HIGH); //Initialise le pin Dw au niveau haut
Serial.begin(9600); //Initialise la connexion série à 9600 bauds
}
void loop() {
vLum = analogRead(luminosite); //Stock dans vLum la valeur analogique lu sur le pin luminosite
Serial.println(vLum); //Ecris sur le port série la valeur de vLum
Spark.publish("Luminosité", String(vLum)); //Publie les valeurs de vLum sur la dashboard (https://dashboard.particle.io)
delay(5000); //Délai d'attente de 5 seconde entre chaque relever et 1 seconde entre chaque affichage
}
You are going to need something in between the data coming off of the Photon and the database. There are a couple options that you have here. (You can’t really just write code on the Photon that interacts directly with the database.)
Have the particle photon communicate directly with the server by sending data to the server that is then stored in the database. (In my opinion, the most modular and therefore the best option.)
For this reference the http code MORA’s post above. Also, you will need a basic understanding of POST, GET, PUT, etc. in PHP:
Here are links for that: https://www.youtube.com/watch?v=CEl3bhCBjtI
To elaborate further on this option, you need to be able to access your WAMP server from the web.
So, you need to open the ports on your firewall on port 80 if running locally, or you could also push your WAMP stuff to another service that hosts your application publicly. Once you have that set, you should be able to go to your website such as www.mysite.com (or perhaps just an ip address if there is no domain). If you do not want to do this portion, you can probably find the local ip address of the computer running the server and use that instead!
Then on the code behind mysite.com you need to code a page such as photon.php that can handle a request from the photon.
So when you POST data to photon.php at www.mysite.php/photon.php there will be php code to take the data coming off of the sensor and then store it in the database via a mysql insertion through php.
This is a lot of different abstract concepts in one place, so if you have any questions just reach out.
In this system you make a regular publish and the particle cloud makes the http call for you, you still need to write the PHP to handle it, and as @stepintostem noted the server needs to be reachable.