Commit f3d8bf268dfcd03b8027a9b8b0a2e7a124a1fd43

Authored by ftaingla
1 parent 782c28c5

fichiers finaux

arduino/progr_final.ino 0 → 100644
... ... @@ -0,0 +1,281 @@
  1 +//programme principal
  2 +
  3 +#define Lampe 3
  4 +#define venti 4
  5 +#define photocellPin 0
  6 +
  7 +#include <Wire.h>
  8 +
  9 +#define SLAVE_ADDRESS 0x12
  10 +int dataReceived = 0;
  11 +
  12 +int temp;//en dégres > Reception de la Raspberry
  13 +int lum; // en pourcent
  14 +int vent; // en pourcent
  15 +
  16 +
  17 +int temp_m;//envoie vers la raspb
  18 +int lum_m;
  19 +int hum_m;
  20 +
  21 +int photocellReading;
  22 +int envoie;
  23 +/* brochage de la carte arduino
  24 + */
  25 +const byte resitanceChauf= A0;
  26 +const byte ventilateur=A1;
  27 +
  28 +
  29 +/** Broche "DATA" du capteur */
  30 +const byte BROCHE_CAPTEUR = 5;
  31 +
  32 +/* Code d'erreur de la fonction readDHT11() et readDHT22() */
  33 +const byte DHT_SUCCESS = 0; // Pas d'erreur
  34 +const byte DHT_TIMEOUT_ERROR = 1; // Temps d'attente dépassé
  35 +const byte DHT_CHECKSUM_ERROR = 2; // Données reçues erronées
  36 +
  37 +void setup() {
  38 + // put your setup code here, to run once:
  39 + Serial.begin(9600);
  40 + Wire.begin(SLAVE_ADDRESS);
  41 + Wire.onReceive(receiveData);
  42 + Wire.onRequest(sendData);
  43 + pinMode(Lampe,OUTPUT);
  44 + pinMode (venti,OUTPUT);
  45 +
  46 + /* Place la broche du capteur en entrée avec pull-up */
  47 + pinMode(BROCHE_CAPTEUR, INPUT_PULLUP);
  48 +
  49 +}
  50 +
  51 +
  52 +
  53 +void loop() {
  54 +
  55 + float temperature, humidity;
  56 +
  57 + // création des trames pour la com rasp
  58 +
  59 + //lecture des données
  60 + temp = dataReceived/1000000;
  61 + vent = (dataReceived /1000)-temp;
  62 + lum= dataReceived -vent -temp;
  63 + cmd_vent(vent);
  64 + cmd_lampe(lum);
  65 + if ( temp_m >= temp )
  66 + {
  67 + cmd_temp(false);
  68 + }
  69 + else
  70 + {
  71 +
  72 + cmd_temp(true);
  73 + }
  74 +
  75 +
  76 +
  77 + /* Lecture de la température et de l'humidité, avec gestion des erreurs */
  78 + // N.B. Remplacer readDHT11 par readDHT22 en fonction du capteur utilisé !
  79 + switch (readDHT11(BROCHE_CAPTEUR, &temperature, &humidity)) {
  80 + case DHT_SUCCESS:
  81 +
  82 + /* Affichage de la température et du taux d'humidité */
  83 + /*Serial.print(F("Humidite (%): "));
  84 + Serial.println(humidity, 2);
  85 + Serial.print(F("Temperature (^C): "));
  86 + Serial.println(temperature, 2);*/
  87 + temp_m=temperature;
  88 + hum_m=humidity;
  89 + break;
  90 +
  91 + case DHT_TIMEOUT_ERROR:
  92 + Serial.println(F("Pas de reponse !"));
  93 + break;
  94 +
  95 + case DHT_CHECKSUM_ERROR:
  96 + Serial.println(F("Pb de communication !"));
  97 + break;
  98 + }
  99 + lum=cpt_lum();
  100 +
  101 + // envoie des données ic2
  102 + envoie = temp_m * 1000000 + hum_m *1000 +lum_m;
  103 + /* Pas plus d'une mesure par seconde */
  104 +}
  105 +int cpt_lum()
  106 +{
  107 + photocellReading = analogRead(photocellPin);
  108 +
  109 + //faire la conversion valeur vers lux
  110 +
  111 + return photocellReading;
  112 +
  113 +}
  114 +void cmd_lampe(float lum)
  115 +{
  116 +
  117 + // conversion vent a faire une fois le dome concu
  118 + lum = (lum/100)*255 ;// commande en pourcentage pour l'instant
  119 + analogWrite(Lampe,lum);
  120 +
  121 +}
  122 +void cmd_vent(float vent)
  123 +{
  124 +
  125 + // conversion vent a faire une fois le dome concu
  126 + vent = (vent/100)*255 ;// commande en pourcentage pour l'instant
  127 + analogWrite(ventilateur,vent);
  128 +
  129 +}
  130 +void cmd_temp(bool actif)
  131 +{
  132 + if ( actif)
  133 + {
  134 + analogWrite(resitanceChauf,200);
  135 + }
  136 + else
  137 + {
  138 + analogWrite(resitanceChauf,0);
  139 + }
  140 + }
  141 +// communication i2c entre raspeberrry et arduino
  142 +void receiveData(int byteCount){
  143 + while(Wire.available()) {
  144 + dataReceived = Wire.read();
  145 + }
  146 +}
  147 +
  148 +void sendData(){
  149 + Wire.write(envoie);
  150 +}
  151 +
  152 + /*
  153 + * Lit la température et le taux d'humidité mesuré par un capteur DHT11.
  154 + *
  155 + * @param pin Broche sur laquelle est câblée le capteur.
  156 + * @param temperature Pointeur vers la variable stockant la température.
  157 + * @param humidity Pointeur vers la variable stockant le taux d'humidité.
  158 + * @return DHT_SUCCESS si aucune erreur, DHT_TIMEOUT_ERROR en cas de timeout, ou DHT_CHECKSUM_ERROR en cas d'erreur de checksum.
  159 + */
  160 +byte readDHT11(byte pin, float* temperature, float* humidity)
  161 +{
  162 +
  163 + /* Lit le capteur */
  164 + byte data[5];
  165 + byte ret = readDHTxx(pin, data, 18, 1000);
  166 +
  167 + /* Détecte et retourne les erreurs de communication */
  168 + if (ret != DHT_SUCCESS)
  169 + return ret;
  170 +
  171 + /* Calcul la vraie valeur de la température et de l'humidité */
  172 + *humidity = data[0];
  173 + *temperature = data[2];
  174 +
  175 + /* Ok */
  176 + return DHT_SUCCESS;
  177 +}
  178 +
  179 +/**
  180 + * Fonction bas niveau permettant de lire la température et le taux d'humidité (en valeurs brutes) mesuré par un capteur DHTxx.
  181 + */
  182 +byte readDHTxx(byte pin, byte* data, unsigned long start_time, unsigned long timeout)
  183 +{
  184 + data[0] = data[1] = data[2] = data[3] = data[4] = 0;
  185 + // start_time est en millisecondes
  186 + // timeout est en microsecondes
  187 +
  188 + /* Conversion du numéro de broche Arduino en ports / masque binaire "bas niveau" */
  189 + uint8_t bit = digitalPinToBitMask(pin);
  190 + uint8_t port = digitalPinToPort(pin);
  191 + volatile uint8_t *ddr = portModeRegister(port); // Registre MODE (INPUT / OUTPUT)
  192 + volatile uint8_t *out = portOutputRegister(port); // Registre OUT (écriture)
  193 + volatile uint8_t *in = portInputRegister(port); // Registre IN (lecture)
  194 +
  195 + /* Conversion du temps de timeout en nombre de cycles processeur */
  196 + unsigned long max_cycles = microsecondsToClockCycles(timeout);
  197 +
  198 + /* Evite les problèmes de pull-up */
  199 + *out |= bit; // PULLUP
  200 + *ddr &= ~bit; // INPUT
  201 + delay(100); // Laisse le temps à la résistance de pullup de mettre la ligne de données à HIGH
  202 +
  203 + /* Réveil du capteur */
  204 + *ddr |= bit; // OUTPUT
  205 + *out &= ~bit; // LOW
  206 + delay(start_time); // Temps d'attente à LOW causant le réveil du capteur
  207 + // N.B. Il est impossible d'utilise delayMicroseconds() ici car un délai
  208 + // de plus de 16 millisecondes ne donne pas un timing assez précis.
  209 +
  210 + /* Portion de code critique - pas d'interruptions possibles */
  211 + noInterrupts();
  212 +
  213 + /* Passage en écoute */
  214 + *out |= bit; // PULLUP
  215 + delayMicroseconds(40);
  216 + *ddr &= ~bit; // INPUT
  217 +
  218 + /* Attente de la réponse du capteur */
  219 + timeout = 0;
  220 + while(!(*in & bit)) { /* Attente d'un état LOW */
  221 + if (++timeout == max_cycles) {
  222 + interrupts();
  223 + return DHT_TIMEOUT_ERROR;
  224 + }
  225 + }
  226 +
  227 + timeout = 0;
  228 + while(*in & bit) { /* Attente d'un état HIGH */
  229 + if (++timeout == max_cycles) {
  230 + interrupts();
  231 + return DHT_TIMEOUT_ERROR;
  232 + }
  233 + }
  234 +
  235 + /* Lecture des données du capteur (40 bits) */
  236 + for (byte i = 0; i < 40; ++i) {
  237 +
  238 + /* Attente d'un état LOW */
  239 + unsigned long cycles_low = 0;
  240 + while(!(*in & bit)) {
  241 + if (++cycles_low == max_cycles) {
  242 + interrupts();
  243 + return DHT_TIMEOUT_ERROR;
  244 + }
  245 + }
  246 +
  247 + /* Attente d'un état HIGH */
  248 + unsigned long cycles_high = 0;
  249 + while(*in & bit) {
  250 + if (++cycles_high == max_cycles) {
  251 + interrupts();
  252 + return DHT_TIMEOUT_ERROR;
  253 + }
  254 + }
  255 +
  256 + /* Si le temps haut est supérieur au temps bas c'est un "1", sinon c'est un "0" */
  257 + data[i / 8] <<= 1;
  258 + if (cycles_high > cycles_low) {
  259 + data[i / 8] |= 1;
  260 + }
  261 + }
  262 +
  263 + /* Fin de la portion de code critique */
  264 + interrupts();
  265 +
  266 + /*
  267 + * Format des données :
  268 + * [1, 0] = humidité en %
  269 + * [3, 2] = température en degrés Celsius
  270 + * [4] = checksum (humidité + température)
  271 + */
  272 +
  273 + /* Vérifie la checksum */
  274 + byte checksum = (data[0] + data [1] + data[2] + data[3]) & 0xff;
  275 + if (data[4] != checksum)
  276 + return DHT_CHECKSUM_ERROR; /* Erreur de checksum */
  277 + else
  278 + return DHT_SUCCESS; /* Pas d'erreur */
  279 +
  280 +}
  281 +
