WIZwiki-W7500_ADC + Flot Exemple interactivity + THING SPEAK

Dependencies:   SDFileSystem STATIC_COLORS WIZnetInterface mbed

/media/uploads/Fo170/wizwiki-w7500_adc.png

/media/uploads/Fo170/wizwiki_thing_speak.png

test durée de fonctionnement :

/media/uploads/Fo170/test_duree.png

172 458 secondes ===> environs 48h

Revision:
4:0e09a4c5bd22
Parent:
2:86f52ca432b8
Child:
5:d5a3be58b76a
--- a/main.cpp	Sat Jul 09 23:19:27 2016 +0000
+++ b/main.cpp	Sat Jul 09 23:41:13 2016 +0000
@@ -13,7 +13,7 @@
 KOREA, REPUBLIC OF
 Range : 00:08:DC:00:00:00 - 00:08:DC:FF:FF:FF
 Type : MA-L: IEEE MAC Address Large (24-bit block size)
-3,1415926535897932384626433832795
+
 */
 //#define MAC     "\x31\x41\x59\x26\x53\x58"
 #define MAC     "\x00\x08\xDC\x31\x41\x59"
@@ -63,105 +63,37 @@
 #define __IP_LOCAL__           IP
 #define  __hebergement__                  "http://olivier.fournet.free.fr/"
 #define  __Time_between_page_refresh__    "1"
-//#include <hebergement.h>
 
 int refresh = 1; // 1 second refresh
 
-#define NB_SAMPLES_GPH    10
-unsigned long int Sample_gph = 0;
-float adc_samples[NB_SAMPLES_GPH];// = { 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.01,1.02,1.03,1.04 };
-float time_samples[NB_SAMPLES_GPH];// = { -0.1,2,3,4,5,6,7,8,9,10,11,12,13,14 };
+#define NB_SAMPLES    10
+unsigned long int Sample = 0;
+float adc_samples[NB_SAMPLES];// = { 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.01,1.02,1.03,1.04 };
+float time_samples[NB_SAMPLES];// = { -0.1,2,3,4,5,6,7,8,9,10,11,12,13,14 };
 float x_min = 0.0, x_max = 0.0;
 float y_min = 0.0, y_max = 0.0;
 float Seconds = 0.0;
-//float meas = 0.0;
+float meas = 0.0;
 
 //------------
 #define      __Time_tic_in_Second__      0.1
 
 Ticker time_tic;
 
