banierre PV

 

Cet accéléromètre arduino est construit autour d'un MPU5060 et d'un Wemos D1 mini pro. J'ai utilisé l'IDE d'arduino pour faire sa programmation. Il est doté d'une batterie de 1000mAH, cela lui permet une autonomie de 10 jours en veille et de 10 heures en cycle. Il se recharge par un chargeur sans contact.

Il est programmé pour enregistrer un cycle (un tour d'un train de coaster par exemple) puis il se connecte à un logiciel développé en PHP pour synchroniser les données récoltées.  Celle-ci peuvent être traitées pour activer des alarmes ou faire du reporting via  l'interface web du serveur de données. 

Il est doté d'une interface web intégrée. Celle ci permet d'effectuer diverses opérations: calibrage, taux d’échantillonnage,  filtre passe bas, durée maximum d'un cycle, connexion wifi,...

Cet appareil est très abouti, il est prêt à être exploité, d’ailleurs je vends sa réalisation et sa mise en place. Pour les makers , vous trouverez dans la suite de cet article toutes les informations nécessaires à sa réalisation.

Ici une démo faite avec le prototype, le programme a évolué depuis : //www.youtube.com/watch?v=4cgt9LUoMbU.

Merci à vous de me faire un retour sur l'utilisation et les améliorations que vous aurez apportées.

 

Sommaire

 

1-Utilisation et configuration

2-Les caractéristiques techniques

3-Le matériel utilisé

4-Le schéma électrique et son PCB

5-Les fichiers 3D pour le boîtage.

6-Les codes de programmations


 

1-Utilisation et configuration:

Après une configuration simple de ses paramètres wifi sur l'interface du module, il suffit d'informer le formulaire d'ajout pour l'intégrer dans le logiciel de supervision

Portail de configuration du wifi      Page d'ajout d'un objet connecté Innogreentech

Une fois l'enregistrement de l'appareil l'interface permet de le configurer, de le calibrer ou de le mettre à jour.

Configuration objets connectés innogreentech

 Pour obtenir un rapport il suffit d'aller sur l'interface pour éditer un rapport en PDF

Rapport journalier accéléromètre

Rapport pdf de l'accélèrométre

 2-Les caractéristiques techniques :

 

 

3-Le matériel utilisé :

          -Un accélérométre MPU5060 :accéléromètre MPU6050

       -Un shield de gestion de batterie :chargeur batterie

       -Une batterie de 1000 AH 34x52x5,5 :batterie

 

 

 4-Schémas et PCB :

        Le schéma et le PCB sont réalisés avec Kicad, http://www.kicad-pcb.org :

                                 - Pour télécharger le projet c'est ici: Projet Kicad de l'accéléromètreSchéma accéléromètrePCB accéléromètre

 

5-Le boîtage en impression 3D :

 accéléromètre innogreentech

accéléromètre innogreentech

support accéléromètre innogreentech

 

6-Les codes de programmation  :

    /***********************************************************************
    
    <Accelerometer connected. This a accelerometer for ride machines it work itself to record data in a data base>
    Copyright (C) <2019>  <Fabrice BAUDIN>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.

    Cette adresse e-mail est protégée contre les robots spammeurs. Vous devez activer le JavaScript pour la visualiser.

****************************************************************************************/

/* library system*/

#include <Wire.h>
#include <FS.h>
#include <EEPROM.h>
#include <ESP8266WiFi.h> 
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>


/* to enable sleep mode */

extern "C" {
            #include "user_interface.h"
           }

/* define registrer of MPU 6050 */

#define MPU6050_RA_XG_OFFS_TC       0x00 //[7] PWR_MODE, [6:1] XG_OFFS_TC, [0] OTP_BNK_VLD
#define MPU6050_RA_YG_OFFS_TC       0x01 //[7] PWR_MODE, [6:1] YG_OFFS_TC, [0] OTP_BNK_VLD
#define MPU6050_RA_Y_FINE_GAIN      0x04 //[7:0] Y_FINE_GAIN
#define MPU6050_RA_ZG_OFFS_TC       0x02 //[7] PWR_MODE, [6:1] ZG_OFFS_TC, [0] OTP_BNK_VLD
#define MPU6050_RA_X_FINE_GAIN      0x03 //[7:0] X_FINE_GAIN
#define MPU6050_RA_Z_FINE_GAIN      0x05 //[7:0] Z_FINE_GAIN

#define MPU6050_ADDR                0x68   //68 Adress of the MPU
#define MPU6050_SMPLRT_DIV          0x19   // Sample divider 1 Khz/1+this number here to have 20 Hhz
#define MPU6050_CONFIG              0x1a   // Config filter pass down
#define MPU6050_GYRO_CONFIG         0x1b   // Configure gyroscope
#define MPU6050_ACCEL_CONFIG        0x1c   // Configure accelerometer
#define MPU6050_WHO_AM_I            0x75   // Information on the device
#define MPU6050_PWR_MGMT_1          0x6b   // Sleep or wake up management
#define MPU6050_PWR_MGMT_2          0x6c   // Sleep or wake up management
#define MPU6050_TEMP_H              0x41   // Registrers of temperature
#define MPU6050_TEMP_L              0x42
#define MPU6050_FIFO_EN             0x23    // Enable Fifo registrer
#define MPU6050_INT_PIN_CFG         0x37    // Configure  the interrupt pin
#define MPU6050_INT_ENABLE          0x38    // Enable interrupt
#define MPU6050_INT_STATUS          0x3A    // Staut flags occure by interrupt
#define MPU6050_USER_CTRL           0x6A    // User control enable fifo...
#define MPU6050_FIFO_COUNT_H        0x72    // count the bytes in the FIFO registrers
#define MPU6050_FIFO_COUNT_L        0x73   
#define MPU6050_FIFO_R_W            0x74    // Read or Write in the FIFO registrers
#define MPU6050_MOT_DETECT_CTRL     0x69    // Delay detection motion
#define MPU6050_RA_FF_THR           0x1D    // fall_Thresold
#define MPU6050_RA_FF_DUR           0x1E    // Fall_DURATION
#define MPU6050_RA_MOT_THR          0x1F    // Motion Thresold
#define MPU6050_RA_MOT_DUR          0x20    // Motion Duration
#define MPU6050_RA_ZRMOT_THR        0x21    // Zero Thesold
#define MPU6050_RA_ZRMOT_DUR        0x22    // Zero Duration
#define MPU6050_RA_INT_STATUS       0x3A    // Read to clear interrupt
#define MPU6050_SIGNAL_PATH_RESET   0x68    // Reset Path 



#define MPU6050_ACONFIG_ACCEL_HPF_BIT       2
#define MPU6050_ACONFIG_ACCEL_HPF_LENGTH    3

/* Memory page*/

#define OFFSET_X_MEM       0        //value adjustement of X
#define GAIN_X_MEM         4
#define OFFSET_Y_MEM       8        //Value adjust of Y
#define GAIN_Y_MEM         12
#define OFFSET_Z_MEM       16       // Value adjust of Z
#define GAIN_Z_MEM         20
#define OFFSET_T_MEM       24       // Value adjust of température
#define POSITION_MEM       28       // Vertical or horizontal position
#define MEM_SSID           32       // SSID of connection 30 max
#define MEM_PASSWORD       65       // pass word access
#define ADRESS_SERVER      200      //
#define PORT_SERVER        116   
#define NAME_MODULE        120
#define MEM_TIME_SLEEP     150      //time out time sleep after wake up *///
#define MEM_CALIBRATION    155      // Date of the last calibration
#define SAMPLE_MEM         170       //period to get samples
#define DURATION_RIDE_MEM  172      // Duration maximum for a ride (in seconds)
#define LOW_PASS_MEM       174      // Filter low pass 

/* wifi variables */

ESP8266WebServer httpServer(80);

char ip_httpServer[15];                 // adress ip of the module
int unsigned   port_httpServer=80;      // port of httpServer
String ssid="";                     // ssid 
String password="";                 // Password

String local_mac;                   // adress mac of the module
String local_ip;                    // adress ip of module

int    power_mode=0;                // 0: mode normale; 1: mode portail wifi; 2: mise en route paramettrage possible, 4: sleep mode demand
unsigned long delay_reboot=0;       // delay during the page of connection is open before reboot
#define DELAY_REBOOT 300000         // time during the portail is open befor reset,cpu don't go in sleep mode during this time

String ref_module="coaster_accelerometer";         // référence du module
String version_module="V1";                        // version of module
char name_module[20];                              // name of module

/* config update server */

//const char* host = "esp8266-webupdate";
const char* update_path = "/firmware";
const char* update_username = "admin";
const char* update_password = "admin";

ESP8266HTTPUpdateServer httpUpdater;

/* Use to control software */

long timer = 0;                     // Timer
byte flag = 0;                      // flag statut  
int i=0;                            // index
byte file_number=1;                 // Number of file open


#define        TIME_SLEEP_MODE  30000      // Define the time before to go to sleep
unsigned long  time_wake_up;              // mesure time before to go in sleep mode

/*use to mesure the time between two samples */

unsigned long periode=0;
unsigned long lasttime=0;

/* accelerometer variable */

int16_t rawAccX, rawAccY, rawAccZ, rawTemp; // value read befor conversion

float temp, accX, accY, accZ;              // currently value

float max_x, max_y, max_z;                 // maximum found for a ride
float min_x, min_y, min_z;                 // minimum found for a ride

byte sample;                               // period of simple 4 or 8 ms (125 Hz or 250 Hz)
byte hex_sample;                           // convert sample for MPU5060
byte low_pass;                             // filter 5 or 10 Hz
byte hex_low_pass;                         // convert filter for MPU5060
unsigned int duration_ride;                // max time in seconds for one ride maximum 300 secondes
int data;                                  //read data from accelerometer


unsigned long  time_ride;                  // time of the last ride in milliseconds
unsigned long  max_sample_ride;            // Number of samples that it can be recorders

int false_sample=0;


/* variable for calibration  adjuste= aX + b */

int activation=0;                          // equal 1 when the calibration in underway
int step_calibration=0;                    // Step of calibration 8 steps
int step_format=0;                         // Step use to format memory and return informations on the web page
float first_dot;                           // First dot mesure for the calibration
float second_dot;                          // Second dot use to make calibration
byte error_position;                       // Bad position of the accelerometer for the calibration
byte verticale_position=0;                 // Use position
float gain_x;                              // Gain correction   
float offset_x;                            // Offset correction
float gain_y;                              // Gain correction
float offset_y;                            // Offset correction
float gain_z;                              // Gain correction
float offset_z;                            // Offser correction

String date_calibration;                   // Date of the last calibration

float offset_temp;                         // Value of adjustement 

int  number_samples=0;                     // numbers of sample

/* Value to adjust start or stop ride */

#define START_DELAY   500                 // Delay in ms before to validate start signal
#define STOP_DELAY    3000               // Delay in ms to validate the stop of the ride
#define END_RIDE_TIME      0              // Delay avaible to stop the ride in ms

 unsigned long start_delay;               // Mesure the delay to wait start
 unsigned long stop_delay;                // Mesure the delay to wait stop
 unsigned long end_ride_sample;              
 int run_ride=0;                          // 0: ride stop, 1: tempory signal to run ride, 2: the ride run, 3: Tempory signal for stop

/* Spiff file datas */

File f;

/**************************************************************
*                       Set up system                         *
***************************************************************/

void setup() {

              system_update_cpu_freq(160);
              WiFi.setPhyMode(WIFI_PHY_MODE_11G);


              pinMode(D5, OUTPUT);
              digitalWrite(D5,LOW);
              delay(100);
              //system_phy_set_powerup_option(0);
     

              /* Start Wire communication */
              Wire.begin(D1,D2);
              Wire.flush();                       // empty serial buffer

           
  
              Serial.begin(115200);  // set serial port  
              Serial.flush();
              Serial.println("");
              Serial.println F ("Start setup");
            
   
              Serial.println F ("Start I2C Communication ");
              

              
                        
              
              

              /*EEPPROM setup */

              EEPROM.begin(512);                              // allocations  de 512 adresses Mémoires
              Serial.println F ("Read EEPROM");


              byte mem[4];                                    // Array to read men
              long rsave;                                     // long to read save
              byte test_mem[2];                               // to read men


              /* Samples and low filter configuration */

              sample= EEPROM.read (SAMPLE_MEM);    // Read  period of sample
              if(sample==4){hex_sample=0x03;}      // 250 Hz
              else{hex_sample=0x07;}               // 125 Hz
              end_ride_sample=END_RIDE_TIME/sample;
              Serial.print F ("the period sample is: "); Serial.print(sample); Serial.println F (" ms");

              low_pass= EEPROM.read (LOW_PASS_MEM);  // Read value of filter
              if(low_pass==10){hex_low_pass=0x05;}   // 10 Hz
              else{hex_low_pass=0x06;}               // 5 Hz
              Serial.print F ("the low filter is : "); Serial.print(low_pass); Serial.println F (" Hz");

              /* Duration of one ride */

              for (int a=0;a<3;a++){test_mem[a]= EEPROM.read(DURATION_RIDE_MEM+a);}     // Read the time max of a ride        
              duration_ride= test_mem[0]|test_mem[1]<<8;                                // in seconds
              max_sample_ride=(duration_ride*1000)/sample;                              // Convert in number of samples
              Serial.print F ("The max time ride is : "); Serial.print(duration_ride); Serial.println F (" s");

              /* offset and gain to adjust mesurement */

              for (int a=0;a<4;a++){mem[a]= EEPROM.read (OFFSET_X_MEM+a);}
              rsave=(long)mem[0]|(long)mem[1]<<8|(long)mem[2]<<16|(long)mem[3]<<24;
              offset_x= float(rsave)/1000;
              if (fabs(offset_x)>0.5){offset_x=0;}
              Serial.print F ("The x off_set adjust is : "); Serial.println(offset_x);

              for (int a=0;a<4;a++){mem[a]= EEPROM.read (GAIN_X_MEM+a);}
              rsave=(long)mem[0]|(long)mem[1]<<8|(long)mem[2]<<16|(long)mem[3]<<24;
              gain_x= float(rsave)/1000;
              if (fabs(gain_x)>1.2||fabs(gain_z)<0.8){gain_x=1;}
              Serial.print F ("The x gain adjust is : "); Serial.println(gain_x);


              for (int a=0;a<4;a++){mem[a]= EEPROM.read (OFFSET_Y_MEM+a);}
              rsave=(long)mem[0]|(long)mem[1]<<8|(long)mem[2]<<16|(long)mem[3]<<24;
              offset_y= float(rsave)/1000;
              if (abs(offset_y)>0.5){offset_y=0;}
              Serial.print F ("The y off_set adjust is : "); Serial.println(offset_y);

              for (int a=0;a<4;a++){mem[a]= EEPROM.read (GAIN_Y_MEM+a);}
              rsave=(long)mem[0]|(long)mem[1]<<8|(long)mem[2]<<16|(long)mem[3]<<24;
              gain_y= float(rsave)/1000;
              if (abs(gain_y)>1.2||fabs(gain_y)<0.8){gain_y=1;}
              Serial.print F ("The y gain adjust is : "); Serial.println(gain_y);

              for (int a=0;a<4;a++){mem[a]= EEPROM.read (OFFSET_Z_MEM+a);}
              rsave=(long)mem[0]|(long)mem[1]<<8|(long)mem[2]<<16|(long)mem[3]<<24;
              offset_z= float(rsave)/1000;
              if (fabs(offset_z)>0.5){offset_z=0;}
              Serial.print F ("The z off_set adjust is : "); Serial.println(offset_z);   

              for (int a=0;a<4;a++){mem[a]= EEPROM.read (GAIN_Z_MEM+a);}
              rsave=(long)mem[0]|(long)mem[1]<<8|(long)mem[2]<<16|(long)mem[3]<<24;
              gain_z= float(rsave)/1000;
              if (fabs(gain_z)>1.2||fabs(gain_z)<0.8){gain_z=1;}  
              Serial.print F ("The z gain adjust is : "); Serial.println(gain_z);
              
              /* Date of the last calibration */
              
              char carac='1';                 
              int a=0;
              while (!(carac=='\0')&&a<100){carac=char (EEPROM.read(MEM_CALIBRATION+a));if (!(carac=='\0')){date_calibration +=carac;} a++;}  
              if (date_calibration=='\0'||a>50){date_calibration=F("1901-00-00");}

              Serial.print F ("Date of the last calibration: ");Serial.println(date_calibration);

              /* Position of work Vertical or Horizontal */

              verticale_position= EEPROM.read (POSITION_MEM);    // Position of work
              if(verticale_position>1){verticale_position=0;}
              Serial.print F ("Work position: ");Serial.println(verticale_position);

              /* offset of temperature */
              
              for (int a=0;a<4;a++){mem[a]= EEPROM.read (OFFSET_T_MEM+a);}  // oofset temp
              rsave=(long)mem[0]|(long)mem[1]<<8|(long)mem[2]<<16|(long)mem[3]<<24;
              offset_temp= float(rsave)/100;
              if (fabs(offset_temp)>10){offset_temp=0;}  
              Serial.print F ("Offset temperatur: ");Serial.println(offset_temp);

  
              /* Read ip adress httpServer */
              
              String reception="";
              reception.reserve(30);
              carac='1';
              a=0;
              while (!(carac=='\0')&&a<20){carac=char (EEPROM.read(ADRESS_SERVER+a));reception+= carac; a++;}
              if (reception=='\0'||a==20){reception=F("InnoGreenTech");} 
              int c = reception.length() + 1;                
              reception.toCharArray(ip_httpServer, c);
              Serial.print F ("The IP Server is : ");Serial.println(ip_httpServer);

              /* Name of the module */
              reception="";             
              carac='1';  
              a=0;
              while (!(carac=='\0')&&a<20){carac=char (EEPROM.read(NAME_MODULE+a));reception+= carac; a++;} 
              if (reception=='\0'||a==20){reception=F("InnoGreenTech");}
              c = reception.length() + 1;                               // longueur de la chaîne de caractéres
              reception.toCharArray(name_module, c);
              Serial.print F ("Name modul is : ");Serial.println(name_module);

              /* SSID connection */
                         
              carac='1';                
              a=0;
              while (!(carac=='\0')&&a<100){carac=char (EEPROM.read(MEM_SSID+a));if (!(carac=='\0')){ssid +=carac;} a++;}  //récupération du lien d'information
              if (ssid=='\0'||a>50){ssid=F("");}
              Serial.print F ("SSID : ");Serial.println(ssid);
      
              /* Password */
                         
              carac='1';
              a=0;
              while (!(carac=='\0')&&a<100){carac=char (EEPROM.read(MEM_PASSWORD+a));if (!(carac=='\0')){password +=carac;} a++;}  //récupération du lien d'information
              if (password=='\0'||a>50){password=F("");}
              Serial.print F ("Password : ");Serial.println("****");

              /* Port httpServer */

              for (int a=0;a<3;a++){test_mem[a]= EEPROM.read(PORT_SERVER+a);}     // load the port httpServer         
              port_httpServer= test_mem[0]|test_mem[1]<<8;
              Serial.print F ("Server port is : ");Serial.println(port_httpServer);
            
              /*wifi configuration */
              



               WiFi.mode(WIFI_STA);                               // switch on Wifi
               
               c =ssid.length()+1;                                // convert ssid in chart variable
               char char_ssid[30];
               ssid.toCharArray(char_ssid, c);
            
               c =password.length()+1;                            // convert password in chart              
               char char_password[30];
               password.toCharArray(char_password, c);
            
               WiFi.begin(char_ssid,char_password);              //Connect to wifi router  
    
               local_mac=WiFi.macAddress();                      // Convert mac adress               
               delay(10000);                                     // Delay for waiting connection
              
              /* sleelp mode of wemos */

              wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);           // set the sleep mode of 8266
              
              /* Portal for configur WIFI connection
              If wifi is not connected, open the webpage to change configuration */
              
              if ( WiFi.status()!= WL_CONNECTED)                     
        
              {         
                WiFi.disconnect();
                WiFi.mode(WIFI_AP); 
                power_mode=1;
                Serial.println(F("Page of configuration portal open"));
                delay(200);
                WiFi.softAP("InnoGreenTech", "innogreentech");
                httpServer.on ( "/index.html", handleRoot );    // go to set up wifi page
                delay(100);
               
              }

              /* Open wifi httpServer for configure probe */
              
              else{
                 //MDNS.begin(host);
                 httpUpdater.setup(&httpServer, update_path, update_username, update_password);
                 power_mode=2;                
                 local_ip=WiFi.localIP().toString().c_str(); 
                 Serial.println("");
                 Serial.print F("IP address: "); Serial.println (local_ip);
                 Serial.println(F("Server to configur wamp or calibration page are open"));
 
                 httpServer.on ( "/add_module.csv", add_module );         //Page to add or modify  module by php httpServer 
                 httpServer.on ( "/calibration.html", calibration );      //Page to calibratre accelerometer
                 httpServer.on ( "/format.html",format);                  //Page to format spiffs memory
                 delay(100);
                  }
              /* Start File management sytem detect if file exist else format spiffs memory*/
              SPIFFS.begin();  
              Serial.print F("Mac adress: ");Serial.println(local_mac);                        
              Serial.println F ("Start Spiffs memory");
              f=SPIFFS.open("/datas.txt", "w"); 
              f.close();              

              

              Serial.println F ("Version 22/02/2019");   

              /*Prepare accelerometer*/                       
         
              pinMode(D6, INPUT_PULLUP);                        // Configur interrupt input
              pinMode(D7, INPUT_PULLUP);                        // Configur interrupt input

              

              beginMPU6050();                                   // Sart configuration of accelerometer

               Serial.println F ("Accelerometer is ready"); 
                            /* set initial datas */
              
              delay_reboot=millis();        //init delay         
              httpServer.begin();           //start httpServer web
              time_wake_up=millis();        //init delay
              flag=4;                       // avaible get samples 
               

              writeMPU6050(MPU6050_INT_ENABLE, 0x40);       //Set interrupt on motion détection*/
              
              delay(500);             
}