... ...
fpga/Capture.PNG 0 → 100644

73.1 KB

fpga/Sheet1.SchDoc 0 → 100644
No preview for this file type
site web/page.html 0 → 100644
... ... @@ -0,0 +1,109 @@
  1 +<!DOCTYPE html>
  2 +<html>
  3 +<H1> BANC TEST DE STATION METEOROLOGIQUE</H1>
  4 +
  5 +<H2> Commande des paramètres </H2>
  6 +
  7 +
  8 +<p> Vent </p>
  9 + <FORM>
  10 + <SELECT name="nom" size="1">
  11 + <OPTION>null
  12 + <OPTION>faible
  13 + <OPTION>moyen
  14 + <OPTION>fort
  15 + </SELECT>
  16 + </FORM>
  17 +</html>
  18 +<script language="javascript" src="p1.js"> </script>
  19 +<p> Lumière </p>
  20 + <FORM>
  21 + <SELECT name="nom" size="1">
  22 + <OPTION>Noir
  23 + <OPTION>Sombre
  24 + <OPTION>Lumineux
  25 + <OPTION>Très lumineux
  26 + </SELECT>
  27 + </FORM>
  28 +</html>
  29 +
  30 +<form method="post" action="traitement.php">
  31 + <p>
  32 + <label for="temp_donnée">Température: </label>
  33 + <input type="text" name="temp_donnée" id="temp_donnée" placeholder="Ex : 20" size="10" maxlength="4" />
  34 + </p>
  35 +</form>
  36 +
  37 +
  38 +<form method="post" action="traitement.php">
  39 + <p>
  40 + <label for="humidité_donnée">Humidité: </label>
  41 + <input type="text" name="humidité_donnée" id="humidité_donnée" placeholder="Ex : 15" size="10" maxlength="4" />
  42 + </p>
  43 +</form>
  44 +</html>
  45 +
  46 +
  47 +<H2> Données lues sur la Station testée </H2>
  48 +
  49 +</html>
  50 +
  51 +<form method="post" action="traitement.php">
  52 + <p>
  53 + <label for="modèle station météo">Référence: </label>
  54 + <input type="text" name="code" id="code" size="10" maxlength="4" />
  55 + </p>
  56 +</form>
  57 +
  58 +<script language="javascript" src="p1.js"> </script>
  59 +<p> Lumiére </p>
  60 + <FORM>
  61 + <SELECT name="nom" size="1">
  62 + <OPTION>Fonctionne
  63 + <OPTION>Ne fonctionne pas
  64 + </SELECT>
  65 + </FORM>
  66 +</html>
  67 +
  68 +
  69 +<script language="javascript" src="p1.js"> </script>
  70 +<p> Vent </p>
  71 + <FORM>
  72 + <SELECT name="nom" size="1">
  73 + <OPTION>Fonctionne
  74 + <OPTION>Ne fonctionne pas
  75 + </SELECT>
  76 + </FORM>
  77 +</html>
  78 +
  79 +
  80 +
  81 +</html>
  82 +
  83 +<script language="javascript" src="p1.js"> </script>
  84 +<p> Humidité </p>
  85 + <FORM>
  86 + <SELECT name="nom" size="1">
  87 + <OPTION>Fonctionne
  88 + <OPTION>Ne fonctionne pas
  89 + </SELECT>
  90 + </FORM>
  91 +</html>
  92 +
  93 +
  94 +
  95 +<script language="javascript" src="p1.js"> </script>
  96 +<p> Température </p>
  97 + <FORM>
  98 + <SELECT name="nom" size="1">
  99 + <OPTION>Fonctionne
  100 + <OPTION>Ne fonctionne pas
  101 + </SELECT>
  102 + </FORM>
  103 +
  104 + <input type="button" value="Validez" onclick="alert("Validez")">
  105 +</html>
  106 +
  107 +</html>
  108 +
  109 +