-//------------
-
-#define FREQUENCE_SECTEUR             50
-#define NB_SAMPLES_PAR_OSCILLATION    100
-#define NB_SAMPLES                    5000   // FREQUENCE_SECTEUR * NB_SAMPLES_PAR_OSCILLATION
-#define TIME_SAMPLES_us               200    // 1000000 / NB_SAMPLES
-unsigned long int Samples = 0;
-
-float time_between_two_measurement_ADC = 0.0;
-float meas, meas_sum, meas_moy, meas_min, meas_max;
-float vdc, vdc_min, vdc_max;
-float vac, pow2_vac, sum_pow2_vac, veff;
-
-Ticker time_measurement_ADC;
-
-void measurement_ADC(void)
-{
- float meas_moy_t, veff_t; // valeurs temporaires
- 
-    meas = 3.3 * ain0.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
-    //wait_us(10);
-    meas_sum += meas;
-    if(meas_min > meas) meas_min = meas;
-    if(meas_max < meas) meas_max = meas;
-
-    vac = meas - 1.650; // 0V AC = 3,3V/2
-    pow2_vac = vac * vac; // valeur VAC au carré
-    sum_pow2_vac += pow2_vac; // somme des valeurs AC au carré
-
-    Samples++;
-
-    if( Samples == NB_SAMPLES ) 
-    {
-        // VDC
-        meas_moy_t = meas_sum;
-        meas_moy = meas_moy_t / (float)NB_SAMPLES;
-        // VAC
-        veff_t = sum_pow2_vac;
-        veff_t = veff_t / (float)NB_SAMPLES;
-        veff = sqrt(veff_t);
-
-        Samples = 0;
-        meas_sum = 0.0;
-        vdc_min = meas_min, vdc_max = meas_max;
-        meas_min = 3.3 , meas_max = 0.0;
-        sum_pow2_vac = 0.0;
-    }
-}
-
-void init_ADC_sampling(void)
-{
- //-------------
- meas_moy = 0.0;
- Samples = 0;
- meas_sum = 0.0;
- meas_min = 3.3 , meas_max = 0.0;
- sum_pow2_vac = 0.0;
- //-----------------
- // 50 Hz --> 20ms
- // 100 samples par oscillations = 20 / 100 = 0.2ms = 200µs
- // 100 samples * 50 oscillations = 5000 samples au total par secondes
- // interval: 200 micro seconds chaques samples
- time_measurement_ADC.attach_us(&measurement_ADC, TIME_SAMPLES_us);   
-}
-//------------
-
 void add_one_tic()
 {       
  int i;
  
  Seconds = Seconds + (float)__Time_tic_in_Second__;
  
- // mesures ADC  --> measurement_ADC();
- /*
+ // mesures ADC
     meas = ain0.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
-    meas = meas * 3.3; // Change the value to be in the 0 to 3300 range
-  */  
+    meas = meas * 3300.0; // Change the value to be in the 0 to 3300 range
+    
     x_min = x_max = Seconds;
-    y_min = y_max = meas_moy; //meas;
+    y_min = y_max = meas;
                     
-    for(i = 1 ; i < NB_SAMPLES_GPH ; i++)
+    for(i = 1 ; i < NB_SAMPLES ; i++)
     {
      time_samples[i-1] = time_samples[i];
      adc_samples[i-1] = adc_samples[i];
@@ -171,8 +103,8 @@
      if( adc_samples[i] > y_max ) y_max = adc_samples[i];
     }
 
-    adc_samples[NB_SAMPLES_GPH-1] = meas_moy; //meas;
-    time_samples[NB_SAMPLES_GPH-1] = Seconds;
+    adc_samples[NB_SAMPLES-1] = meas;
+    time_samples[NB_SAMPLES-1] = Seconds;
 }
 //------------
 
@@ -199,9 +131,6 @@
  client.send(http_send,strlen(http_send));
 }
 
-#include "WIZwiki_W7500_Interactivity_css.h"
-#include "WIZwiki_W7500_Interactivity_js.h"
-
 void variables(void)
 {
  printf_send_client("<SCRIPT script language=\"javascript\" type=\"text/javascript\">\r\n");
@@ -222,7 +151,7 @@
  sprintf(httpHeader,"A3 = %3.3f;\r\n", a3_f);
  client.send(httpHeader,strlen(httpHeader));
  
- printf_send_client("</SCRIPT>\r\n");
+ printf_send_client("</SCRIPT>\r\n"); 
 }
 
 void ETAT(void)
@@ -234,6 +163,7 @@
             
   // Début page Web
   printf_send_client("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\r\n");
+
   // meta_refresh
   sprintf(httpHeader,"<meta http-equiv=\"refresh\" content=\"" __Time_between_page_refresh__ ";url=http://%s/\">\r\n", eth.getIPAddress() );
   //sprintf(httpHeader,"<meta http-equiv=\"refresh\" content=\"1;url=http://%s/\">\r\n", eth.getIPAddress() );
@@ -243,20 +173,16 @@
   printf_send_client("<html><head>\r\n");
   // title
   printf_send_client("<title>WIZwiki-W7500 - Flot Examples: Interactivity</title>\r\n");