/*************************************************************
 *                    Main program                           *
 *************************************************************/

void loop() {
  
  /* read Value of battery if it is to low enter in sleep mode
  float raw = analogRead(A0);                      
  float volt = map(raw, 274, 949, 0, 420);             // Avec une résistance 1M5 - With a 1M5 resistor
  volt = volt / 100;
  if (volt<3.4)
  { 
    writeMPU6050(MPU6050_INT_ENABLE, 0x00);                         //disable interupt on the MPU 6050
    readMPU6050(MPU6050_INT_STATUS);                                //Clear interupt on MPU6050 
    power_mode=4;
    }
  //Serial.print("A0 "); Serial.println(raw);
  //Serial.print("Voltage "); Serial.println(volt);



  /* active accelerometer if at the beginning there is a motion detection else stay in server mode */ 

  if(flag==4){                                                         //reset false interrupt
              while (digitalRead(D6)==0){
                      //Serial.println(F("interrupt is hight"));
                      readbyteMPU6050(MPU6050_INT_STATUS);            // Reset interrupt on mpu5060
                      delay(20);} 
              flag=6;   
              }

  if(flag==6&&digitalRead(D6)==0)                                     // Control motion and  close page if it hapen
            {
              Serial.println(F("Movement detect"));
              httpServer.stop();
              delay(1000);  
              WiFi.setPhyMode(WIFI_PHY_MODE_11N);            
              wifi_station_disconnect();                              //disable wifi modem for safe power
              wifi_set_opmode(NULL_MODE);                
              power_mode=0;                                           //entry in mode mesurement
              flag=3;
            }
            
/*After wake up open file to recorder enter to mesurement mode*/

   if(power_mode==5)
          {
            writeMPU6050(MPU6050_INT_ENABLE, 0x00);
            power_mode=0;           
          }

 /* order to go in sleep mode */
            
 if (power_mode==4){

            delay(10);
            goto_sleep();             
                    }

/* Mode for open page configution portal wifi */

  if(power_mode==1)
            {

            httpServer.handleClient();
            if (millis()-delay_reboot>DELAY_REBOOT){system_restart(); }
          
            }


/* Page for configure probe on the httpServer or firmware page */  
  

 if(power_mode==2)
            {
             httpServer.handleClient();
             if (millis()-delay_reboot>DELAY_REBOOT){httpServer.stop();power_mode==4;} // close httpServer and put cpu in sleep mode 
 
            }
                 
            
/* Set mode to do mesurements */

 if(flag==3)
            {
      
            writeMPU6050(MPU6050_INT_ENABLE, 0x00);                         //disable interupt on the MPU 6050
            readbyteMPU6050(MPU6050_INT_STATUS);                                //Clear interupt on MPU6050                        
            time_wake_up=millis();                                          //Start time out   
            writeMPU6050(MPU6050_USER_CTRL,0x44);                           //reset buffer
            delay(10);

            //writeMPU6050(MPU6050_USER_CTRL,0xC4); 
            flag=1;                                                         //Start measurement
  
            }
 /* Control ride run, if it does not run, stay the cpu in sleep mode */           

 if(power_mode==0) {  
                  
             if((millis()-time_wake_up>TIME_SLEEP_MODE&&run_ride==0))
                      {
                       power_mode=4;
                      }
             }
 
/* Datas ready to be read */
  
 if(flag==1)          
            { 

             readMPU6050(MPU6050_FIFO_COUNT_H);                 // Update the number of datas in the buffer
             
             if(data>5){               
                     Serial.print(data);Serial.print("*");
                     updateFifoMPU6050();

                  
                     /* Conditions  start ride and stop ride */
                     if(((accX>0.5)&&(accZ<0.8))&&(run_ride<2)&&(activation==0)){                      // start signal   
                                if (run_ride==0){start_delay=millis();run_ride=1;}
                                else if (millis()-start_delay>START_DELAY)
                                {
                                  f=SPIFFS.open("/datas.txt", "a");  
                                  run_ride=2;
                                  Serial.println F("Start ride");                                  
                                  lasttime= millis();
                                } 
                                }
                     else if (run_ride==1){run_ride=0;}                                                // If signal is not confirm, end of start ride
    
                    
                     if(((accX<-0.6)&&(accZ<0.8))&&((run_ride==2)||(run_ride==3))&&(end_ride_sample<number_samples)){                   // stop signal
                                if (run_ride==2){stop_delay=millis();run_ride=3;}
                                else if (millis()-stop_delay>STOP_DELAY)
                                {
                                    periode= millis()-lasttime;run_ride=4; 
                                    Serial.println F("End of ride");                                  // Use to control the period of time, debug tool
                                    Serial.print(periode);Serial.println("ms/");   f.close();}
                                }
                                
                     else if (run_ride==3){run_ride=2;}                                               // If signal is not confirm, continu mesure
    
                     if (number_samples>max_sample_ride){run_ride=4; Serial.println F("Out time, stop ride"); f.close();}
                    
                     /*record datas in file currently open*/
                    
                     if((run_ride==2)||(run_ride==3)) {
                      
                                String datas= String(accX,3)+";"+String(accY,3)+";"+String(accZ,3)+"%";
                                f.print(datas);
                        
                                //Serial.println(datas);      
    
                                if(max_x<accX){max_x=accX;}
                                if(max_y<accY){max_y=accY;}
                                if(max_z<accZ){max_z=accZ;}
                                if(min_x>accX){min_x=accX;}
                                if(min_y>accY){min_y=accY;}
                                if(min_z>accZ){min_z=accZ;}
                                i++;
                                number_samples++;             
                                }
                
                     else if (run_ride==4)  {
        
                                 //writeMPU6050(MPU6050_PWR_MGMT_1, 0x40);        // pause cycle/sleep           
                                 //ETS_GPIO_INTR_DISABLE();                       // disable interrupt mode
                                 i=0;
                                 run_ride=0;
                    
                                 //delay(5000);                                  // delay to wait the and of brake
    
                                 updateTempMPU6050();
                                 send_data();                                    // send data before goto spleep after
                                 number_samples=0;
                                 power_mode=4;                                   // Send spleep mode
                                 flag=0;
                                } 
 
            
          }
         
    }


}

      Le suivant gère la mise en route et la lecture de l'accéléromètre.