... ...
websocket/websocket.c 0 → 100644
... ... @@ -0,0 +1,123 @@
  1 +#include <stdio.h>
  2 +#include <stdlib.h>
  3 +#include <string.h>
  4 +#include <unistd.h>
  5 +#include <termios.h>
  6 +
  7 +#include "serial.h"
  8 +
  9 +
  10 +#define SERIAL_DEVICE "/dev/ttyACM0"
  11 +#include <libwebsockets.h>
  12 +
  13 +#define MAX_FRAME_SIZE 1024
  14 +#define WAIT_DELAY 50
  15 +
  16 +int sd;
  17 +
  18 +//balek de ça
  19 +static int callback_http(struct libwebsocket_context *this,struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason,void *user,void *in,size_t len)
  20 +{
  21 + return 0;
  22 +}
  23 +
  24 +//le plus important est ici
  25 +static int callback_my(struct libwebsocket_context * this,struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason,void *user,void *in,size_t len)
  26 +{
  27 +
  28 + static char *message=NULL;
  29 + static int msize=0;
  30 +
  31 +
  32 +
  33 + switch(reason)
  34 + {
  35 + case LWS_CALLBACK_ESTABLISHED: /
  36 + printf("connection established\n");
  37 + message=NULL;
  38 +
  39 + libwebsocket_callback_on_writable(this,wsi);
  40 + break;
  41 + case LWS_CALLBACK_RECEIVE:
  42 +
  43 + printf("received data: %s\n",(char *)in);
  44 +
  45 + message=malloc(len+LWS_SEND_BUFFER_PRE_PADDING+LWS_SEND_BUFFER_POST_PADDING);
  46 +
  47 + if(message==NULL)
  48 + {
  49 + perror("callback_my.malloc"); exit(EXIT_FAILURE);
  50 + }
  51 + e + le début du buffer d'envoi "LWS_SEND_BUFFER_PRE_PADDING"
  52 + memcpy(message+LWS_SEND_BUFFER_PRE_PADDING,in,len);
  53 +
  54 + msize=len;
  55 + // on envoie a l'arduiono la valeur envoyé par le site web
  56 + write(sd,message,(len+LWS_SEND_BUFFER_PRE_PADDING+LWS_SEND_BUFFER_POST_PADDING));
  57 + libwebsocket_callback_on_writable(this,wsi);
  58 + break;
  59 + case LWS_CALLBACK_SERVER_WRITEABLE:
  60 +
  61 + if(message!=NULL)
  62 + {
  63 +
  64 + read(sd,message,len+LWS_SEND_BUFFER_PRE_PADDING+LWS_SEND_BUFFER_POST_PADDING);
  65 +
  66 + char *out=message+LWS_SEND_BUFFER_PRE_PADDING;
  67 +
  68 +
  69 + libwebsocket_write(wsi,(unsigned char *)out,msize,LWS_WRITE_TEXT);
  70 +
  71 + free(message);
  72 + message=NULL;
  73 + }
  74 + break;
  75 + default:
  76 + break;
  77 + }
  78 + return 0;
  79 +}
  80 +
  81 +static struct libwebsocket_protocols protocols[] = {
  82 + {
  83 + "http-only", // name
  84 + callback_http, // callback
  85 + 0, // data size
  86 + 0 // maximum frame size
  87 + },
  88 + {"myprotocol",callback_my,0,MAX_FRAME_SIZE},
  89 + {NULL,NULL,0,0}
  90 + };
  91 +
  92 +
  93 +
  94 +int main(void)
  95 +{
  96 + int port=9000;
  97 + struct lws_context_creation_info info;
  98 + memset(&info,0,sizeof info);
  99 + info.port=port;
  100 + info.protocols=protocols;
  101 + info.gid=-1;
  102 + info.uid=-1;
  103 + struct libwebsocket_context *context=libwebsocket_create_context(&info);
  104 +
  105 + // communication port série arduino
  106 + int c=0;
  107 + sd=serialOpen(SERIAL_DEVICE,SERIAL_BOTH);
  108 + serialConfig(sd,B9600);
  109 +
  110 + if(context==NULL)
  111 + {
  112 + fprintf(stderr, "libwebsocket init failed\n");
  113 + return -1;
  114 + }
  115 + printf("starting server...\n");
  116 +
  117 + while(1)
  118 + {
  119 + libwebsocket_service(context,WAIT_DELAY);
  120 + }
  121 + libwebsocket_context_destroy(context);
  122 + return 0;
  123 +}
... ...