-  // CSS
-  CSS();
-  // JavaScript Interactivity
-  init_WIZwiki_W7500_Interactivity_JS();
-  WIZwiki_W7500_Interactivity_JS(); 
-  /*sprintf(httpHeader,"<script language=\"javascript\" type=\"text/javascript\" src=\"" __hebergement__ "electronique/e/WIZwiki-W7500/js/WIZwiki-W7500_Interactivity_init.js\"></script>\r\n");
+  // JavaScript Interactivity  
+  sprintf(httpHeader,"<script language=\"javascript\" type=\"text/javascript\" src=\"" __hebergement__ "electronique/e/WIZwiki-W7500/js/WIZwiki-W7500_Interactivity_init.js\"></script>\r\n");
   client.send(httpHeader,strlen(httpHeader));
-  */
-  //printf_send_client("<script language=\"javascript\" type=\"text/javascript\">init_WIZwiki_W7500_Interactivity();</script>\r\n");
+  
+  printf_send_client("<script language=\"javascript\" type=\"text/javascript\">init_WIZwiki_W7500_Interactivity();</script>\r\n");
   
   // Variables JavaScript
   printf_send_client("<script language=\"javascript\" type=\"text/javascript\">\r\n");
   printf_send_client("var color_Y = \"#FF0000\";\r\n");
-  printf_send_client("var label_Y = \"Meas Moy (V)\";\r\n");
+  printf_send_client("var label_Y = \"Adc(mV)\";\r\n");
   // sprintf(httpHeader, "var x_min = -0.5, x_max =  14.5, y_min = -0.5, y_max =  1.5;\r\n"); // TEST
   sprintf(httpHeader, "var x_min = %.1f, x_max = %.1f, y_min = %.1f, y_max = %.1f;\r\n", x_min, x_max, y_min, y_max);
   client.send(httpHeader,strlen(httpHeader));
@@ -264,20 +190,20 @@
   // sprintf(httpHeader, "var array_value = [[-0.1,0.1],[2,0.2],[3,0.3],[4,0.4],[5,0.5],[6,0.6],[7,0.7],[8,0.8],[9,0.9],[10,1],[11,1.01],[12,1.02],[13,1.03],[14,1.04]];\r\n"); // TEST
   // client.send(httpHeader,strlen(httpHeader));  // TEST
   
-  if(Sample_gph > NB_SAMPLES_GPH)
+  if(Sample > NB_SAMPLES)
     {
      printf_send_client("var array_value = [");
 
-     for(i = 0 ; i < NB_SAMPLES_GPH ; i++)
+     for(i = 0 ; i < NB_SAMPLES ; i++)
      {
-      if(i < NB_SAMPLES_GPH-1) sprintf(httpHeader, "[%.1f,%.1f],", time_samples[i], adc_samples[i]);
+      if(i < NB_SAMPLES) sprintf(httpHeader, "[%.1f,%.1f],", time_samples[i], adc_samples[i]);
       else sprintf(httpHeader, "[%.1f,%.1f]", time_samples[i], adc_samples[i]);
       client.send(httpHeader,strlen(httpHeader));
      }
      printf_send_client("];\r\n");
     }
     
-    Sample_gph++;
+    Sample++;
     printf_send_client("</script>\r\n");
     
     // <SCRIPT>
@@ -288,7 +214,7 @@
             
   sprintf(httpHeader,"<h2>WIZwiki-W7500 - mBED</h2> ( Compiled at : %s and %s )<p>\r\n",  __DATE__ , __TIME__);
   client.send(httpHeader,strlen(httpHeader));
-   
+  
   printf_send_client("<p>(<a href=\"http://www.flotcharts.org/flot/examples/interacting/index.html\">Flot Examples: Interactivity</a>)<p>\r\n");
   
   printf_send_client("ETAT :<p>\r\n");
@@ -297,36 +223,30 @@
                       eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway());
   client.send(httpHeader,strlen(httpHeader));
   
-  sprintf(httpHeader,"&tilde;A0 : %3.3fV , \r\n", a0_f);
+  //sprintf(httpHeader,"&tilde;A0 :<script>document.write(A0);</script>V<br>\r\n");
+  sprintf(httpHeader,"&tilde;A0 : %3.3fV<br>\r\n", a0_f);
   client.send(httpHeader,strlen(httpHeader));
             