l'alimentation de l'accéléromètre est connectée sur la sortie D5. Cela permet de mieux gérer son initialisation.

/* Set configuration of the MPU6050 */

void beginMPU6050(void){

  Wire.flush();
  digitalWrite(D5,LOW);
  delay(1000);                                    
  digitalWrite(D5,HIGH);
  delay(500);
  writeMPU6050(MPU6050_PWR_MGMT_1, 0x01);        // Start MPU
  delay(100);
  writeMPU6050(MPU6050_SIGNAL_PATH_RESET, 0x07); // Reset registrer of measurement
  writeMPU6050(MPU6050_PWR_MGMT_1, 0x81);        // Reset MCU
  delay(500);
  digitalWrite(D5,LOW);
  delay(1000); 
  digitalWrite(D5,HIGH);
  delay(500);
  writeMPU6050(MPU6050_PWR_MGMT_1, 0x01);        // Start MPU
  delay(100);
  writeMPU6050(MPU6050_USER_CTRL,0x80);         // Active dmp
  delay(500);
  digitalWrite(D5,LOW);
  delay(1000); 
  digitalWrite(D5,HIGH);
  delay(500);
  writeMPU6050(MPU6050_PWR_MGMT_1, 0x00);        // Start MPU
  delay(100);
  writeMPU6050(MPU6050_USER_CTRL,0x44);         // Active And reset Buffer FIFO
  writeMPU6050(MPU6050_FIFO_EN, 0x08);          // Activate FIFO Buffer acc
  writeMPU6050(MPU6050_RA_MOT_THR,0x04);        // Threehold  motion x2mgx F/7
  writeMPU6050(MPU6050_RA_MOT_DUR,0x2F);        // duration motion  motion ms 1F
  writeMPU6050(MPU6050_PWR_MGMT_2, 0x07);       // Gyroscope into standby mode 
  writeMPU6050(MPU6050_CONFIG, hex_low_pass);   // 06 Configure for low pass filter at 5 Herzts, requier by Norm
  writeMPU6050(MPU6050_SMPLRT_DIV, hex_sample); // 0x07 for 8 ms Sample divider 1 Khz/1+ this number here to 100 hz59)-200(4)
  writeMPU6050(MPU6050_ACCEL_CONFIG, 0x11);     // Set +- 8g ET Digital hight pass
  writeMPU6050(MPU6050_INT_PIN_CFG,0xE0);       // OxE0 behavior Interrupt pin open drain interrupt low level
  //writeMPU6050(MPU6050_INT_ENABLE, 0x40);       //Set interrupt on motion détection*/
  delay(200);

}

/* Write datas in MP5060 */

void writeMPU6050(byte reg, byte data){
  
  Wire.beginTransmission(MPU6050_ADDR);
  Wire.write(reg);
  Wire.write(data);
  Wire.endTransmission(true);
  }
/* Read one registrer */

byte readbyteMPU6050(byte reg) {
  
  Wire.beginTransmission(MPU6050_ADDR);
  Wire.write(reg);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU6050_ADDR, 1,(int)true);
  byte result = Wire.read();
  return result;
}


/* Read datas */

int readMPU6050(byte reg) {
  
  Wire.beginTransmission(MPU6050_ADDR);
  Wire.write(reg);   
  Wire.endTransmission(false);
  Wire.requestFrom(MPU6050_ADDR, 2,(int)true); // wemos
  data = Wire.read()<<8 | Wire.read();
  return data; 
  }

/*Acces to memory FIFO */

void updateFifoMPU6050(){
  
  Wire.beginTransmission(MPU6050_ADDR);
  Wire.write(0x74);    //0x74Wire.read() << 8 | Wire.read();
  Wire.endTransmission(false);
  Wire.requestFrom(MPU6050_ADDR, 6,(int)true); // wemos

  rawAccX = Wire.read() << 8 | Wire.read();
  rawAccY = Wire.read() << 8 | Wire.read();
  rawAccZ = Wire.read() << 8 | Wire.read();

  accX = ((float)rawAccX) / 4096.0;  // Scale for =- 8G
  accY = ((float)rawAccY) / 4096.0;
  accZ = ((float)rawAccZ) / 4096.0;
  
   /* if calibration is not underway */
   
  if (activation!=1){ 
                     if (verticale_position==0){
                       accX = accX*gain_x+offset_x;
                       accY = accY*gain_y+offset_y;
                       accZ = accZ*gain_z+offset_z;} 
                     else{ 
                          float temporaire=accZ*gain_z+offset_z;
                          accZ=accX*gain_x+offset_x;
                          accX=-temp;
                          accY = accY*gain_y+offset_y;
                          accZ=temporaire;
                         }                  
                     }
}