-  sprintf(httpHeader,"&tilde;A1 : %3.3fV , \r\n", a1_f);
+  //sprintf(httpHeader,"&tilde;A1 :<script>document.write(A1);</script>V<br>\r\n");
+  sprintf(httpHeader,"&tilde;A1 : %3.3fV<br>\r\n", a1_f);
   client.send(httpHeader,strlen(httpHeader));
             
-  sprintf(httpHeader,"&tilde;A2 : %3.3fV , \r\n", a2_f);
+  //sprintf(httpHeader,"&tilde;A2 :<script>document.write(A2);</script>V<br>\r\n");
+  sprintf(httpHeader,"&tilde;A2 : %3.3fV<br>\r\n", a2_f);
   client.send(httpHeader,strlen(httpHeader));
             
-  sprintf(httpHeader,"&tilde;A3 : %3.3fV<p>\r\n", a3_f);
+  //sprintf(httpHeader,"&tilde;A3 :<script>document.write(A3);</script>V<p>\r\n");
+  sprintf(httpHeader,"&tilde;A3 : %3.3fV<br>\r\n", a3_f);
   client.send(httpHeader,strlen(httpHeader));
   
-  sprintf(httpHeader, "ADC (A0) :<p>DC : %.3fVmoy ( sum : %.3f - Samples : %u )<br>\r\n", meas_moy, meas_sum, Samples);
-  client.send(httpHeader,strlen(httpHeader));
-    
-  sprintf(httpHeader, "DC (0 &agrave; 3,3V) : %.3fVmin,   %.3fVmax , Vdiff : %.0fmV<br>\r\n", vdc_min, vdc_max, 1000.0*(vdc_max - vdc_min));
-  client.send(httpHeader,strlen(httpHeader));
-    
-  sprintf(httpHeader, "AC (-1,65V &agrave; 1,65V) : %.3fVeff<p>\r\n", veff);
+  sprintf(httpHeader, "Time : %.1f Seconds - Sample : %u<p>\r\n", Seconds, Sample);// diplays the human readable Seconds
   client.send(httpHeader,strlen(httpHeader));
   
-  sprintf(httpHeader, "Time : %.1f Seconds - Sample Graphique : %u<p>\r\n", Seconds, Sample_gph);// diplays the human readable Seconds
-  client.send(httpHeader,strlen(httpHeader));
+  printf_send_client("<p><script language=\"javascript\" type=\"text/javascript\">WIZwiki_W7500_Interactivity();</script><p>\r\n");
   
-  WIZwiki_W7500_Interactivity_div();
-  //printf_send_client("<p><script language=\"javascript\" type=\"text/javascript\">WIZwiki_W7500_Interactivity();</script><p>\r\n");
+  printf_send_client("<p><a href=\"..\">Root</a>\r\n");
   
-  printf_send_client("<p><p><a href=\"..\">Root</a>\r\n");
-  
-  printf_send_client("</center></body></html>\r\n");               
+  printf_send_client("</center></body></html>\r\n");              
 }
 
 //--------------------------------------------
@@ -336,10 +256,7 @@
     // initialisation des variables
  int i;
  
- init_ADC_sampling();
- //-----------------
- 
- for(i = 0 ; i < NB_SAMPLES_GPH ; i++)
+ for(i = 0 ; i < NB_SAMPLES ; i++)
  {
       time_samples[i] = 0;
       adc_samples[i] = 0.0;
@@ -365,7 +282,7 @@
     {
         uart.printf("SD Card Root Directory Not Found\n");
     }
-   wait(1.0);
+ wait(1.0);
 //    EthernetInterface eth;
     uart.printf("Initializing Ethernet\n");
     #if USE_DHCP
@@ -419,7 +336,8 @@
      //led_b = LED_OFF;
      COLOR(_BLACK_);
      exit(0);
-    }    
+    }  
+      
     wait(1.0);
 //    TCPSocketServer server;
     server.bind(HTTPD_SERVER_PORT);