/* Direct Acces to registrer */

 void updateDatasMPU6050(){
  
  Wire.beginTransmission(MPU6050_ADDR);
  Wire.write(0x3B);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU6050_ADDR, 6,(int)true); // wemos

  rawAccX = Wire.read() << 8 | Wire.read();
  rawAccY = Wire.read() << 8 | Wire.read();
  rawAccZ = Wire.read() << 8 | Wire.read();
 

  accX = ((float)rawAccX) / 4096.0;  // Scale for =- 8G
  accY = ((float)rawAccY) / 4096.0;
  accZ = ((float)rawAccZ) / 4096.0;

  /* if calibration is not underway */
  
  if (activation!=1){ 
                     if (verticale_position==0){
                       accX = accX*gain_x+offset_x;
                       accY = accY*gain_y+offset_y;
                       accZ = accZ*gain_z+offset_z;} 
                     else{ 
                          float temporaire=accZ*gain_z+offset_z;
                          accZ=accX*gain_x+offset_x;
                          accX=-temp;
                          accY = accY*gain_y+offset_y;
                          accZ=temporaire;
                         }                  
                     }  
 }


 void updateTempMPU6050(){
  
  Wire.beginTransmission(MPU6050_ADDR);
  Wire.write(0x3B);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU6050_ADDR, 2,(int)true);    // wemos

  rawTemp = Wire.read() << 8 | Wire.read();

  temp = ((float)rawTemp/ 340.0)+35;              //temp = ((float)rawTemp + 12412.0) / 340.0;
  if(activation!=1){temp= temp+offset_temp;}
 }
  

            Cette partie permet de récupérer les informations du serveur de données.

Il permet aussi à l'accéléromètre de s'identifier au prés du serveur.

/* Use to configure communication with wamp server and create data base for this */


void add_module(void){

              String reception;

      if ( httpServer.hasArg("ip_server") ) 
              {      
              reception=httpServer.arg("ip_server");
              int c = reception.length() + 1;                                              // lenght of string                  
              if ( c>15){ Serial.println(F("adresse ip invalide")); return;}
              Serial.println(reception);
              reception.toCharArray(ip_httpServer, c); 
              for (int i = 0; i < c; i++) { 
                                            EEPROM.write((i+ADRESS_SERVER),reception[i]);  // save adresse IP in EEPROM
                                            }  
              }

      if ( httpServer.hasArg("port") ) 
              {       
              reception = httpServer.arg("port");
              Serial.println(reception);
              port_httpServer=reception.toInt();           
              int b=port_httpServer;
              for (int a=0;a<2;a++){EEPROM.write(PORT_SERVER+a ,b);b=b>>8;}               // Save configuration port
              } 

      if ( httpServer.hasArg("name") ) 
              { 
              reception=httpServer.arg("name"); 
              int c = reception.length() + 1;                                 
              if ( c>20){Serial.println(F("Nom trop long"));return;} 
              Serial.println(reception);
              reception.toCharArray(name_module, c); 
              for (int i = 0; i < c; i++) { 
                                            EEPROM.write((i+NAME_MODULE),reception[i]);  // save adresse IP in EEPROM
                                            }  
              } 

      if ( httpServer.hasArg("period") )                                                 // Period to send datas
              {       
              reception = httpServer.arg("period");
              Serial.println(reception);
 
              } 
      EEPROM.commit();                                                                  // Make the recorder
      httpServer.send ( 200, "text/csv", answer_add_module() );                         // Send web page
}

/* Creat file csv with information for the php httpServer */

  String answer_add_module()
      {
          String page =name_module; page +=F(";");  page +=ref_module;  page +=F(";");  page +=local_mac;  page +=F(";");
                 page +=local_ip; page +=F(";");  page +=version_module; page +=F("\r\n");                                      // line 1 informations module       
                 
                 page +=F("coaster_accelerometer;a1;coaster_accelerometer;MPU5060\r\n");                                        // line 2 informations accelerometer   
                 
                 return page;
        }

         Ici le programme qui envoie l'enregistrement à la fin d'un ride. Remarquez que le wifi n'est activé qu'à ce moment.

/* send datas at the datas base */
    
    
    void send_data(void)      {
            
                /* Restart Wifi connection */
                wifi_set_opmode(STATION_MODE);                             //WIFI_AP
                wifi_station_connect();
                

                Serial.println F ("Start connection to wifi station");           
                //delay(3000);                                              // Waiting connection to Wifi
                while (wifi_station_get_connect_status() != STATION_CONNECTING){}
                time_ride= sample*number_samples;                         //calculate the time of ride
                f=SPIFFS.open("/datas.txt", "r+");                         //open file in read mode
                unsigned long lenght_string=f.size();                     
               
                Serial.print F ("The lenght of the message is : ");Serial.print(lenght_string); Serial.println F (" Bytes");
               
                unsigned long time_out_connection= millis();
                while (WiFi.status()!= WL_CONNECTED)
                  {
                    if (millis()-time_out_connection>10000)
                      {
                      Serial.println F ("connection Wifi fail ! Datas have not been send");
                                             
                      goto fin_connection;
                      }
                     delay(100);
                     Serial.print('-');
                  }
            
                if( WiFi.status()== WL_CONNECTED){
                Serial.println();
                Serial.println F ("Connection Wifi success!");
                
            
                String ligne1=("data=a1;"+local_mac+";"+local_ip+";"+temp+";"+sample+";"+time_ride+";"+max_x+";"+max_y+";"+max_z+";"+min_x+";"+min_y+";"+min_z+";"+date_calibration+";"+low_pass+"%");          
                long size_message= lenght_string + ligne1.length();
  
               
                WiFiClient client;                                        
            
               if (client.connect(ip_httpServer,port_httpServer))   
               //if (client.connect("www.innogreentech.fr",port_httpServer)) 
                         
                        {
                        Serial.println F ("Connection to server success, send datas");
                        delay(100);
                          
                        client.print   ("POST");
                        client.println (" /InnoGreenTech/controller/csv_accelerometer.php HTTP/1.1");
                        client.print   ("Host:");
                        client.println (ip_httpServer);
                        client.println ("Connection: Close");
                        client.println ("Content-Type: application/x-www-form-urlencoded");
                        client.print   ("Content-Length: ");
                        client.println (size_message);
                        client.print   ("\r\n");
                                  
                        client.print(ligne1); 
                        //Serial.println(ligne1);

                        /* send file*/
                        for(int a=0; a<lenght_string; a=a+500){
                                    int limit=lenght_string-a;
                                    if (limit>500){limit=500;}
                                    char char_datas[501];
                                    char_datas[500]=0;
                                    for (int index=0; index<500; index++){
                                    char_datas[index]=(char)f.read();                                    
                                   }
                                    client.print(char_datas);
                                    //Serial.println(char_datas);
                                   }                                          
                        /*delay(1000);
                        client.flush();
                        client.stop();*/
                        
                        // wait for data to be available
                        unsigned long timeout = millis();
                        while (client.available() == 0) {
                          if (millis() - timeout > 5000) {
                            Serial.println(">>> Client Timeout !");
                            goto fin;
                          }
                        }
                      
                        // Read all the lines of the reply from server and print them to Serial
                        Serial.println("receiving from remote server");
                        // not testing 'client.connected()' since we do not need to send data here
                        while (client.available()) {
                          char ch = static_cast(client.read());
                          Serial.print(ch);
                        }

                          // Close the connection
                         fin:
                        Serial.println();
                        Serial.println("closing connection");
                        client.flush();
                        client.stop();

                        
                        Serial.println F ("Success ! Datas have been sent");
                         }
                  else{Serial.println F ("Connection to httpServer fail ! Datas have not been send");client.flush();client.stop();} 
                           
                  }
           else{Serial.println F ("connection Wifi fail ! Datas have not been send");}
           fin_connection:
                  number_samples=0;
                  max_x=0;
                  max_y=0;
                  max_z=0;
                  min_x=0;
                  min_y=0;
                  min_z=0;
                  SPIFFS.rename("/datas.txt", "/back.txt");
                  f.close();

            delay(1000);
                 
            
            f=SPIFFS.open("/datas.txt", "w");                         
            f.print("");                       
            f.close();
            time_wake_up=millis();
            
            power_mode=0;
                  
            }

        Gestion de la veille et du réveille de l'accéléromètre.

/* wake up after sleep mode*/ 

 void  fpm_wakup_cb_func1(void)
  {

          wifi_disable_gpio_wakeup();
          wifi_fpm_close();            // disable force sleep function
          
          uint32 gpio_status;                               
          gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);         
          GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);
          
          Serial.println F ("Wake up");
          flag=3;
          power_mode=5;
  
  }
   
/* entry in sleep mode */
  
  void goto_sleep(void){



              ETS_GPIO_INTR_DISABLE();                                  //Disable interupt gpio esp
              //writeMPU6050(MPU6050_INT_ENABLE, 0x00);                   //disable interupt Mpu6050
              //uint32 gpio_status;                               
              //gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);         
              //GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);    //clear interrupt gpio  
              Serial.println ("");
              Serial.println F ("Go to sleep");

              writeMPU6050(MPU6050_USER_CTRL, 0x44);                    // FIFO RESET + enable DMP            
              writeMPU6050(MPU6050_INT_ENABLE, 0x40);                   // Enable move detection interrupt
              //delay(5);

              while (digitalRead(D6)==0){
              readbyteMPU6050(MPU6050_INT_STATUS);                         // Clear interrupt on MP5060
              delay(5);}
              flag=0;

              /*uint32 gpio_status;                               
              gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);         
              GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);*/
                         
              wifi_station_disconnect();
              wifi_set_opmode(NULL_MODE);                             // set WiFi  mode  to  null 
              delay(1000);         

              extern os_timer_t *timer_list;                         // close all timer
              while (timer_list != 0){timer_list = timer_list->timer_next;}           

              Serial.flush();                                        // empty serial buffer

              wifi_fpm_open();        
              //PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12);
              wifi_enable_gpio_wakeup(D6, GPIO_PIN_INTR_LOLEVEL);   // GPIO_PIN_INTR_LOLEVEL 
              wifi_fpm_set_wakeup_cb(fpm_wakup_cb_func1);           // wake up  fonction             
              wifi_fpm_do_sleep(0xFFFFFFF); 
              delay(2000);
              }



/* vadation of interruption to record the samples (actually not use) */

void datas_memory(void)
            {
             ETS_GPIO_INTR_DISABLE();
             
             flag=1;

             /* clear interrupt statut */
             uint32 gpio_status;
             gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
             GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);
            
             ETS_GPIO_INTR_ENABLE();
             readbyteMPU6050(MPU6050_INT_STATUS); 
             
            }  

        Portail pour la calibration et le réglage de l'accéléromètre.

/* use to set the accelerometer by customer */

void calibration(void){

       String reception;
       verticale_position=0;
       time_wake_up=millis();                                         // reset time out
       delay_reboot=millis();                                         // reset time out
       if (activation==0){
                          flag=3;
                          activation=1;
                          writeMPU6050(MPU6050_SMPLRT_DIV, 0xC7);     // Sample divider 1 Khz/1+ this number here to 5 hz for more disponibility of cpu
                          }                                           // activate sample
       

       
       if(httpServer.hasArg("Annulation"))
                 {
                  step_calibration=0;
                  activation=1;
                 }                 

       /* z calibration */
       
      if(step_calibration==0){
          if ( httpServer.hasArg("Validate")) 
                  {
                  gain_z=0;
                  offset_z=0; 
                  if(accZ<0.8){step_calibration=0;error_position=1;}  // If the accelerometer is not in the good position return the same page
                  else{ first_dot=accZ; error_position=0;}
                   }
      }

      if(step_calibration==1){
          if ( httpServer.hasArg("Validate")) 
                  {
                  if(accZ>-0.8){step_calibration=1;error_position=1;}  // If the accelerometer is not in the good position return the same page
                  else{ second_dot=accZ;
                        error_position=0;
                        offset_z=((second_dot+first_dot)*-1)/(first_dot-second_dot);
                        gain_z=(1-offset_z)/first_dot;                         
                         }                 
                  }
      }

      
       /* y calibration */
       
      if(step_calibration==2){
          if ( httpServer.hasArg("Validate")) 
                  {
                  gain_y=0;
                  offset_y=0;    
                  if(accY<0.8){step_calibration=2;error_position=1;}  // If the accelerometer is not in the good position return the same page
                  else{ first_dot=accY; error_position=0;}
                   }
      }

      if(step_calibration==3){
          if ( httpServer.hasArg("Validate")) 
                  {
                  //updateDatasMPU6050();
                  if(accY>-0.8){step_calibration=3;error_position=1;}  // If the accelerometer is not in the good position return the same page
                  else{ second_dot=accY;
                        error_position=0;
                        offset_y=((second_dot+first_dot)*-1)/(first_dot-second_dot);;
                        gain_y=(1-offset_y)/first_dot;                           
                        }                  
                   }
      }

       /* x calibration */
       
      if(step_calibration==4){
          if ( httpServer.hasArg("Validate")) 
                  {
                  gain_x=0;
                  offset_x=0;    
                  if(accX<0.8){step_calibration=4;error_position=1;}  // If the accelerometer is not in the good position return the same page
                  else{ first_dot=accX;error_position=0;}
                   }
      }

      if(step_calibration==5){
          if ( httpServer.hasArg("Validate")) 
                  {
                  //updateDatasMPU6050();
                  if(accX>-0.8){step_calibration=5;error_position=1;}  // If the accelerometer is not in the good position return the same page
                  else{ second_dot=accX;
                        error_position=0;
                        offset_x=((second_dot+first_dot)*-1)/(first_dot-second_dot);
                        gain_x=(1-offset_x)/first_dot;
                        activation=2;                           
                        }
                  
                   }
      }

      /* End of accelerometer calibration, wait validation */
      
      if(step_calibration==6){
          if ( httpServer.hasArg("date_calibration")) 
                  {
                    date_calibration=httpServer.arg("date_calibration");
                    int c = date_calibration.length() + 1;         // longueur de la chaîne de caractéres
                    for (int i = 0; i < c; i++) { 
                                  EEPROM.write((i+MEM_CALIBRATION),date_calibration[i]);  // Réglage du pointeur sur l'adresse mémoire
                                  }  

                    long consigneLong=long(offset_x*1000);
                    Serial.println(consigneLong);
                    for (int a=0;a<4;a++){EEPROM.write(OFFSET_X_MEM+a ,consigneLong);consigneLong=consigneLong>>8;}

                    consigneLong=long(gain_x*1000);
                    Serial.println(consigneLong);
                    for (int a=0;a<4;a++){EEPROM.write(GAIN_X_MEM+a ,consigneLong);consigneLong=consigneLong>>8;}
                  
                    consigneLong=long(offset_y*1000);
                    Serial.println(consigneLong);
                    for (int a=0;a<4;a++){EEPROM.write(OFFSET_Y_MEM+a ,consigneLong);consigneLong=consigneLong>>8;} 

                    consigneLong=long(gain_y*1000);
                    Serial.println(consigneLong);
                    for (int a=0;a<4;a++){EEPROM.write(GAIN_Y_MEM+a ,consigneLong);consigneLong=consigneLong>>8;}
                  
                    consigneLong=long(offset_z*1000);
                    Serial.println(consigneLong);
                    for (int a=0;a<4;a++){EEPROM.write(OFFSET_Z_MEM+a ,consigneLong);consigneLong=consigneLong>>8;} 

                    consigneLong=long(gain_z*1000);
                    Serial.println(consigneLong);
                    for (int a=0;a<4;a++){EEPROM.write(GAIN_Z_MEM+a ,consigneLong);consigneLong=consigneLong>>8;}

                    EEPROM.commit();                          
                    step_calibration++;              
                    }
          }

          /* Set temperrature,work position, filter, period samples and max time ride */
          
          if(step_calibration==7){

                    /* record ofset temperature */
                    if (httpServer.hasArg("offset_temperature")){
                    reception=httpServer.arg("offset_temperature");
                    offset_temp=reception.toFloat();
                    long consigneLong=long(offset_temp*100);
                    Serial.println(consigneLong);
                    for (int a=0;a<4;a++){EEPROM.write(OFFSET_T_MEM+a ,consigneLong);consigneLong=consigneLong>>8;}
                    }
                    
                    /* Record work position of the accelerometer */
                    if (httpServer.hasArg("position")){
                    reception=httpServer.arg("position");
                    verticale_position=reception.toInt();
                    if(verticale_position!=1){verticale_position=0;}     
                    int b=verticale_position;
                    for (int a=0;a<2;a++){EEPROM.write(POSITION_MEM+a ,b);b=b>>8;} 
                    
                    /* Record period of samples */
                    if (httpServer.hasArg("sample")){
                    reception=httpServer.arg("sample");
                    sample=reception.toInt();
                    EEPROM.write(SAMPLE_MEM,sample);                    
                    }

                    /*Record low filter configuration*/
                    if (httpServer.hasArg("low_pass")){
                    reception=httpServer.arg("low_pass");
                    low_pass=reception.toInt();
                    EEPROM.write(LOW_PASS_MEM,low_pass);
                    }

                    /*Record the max time for a ride*/

                   if(httpServer.hasArg("duration_ride")){
                    reception=httpServer.arg("duration_ride");
                    duration_ride=reception.toInt();
                    if(duration_ride>300){duration_ride=300;}
                    int b=duration_ride;
                    for (int a=0;a<2;a++){EEPROM.write(DURATION_RIDE_MEM+a ,b);b=b>>8;}
                   }
                    
                    EEPROM.commit();                          
                    step_calibration++;  
                      
                    }
                
      }
      
       if(error_position==0&&httpServer.hasArg("Validate")){ step_calibration++;}
      
       httpServer.send ( 200, "text/html", page_calibration() );                            // send web page
}


String page_calibration(){

/* Buttoms validate, restart calibration, warnong prevent */

String buttom1=F("<br><form method='GET'><input type='hidden' name='Validate' id='Validate'/> <input type='submit'  value='Validation'/> </form>");
String buttom2=F("<br><form method='GET'><input type='hidden' name='Annulation' id='Annulation'/> <input type='submit' value='Recommencer'/> </form>");
String warning=F("<p><strong>L'appareil n'a pas été positionné correctement, merci de le repositionner. </p>");

  
String  page =F("<!DOCTYPE html> <html lang=fr-FR> <head> <meta charset='utf-8'><title>Coaster accelerometer</title></head>"); 
        page +=F("<body");
        if( error_position==1){page +=F(" onload=\"alert('L appareil n a pas été positionné correctement, merci de le repositionner.');\"");}
        page +=F(">");
         

        
         
         page +=F("<h2> Calibration de l'accélérométre</h2>"); 

         page +=F("<br/>");
       
         if ( step_calibration==0){
         page +=F("<p>Etape 1/8 <br> Veuillez installer l'accéléromètre sur une surface de niveau en Z positif <br> Valider lorsque l'accélérométre est en position </P>");
         page +=buttom1;
         page +=buttom2;
         if( error_position==1){page +=warning;}
         }

         if ( step_calibration==1){
         page +=F("<p>Etape 2/8 <br> Veuillez installer l'accéléromètre sur une surface de niveau en Z négatif <br> Valider lorsque l'accélérométre est en position </P>");
         page +=buttom1;
         page +=buttom2;
         if( error_position==1){page +=warning;}
         }        

         
         if ( step_calibration==2){
         page +=F("<p>Etape 3/8 <br> Veuillez installer l'accéléromètre sur une surface de niveau en Y positif <br> Valider lorsque l'accélérométre est en position </P>");
         page +=buttom1;
         page +=buttom2;
         if( error_position==1){page +=warning;}
         }   
         
         if ( step_calibration==3){
         page +=F("<p>Etape 4/8 <br> Veuillez installer l'accéléromètre sur une surface de niveau en Y négatif. <br> Valider lorsque l'accélérométre est en position. </P>");
         page +=buttom1;
         page +=buttom2;
         if( error_position==1){page +=warning;}
         }        
         
         if ( step_calibration==4){
         page +=F("<p>Etape 5/8 <br> Veuillez installer l'accéléromètre sur une surface de niveau en X positif. <br> Valider lorsque l'accélérométre est en position. </P>");
         page +=buttom1;
         page +=buttom2;
         if( error_position==1){page +=warning;}
         }        

         if ( step_calibration==5){
         page +=F("<p>Etape 6/8 <br> Veuillez installer l'accéléromètre sur une surface de niveau en X négatif. <br> Valider lorsque l'accélérométre est en position. </P>");
         page +=buttom1;
         page +=buttom2;
         if( error_position==1){page +=warning;}
         }   

         if ( step_calibration==6){
         page +=F("<p>Etape 7/8 <br>Merci de vérifier que les valeurs affichées sont cohérentes.<br> Réactualise la page pour mettre à jour les valeurs. </P>");
         page +=F("<a href='calibration.html'><button >Actualisation</button></a><p><br></p>");
         page +=F("<table border=4 cellspacing=4 cellpadding=4 width=50%><tr><td>Gx</td><td>Gy</td><td>Gz</td></tr><tr><td>");
         page +=accX;page +=F("</td><td>");page +=accY;page +=F("</td><td>");page +=accZ;page +=F("</td></tr></table>");
         
         page +=F("<br><form method='GET'><input type='hidden' name='date_calibration' id='date_calibration'/><br><input type='submit' value='Validation' requiered/> </form>");

         page +=F("<script type='text/javascript'>");
         page +=F("function jour(){ var d = new Date().toJSON().slice(0, 10); return d;}");
         page +=F("var elem = document.getElementById('date_calibration');");
         page +=F("elem.value = jour();</script>");  
         
         page +=buttom2;


         } 
          /* page to set offset temperature and position of box */
          
         if ( step_calibration==7){
         offset_temp=0;     
         page +=F("<p>Etape 8/8 <br>Merci d'indiquer l'offset de température.<br> Ainsi que la postion d'utilisation du Boîtier.<br> 0 pour une utilisation horizontale et 1 Pour une utilisation verticale.<br> La température lu actuelle est de:");page +=temp;page +=F(" °C</P>");
         page +=F("<form method='GET'><label>Offset de température</label><input type='number' step='0.01' name='temperature' id='temperature'/><br><br>");
         page +=F("<label>Position d'utilisation</label><input type='number' name='position' id='position' value='0' requiered /><br><br>");
         page +=F("<label>Durée maximun du cycle en seconde</label><input type='number' name='duration_ride' id='duration_ride' value='120' max='300' requiered /><br><br>");
         page +=F("<label>Fréquence d'échantillonnage</label><select name='sample' id='sample'><option value=8 selected>125 Hz</option> <option value=4>250 Hz</option> </select><br><br>");
         page +=F("<label>Filtre passe bas en Hz</label><select name='low_pass' id='low_pass'><option value=5 selected>5 Hz</option> <option value=10>10 Hz</option> </select><br><br>");
         page +=F("<input type='submit' value='Validation'/> </form>");

         }

         if ( step_calibration==8){
    
         page +=F("<p>Fin <br>La configuration est maintenant terminée.<br> Merci d'éteindre puis de rallumer l'appareil pour finir l'installation.</P>");

         flag=4;
         }

         page +=F("</body>");
         page +=F("<br><footer><a href='http://www.innogreentech.fr'>InnoGreenTech</a><br/><a href='mailto: Cette adresse e-mail est protégée contre les robots spammeurs. Vous devez activer le JavaScript pour la visualiser.'>Contactez moi</a></footer>");
         page +=F("</html>");

return page;
}

       Portail pour la configuration du wifi de l'accéléromètre.

/* Portal to set wifi connection */

void handleRoot(void){ 

      /* PSSID set*/
      
      if ( httpServer.hasArg("SSID") ) { 
      Serial.print("SSID: ");
      ssid=httpServer.arg("SSID");
      Serial.println(ssid);
      int c = ssid.length() + 1;         
      for (int i = 0; i < c; i++) { 
                                  EEPROM.write((i+MEM_SSID),ssid[i]);  
                                  }                       
      } 
      
      if ( httpServer.hasArg("PASSWORD") ) {  
      Serial.print("password: ");
      password=httpServer.arg("PASSWORD");
      Serial.println(password);
      int c = password.length() + 1;        
                   
      for (int i = 0; i < c; i++) { 
                                  EEPROM.write((i+MEM_PASSWORD),password[i]);  
                                  }

       
                                  
             EEPROM.commit();               // Record informations
             delay (500);

             ESP.reset();
                                                               
      } 
      
               
       httpServer.send ( 200, "text/html", page_handleroot() );   // Send web page
    }
  


String page_handleroot(){
  
  String page =F("<!DOCTYPE html> <html lang=fr-FR> <head> <meta charset='utf-8'><title>Coaster accelerometer</title></head>"); 
         page +=F("<body><div id='page'");
         
        

         page +=F("<section id='configuration'>");
         page +=F("<h2> Configuration de la connexion wifi</h2>"); 

         page +=F("<br/>");
         page +=F("<br/>");

         page +=F("<p>adresse MAC: ");
         page +=local_mac;
         page +=F("<p/>");

         
         page +=F("<form method='get' accept='' >");

                  
         page +=F("<br/>");
         page +=F("<br/>");
                  
         page += F("<label>SSID: </label><br/>");
         page += F("<input type='texte' name='SSID' id='SSID' maxlength='45' value='");page +=ssid; page +=F("' />");
         
         page +=F("<br/>");
         page +=F("<br/>");
                  
         page += F("<label>Password: <br/></label>");
         page += F("<input type='password' name='PASSWORD' id='PASSWORD' maxlength='45' />");
         
         page +=F("<br/>");
         page +=F("<br/>"); 
                 
                
         page += F("<input type='submit'  value='Envoi'>");
         page += F("</p>");
         page += F("</form>");
         page += F("</section>");
     
         
        // page +=F("</div>");
         page +=F("<footer><a href='http://www.innogreentech.fr'>InnoGreenTech</a><br/><a href='mailto: Cette adresse e-mail est protégée contre les robots spammeurs. Vous devez activer le JavaScript pour la visualiser.'>Contactez moi</a></footer>");
         page +=F("</div></body></html>");

return page;
}

       Portail pour formater la mémoire Spiff de l'accéléromètre (lieu où sont enregistrées les données avant d'être transmises)

void format(void){

       
            if(httpServer.hasArg("format"))
                 {
                  if(step_format==0){step_format=1;}                 
                  if(step_format==2)
                    {
                      Serial.println F ("Format Flash memory, it takes several time");
                      SPIFFS.format();
                      step_format=3;
                    }                 
                 } 
                  
  httpServer.send ( 200, "text/html", page_format() );                            // send web page
}

String page_format(){

    String buttom1=F("<br><form method='GET'><input type='hidden' name='format' id='format'/> <input type='submit'  value='Validation'/> </form>");
    String  page =F("<!DOCTYPE html> <html lang=fr-FR> <head>");
            if(step_format==1)
            {
              page +=F("<META HTTP-EQUIV='Refresh' CONTENT='5;url=format.html?format='>");
            }
            page +=F("<meta charset='utf-8'>");
            page +=F("<title>Format accelerometer</title></head>");
            page +=F("<body");
            if (step_format==0){page +=F(" onload=\"alert('Attention vous êtes sur le point de formater la mémoire.');\"");}
            page +=F(">");
         

        
         
         page +=F("<h2> Formatage de la mémoire</h2>"); 
         
         page +=F("<br/>");

         if(step_format==0)
         {
           page +=F("<p>Valider pour confirmer le formatage </P>");
           page +=buttom1;
         }
         if(step_format==1)
         {
           page +=F("<p> Le formatage est en cours, merci de patienter quelques instants.<br> Ne débranchez pas l'accélérométre. </P>");
           step_format=2;

         }
         if(step_format==3)
         {
            page +=F("<p> Le formatage est terminé. </P>");
            step_format=0;
         }
         
return page;
}

 

 

Veuillez vous connecter ou créer un compte pour pouvoir poster un commentaire.

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.

Ok