WIZwiki-W7500_ADC + Flot Exemple interactivity + THING SPEAK
Dependencies: SDFileSystem STATIC_COLORS WIZnetInterface mbed
test durée de fonctionnement :
172 458 secondes ===> environs 48h
main.cpp@2:86f52ca432b8, 2016-07-09 (annotated)
- Committer:
- Fo170
- Date:
- Sat Jul 09 23:19:27 2016 +0000
- Revision:
- 2:86f52ca432b8
- Parent:
- 1:4853006cf179
- Child:
- 4:0e09a4c5bd22
WIZwiki-W7500 (100 sampling alternation of 50Hz sector and graphics Flot interactivity)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Fo170 | 0:70a1e939250e | 1 | #include "mbed.h" |
Fo170 | 0:70a1e939250e | 2 | #include "EthernetInterface.h" |
Fo170 | 0:70a1e939250e | 3 | #include "SDFileSystem.h" |
Fo170 | 0:70a1e939250e | 4 | #include <stdio.h> |
Fo170 | 0:70a1e939250e | 5 | #include <string.h> |
Fo170 | 0:70a1e939250e | 6 | |
Fo170 | 0:70a1e939250e | 7 | #define USE_DHCP 1 |
Fo170 | 0:70a1e939250e | 8 | /* |
Fo170 | 0:70a1e939250e | 9 | MAC Address Details ( http://www.macvendorlookup.com/ ) |
Fo170 | 0:70a1e939250e | 10 | Company Wiznet Address |
Fo170 | 0:70a1e939250e | 11 | Seoul 135-830 |
Fo170 | 0:70a1e939250e | 12 | Nonyhun, Kangnam |
Fo170 | 0:70a1e939250e | 13 | KOREA, REPUBLIC OF |
Fo170 | 0:70a1e939250e | 14 | Range : 00:08:DC:00:00:00 - 00:08:DC:FF:FF:FF |
Fo170 | 0:70a1e939250e | 15 | Type : MA-L: IEEE MAC Address Large (24-bit block size) |
Fo170 | 0:70a1e939250e | 16 | 3,1415926535897932384626433832795 |
Fo170 | 0:70a1e939250e | 17 | */ |
Fo170 | 0:70a1e939250e | 18 | //#define MAC "\x31\x41\x59\x26\x53\x58" |
Fo170 | 0:70a1e939250e | 19 | #define MAC "\x00\x08\xDC\x31\x41\x59" |
Fo170 | 0:70a1e939250e | 20 | //#define MAC "\x00\x08\xDC\x11\x34\x78" |
Fo170 | 0:70a1e939250e | 21 | #define IP "192.168.0.170" |
Fo170 | 0:70a1e939250e | 22 | #define MASK "255.255.255.0" |
Fo170 | 0:70a1e939250e | 23 | #define GATEWAY "192.168.0.254" |
Fo170 | 0:70a1e939250e | 24 | |
Fo170 | 0:70a1e939250e | 25 | #define HTTPD_SERVER_PORT 80 |
Fo170 | 0:70a1e939250e | 26 | #define HTTPD_MAX_REQ_LENGTH 1023 |
Fo170 | 0:70a1e939250e | 27 | #define HTTPD_MAX_HDR_LENGTH 255 |
Fo170 | 0:70a1e939250e | 28 | #define HTTPD_MAX_FNAME_LENGTH 127 |
Fo170 | 0:70a1e939250e | 29 | #define HTTPD_MAX_DNAME_LENGTH 127 |
Fo170 | 0:70a1e939250e | 30 | |
Fo170 | 0:70a1e939250e | 31 | #if defined(TARGET_WIZwiki_W7500) |
Fo170 | 0:70a1e939250e | 32 | Serial uart(USBTX, USBRX); |
Fo170 | 0:70a1e939250e | 33 | SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // WIZwiki-W7500 |
Fo170 | 0:70a1e939250e | 34 | #include "static_colors.h" |
Fo170 | 0:70a1e939250e | 35 | // LED RED : server listning status |
Fo170 | 0:70a1e939250e | 36 | // LED GREEN : socket connecting status Ok |
Fo170 | 0:70a1e939250e | 37 | // LED BLUE : socket connecting status Busy |
Fo170 | 0:70a1e939250e | 38 | #endif |
Fo170 | 0:70a1e939250e | 39 | |
Fo170 | 0:70a1e939250e | 40 | EthernetInterface eth; |
Fo170 | 0:70a1e939250e | 41 | TCPSocketServer server; |
Fo170 | 0:70a1e939250e | 42 | TCPSocketConnection client; |
Fo170 | 0:70a1e939250e | 43 | |
Fo170 | 0:70a1e939250e | 44 | char buffer[HTTPD_MAX_REQ_LENGTH+1]; |
Fo170 | 0:70a1e939250e | 45 | char httpHeader[HTTPD_MAX_HDR_LENGTH+1]; |
Fo170 | 0:70a1e939250e | 46 | char fileName[HTTPD_MAX_FNAME_LENGTH+1]; |
Fo170 | 0:70a1e939250e | 47 | char dirName[HTTPD_MAX_DNAME_LENGTH+1]; |
Fo170 | 0:70a1e939250e | 48 | char *uristr; |
Fo170 | 0:70a1e939250e | 49 | char *eou; |
Fo170 | 0:70a1e939250e | 50 | char *qrystr; |
Fo170 | 0:70a1e939250e | 51 | |
Fo170 | 0:70a1e939250e | 52 | FILE *fp; |
Fo170 | 0:70a1e939250e | 53 | int rdCnt; |
Fo170 | 0:70a1e939250e | 54 | |
Fo170 | 0:70a1e939250e | 55 | // Initialize a pins to perform analog input and digital output fucntions |
Fo170 | 0:70a1e939250e | 56 | AnalogIn ain0(A0); |
Fo170 | 0:70a1e939250e | 57 | AnalogIn ain1(A1); |
Fo170 | 0:70a1e939250e | 58 | AnalogIn ain2(A2); |
Fo170 | 0:70a1e939250e | 59 | AnalogIn ain3(A3); |
Fo170 | 0:70a1e939250e | 60 | |
Fo170 | 0:70a1e939250e | 61 | float a0_f, a1_f, a2_f, a3_f; |
Fo170 | 0:70a1e939250e | 62 | |
Fo170 | 0:70a1e939250e | 63 | #define __IP_LOCAL__ IP |
Fo170 | 0:70a1e939250e | 64 | #define __hebergement__ "http://olivier.fournet.free.fr/" |
Fo170 | 0:70a1e939250e | 65 | #define __Time_between_page_refresh__ "1" |
Fo170 | 2:86f52ca432b8 | 66 | //#include <hebergement.h> |
Fo170 | 0:70a1e939250e | 67 | |
Fo170 | 0:70a1e939250e | 68 | int refresh = 1; // 1 second refresh |
Fo170 | 0:70a1e939250e | 69 | |
Fo170 | 2:86f52ca432b8 | 70 | #define NB_SAMPLES_GPH 10 |
Fo170 | 2:86f52ca432b8 | 71 | unsigned long int Sample_gph = 0; |
Fo170 | 2:86f52ca432b8 | 72 | 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 }; |
Fo170 | 2:86f52ca432b8 | 73 | float time_samples[NB_SAMPLES_GPH];// = { -0.1,2,3,4,5,6,7,8,9,10,11,12,13,14 }; |
Fo170 | 0:70a1e939250e | 74 | float x_min = 0.0, x_max = 0.0; |
Fo170 | 0:70a1e939250e | 75 | float y_min = 0.0, y_max = 0.0; |
Fo170 | 0:70a1e939250e | 76 | float Seconds = 0.0; |
Fo170 | 2:86f52ca432b8 | 77 | //float meas = 0.0; |
Fo170 | 0:70a1e939250e | 78 | |
Fo170 | 0:70a1e939250e | 79 | //------------ |
Fo170 | 0:70a1e939250e | 80 | #define __Time_tic_in_Second__ 0.1 |
Fo170 | 0:70a1e939250e | 81 | |
Fo170 | 0:70a1e939250e | 82 | Ticker time_tic; |
Fo170 | 0:70a1e939250e | 83 | |
Fo170 | 2:86f52ca432b8 | 84 | //------------ |
Fo170 | 2:86f52ca432b8 | 85 | |
Fo170 | 2:86f52ca432b8 | 86 | #define FREQUENCE_SECTEUR 50 |
Fo170 | 2:86f52ca432b8 | 87 | #define NB_SAMPLES_PAR_OSCILLATION 100 |
Fo170 | 2:86f52ca432b8 | 88 | #define NB_SAMPLES 5000 // FREQUENCE_SECTEUR * NB_SAMPLES_PAR_OSCILLATION |
Fo170 | 2:86f52ca432b8 | 89 | #define TIME_SAMPLES_us 200 // 1000000 / NB_SAMPLES |
Fo170 | 2:86f52ca432b8 | 90 | unsigned long int Samples = 0; |
Fo170 | 2:86f52ca432b8 | 91 | |
Fo170 | 2:86f52ca432b8 | 92 | float time_between_two_measurement_ADC = 0.0; |
Fo170 | 2:86f52ca432b8 | 93 | float meas, meas_sum, meas_moy, meas_min, meas_max; |
Fo170 | 2:86f52ca432b8 | 94 | float vdc, vdc_min, vdc_max; |
Fo170 | 2:86f52ca432b8 | 95 | float vac, pow2_vac, sum_pow2_vac, veff; |
Fo170 | 2:86f52ca432b8 | 96 | |
Fo170 | 2:86f52ca432b8 | 97 | Ticker time_measurement_ADC; |
Fo170 | 2:86f52ca432b8 | 98 | |
Fo170 | 2:86f52ca432b8 | 99 | void measurement_ADC(void) |
Fo170 | 2:86f52ca432b8 | 100 | { |
Fo170 | 2:86f52ca432b8 | 101 | float meas_moy_t, veff_t; // valeurs temporaires |
Fo170 | 2:86f52ca432b8 | 102 | |
Fo170 | 2:86f52ca432b8 | 103 | meas = 3.3 * ain0.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
Fo170 | 2:86f52ca432b8 | 104 | //wait_us(10); |
Fo170 | 2:86f52ca432b8 | 105 | meas_sum += meas; |
Fo170 | 2:86f52ca432b8 | 106 | if(meas_min > meas) meas_min = meas; |
Fo170 | 2:86f52ca432b8 | 107 | if(meas_max < meas) meas_max = meas; |
Fo170 | 2:86f52ca432b8 | 108 | |
Fo170 | 2:86f52ca432b8 | 109 | vac = meas - 1.650; // 0V AC = 3,3V/2 |
Fo170 | 2:86f52ca432b8 | 110 | pow2_vac = vac * vac; // valeur VAC au carré |
Fo170 | 2:86f52ca432b8 | 111 | sum_pow2_vac += pow2_vac; // somme des valeurs AC au carré |
Fo170 | 2:86f52ca432b8 | 112 | |
Fo170 | 2:86f52ca432b8 | 113 | Samples++; |
Fo170 | 2:86f52ca432b8 | 114 | |
Fo170 | 2:86f52ca432b8 | 115 | if( Samples == NB_SAMPLES ) |
Fo170 | 2:86f52ca432b8 | 116 | { |
Fo170 | 2:86f52ca432b8 | 117 | // VDC |
Fo170 | 2:86f52ca432b8 | 118 | meas_moy_t = meas_sum; |
Fo170 | 2:86f52ca432b8 | 119 | meas_moy = meas_moy_t / (float)NB_SAMPLES; |
Fo170 | 2:86f52ca432b8 | 120 | // VAC |
Fo170 | 2:86f52ca432b8 | 121 | veff_t = sum_pow2_vac; |
Fo170 | 2:86f52ca432b8 | 122 | veff_t = veff_t / (float)NB_SAMPLES; |
Fo170 | 2:86f52ca432b8 | 123 | veff = sqrt(veff_t); |
Fo170 | 2:86f52ca432b8 | 124 | |
Fo170 | 2:86f52ca432b8 | 125 | Samples = 0; |
Fo170 | 2:86f52ca432b8 | 126 | meas_sum = 0.0; |
Fo170 | 2:86f52ca432b8 | 127 | vdc_min = meas_min, vdc_max = meas_max; |
Fo170 | 2:86f52ca432b8 | 128 | meas_min = 3.3 , meas_max = 0.0; |
Fo170 | 2:86f52ca432b8 | 129 | sum_pow2_vac = 0.0; |
Fo170 | 2:86f52ca432b8 | 130 | } |
Fo170 | 2:86f52ca432b8 | 131 | } |
Fo170 | 2:86f52ca432b8 | 132 | |
Fo170 | 2:86f52ca432b8 | 133 | void init_ADC_sampling(void) |
Fo170 | 2:86f52ca432b8 | 134 | { |
Fo170 | 2:86f52ca432b8 | 135 | //------------- |
Fo170 | 2:86f52ca432b8 | 136 | meas_moy = 0.0; |
Fo170 | 2:86f52ca432b8 | 137 | Samples = 0; |
Fo170 | 2:86f52ca432b8 | 138 | meas_sum = 0.0; |
Fo170 | 2:86f52ca432b8 | 139 | meas_min = 3.3 , meas_max = 0.0; |
Fo170 | 2:86f52ca432b8 | 140 | sum_pow2_vac = 0.0; |
Fo170 | 2:86f52ca432b8 | 141 | //----------------- |
Fo170 | 2:86f52ca432b8 | 142 | // 50 Hz --> 20ms |
Fo170 | 2:86f52ca432b8 | 143 | // 100 samples par oscillations = 20 / 100 = 0.2ms = 200µs |
Fo170 | 2:86f52ca432b8 | 144 | // 100 samples * 50 oscillations = 5000 samples au total par secondes |
Fo170 | 2:86f52ca432b8 | 145 | // interval: 200 micro seconds chaques samples |
Fo170 | 2:86f52ca432b8 | 146 | time_measurement_ADC.attach_us(&measurement_ADC, TIME_SAMPLES_us); |
Fo170 | 2:86f52ca432b8 | 147 | } |
Fo170 | 2:86f52ca432b8 | 148 | //------------ |
Fo170 | 2:86f52ca432b8 | 149 | |
Fo170 | 0:70a1e939250e | 150 | void add_one_tic() |
Fo170 | 0:70a1e939250e | 151 | { |
Fo170 | 0:70a1e939250e | 152 | int i; |
Fo170 | 0:70a1e939250e | 153 | |
Fo170 | 0:70a1e939250e | 154 | Seconds = Seconds + (float)__Time_tic_in_Second__; |
Fo170 | 0:70a1e939250e | 155 | |
Fo170 | 2:86f52ca432b8 | 156 | // mesures ADC --> measurement_ADC(); |
Fo170 | 2:86f52ca432b8 | 157 | /* |
Fo170 | 0:70a1e939250e | 158 | meas = ain0.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
Fo170 | 2:86f52ca432b8 | 159 | meas = meas * 3.3; // Change the value to be in the 0 to 3300 range |
Fo170 | 2:86f52ca432b8 | 160 | */ |
Fo170 | 0:70a1e939250e | 161 | x_min = x_max = Seconds; |
Fo170 | 2:86f52ca432b8 | 162 | y_min = y_max = meas_moy; //meas; |
Fo170 | 0:70a1e939250e | 163 | |
Fo170 | 2:86f52ca432b8 | 164 | for(i = 1 ; i < NB_SAMPLES_GPH ; i++) |
Fo170 | 0:70a1e939250e | 165 | { |
Fo170 | 0:70a1e939250e | 166 | time_samples[i-1] = time_samples[i]; |
Fo170 | 0:70a1e939250e | 167 | adc_samples[i-1] = adc_samples[i]; |
Fo170 | 0:70a1e939250e | 168 | if( time_samples[i] < x_min ) x_min = time_samples[i]; |
Fo170 | 0:70a1e939250e | 169 | if( time_samples[i] > x_max ) x_max = time_samples[i]; |
Fo170 | 0:70a1e939250e | 170 | if( adc_samples[i] < y_min ) y_min = adc_samples[i]; |
Fo170 | 0:70a1e939250e | 171 | if( adc_samples[i] > y_max ) y_max = adc_samples[i]; |
Fo170 | 0:70a1e939250e | 172 | } |
Fo170 | 0:70a1e939250e | 173 | |
Fo170 | 2:86f52ca432b8 | 174 | adc_samples[NB_SAMPLES_GPH-1] = meas_moy; //meas; |
Fo170 | 2:86f52ca432b8 | 175 | time_samples[NB_SAMPLES_GPH-1] = Seconds; |
Fo170 | 0:70a1e939250e | 176 | } |
Fo170 | 0:70a1e939250e | 177 | //------------ |
Fo170 | 0:70a1e939250e | 178 | |
Fo170 | 0:70a1e939250e | 179 | Ticker ledTick; |
Fo170 | 0:70a1e939250e | 180 | |
Fo170 | 0:70a1e939250e | 181 | char *pch; |
Fo170 | 0:70a1e939250e | 182 | char ext[5]; |
Fo170 | 0:70a1e939250e | 183 | char ext_gif[] = "gif"; |
Fo170 | 0:70a1e939250e | 184 | char ext_jpg[] = "jpg"; |
Fo170 | 0:70a1e939250e | 185 | char ext_png[] = "png"; |
Fo170 | 0:70a1e939250e | 186 | char ext_tiff[] = "tiff"; |
Fo170 | 0:70a1e939250e | 187 | int pos_ext; |
Fo170 | 0:70a1e939250e | 188 | int extLen; |
Fo170 | 0:70a1e939250e | 189 | |
Fo170 | 0:70a1e939250e | 190 | void ledTickfunc() |
Fo170 | 0:70a1e939250e | 191 | { |
Fo170 | 0:70a1e939250e | 192 | led_r = !led_r; |
Fo170 | 0:70a1e939250e | 193 | } |
Fo170 | 0:70a1e939250e | 194 | |
Fo170 | 0:70a1e939250e | 195 | void printf_send_client(const char *str_c) |
Fo170 | 0:70a1e939250e | 196 | { |
Fo170 | 0:70a1e939250e | 197 | char http_send[HTTPD_MAX_REQ_LENGTH+1]; |
Fo170 | 0:70a1e939250e | 198 | sprintf(http_send,str_c); |
Fo170 | 0:70a1e939250e | 199 | client.send(http_send,strlen(http_send)); |
Fo170 | 0:70a1e939250e | 200 | } |
Fo170 | 0:70a1e939250e | 201 | |
Fo170 | 2:86f52ca432b8 | 202 | #include "WIZwiki_W7500_Interactivity_css.h" |
Fo170 | 2:86f52ca432b8 | 203 | #include "WIZwiki_W7500_Interactivity_js.h" |
Fo170 | 2:86f52ca432b8 | 204 | |
Fo170 | 0:70a1e939250e | 205 | void variables(void) |
Fo170 | 0:70a1e939250e | 206 | { |
Fo170 | 0:70a1e939250e | 207 | printf_send_client("<SCRIPT script language=\"javascript\" type=\"text/javascript\">\r\n"); |
Fo170 | 0:70a1e939250e | 208 | |
Fo170 | 0:70a1e939250e | 209 | a0_f = ain0.read()*3.3; |
Fo170 | 0:70a1e939250e | 210 | sprintf(httpHeader,"A0 = %3.3f;\r\n", a0_f); |
Fo170 | 0:70a1e939250e | 211 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 0:70a1e939250e | 212 | |
Fo170 | 0:70a1e939250e | 213 | a1_f = ain1.read()*3.3; |
Fo170 | 0:70a1e939250e | 214 | sprintf(httpHeader,"A1 = %3.3f;\r\n", a1_f); |
Fo170 | 0:70a1e939250e | 215 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 0:70a1e939250e | 216 | |
Fo170 | 0:70a1e939250e | 217 | a2_f = ain2.read()*3.3; |
Fo170 | 0:70a1e939250e | 218 | sprintf(httpHeader,"A2 = %3.3f;\r\n", a2_f); |
Fo170 | 0:70a1e939250e | 219 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 0:70a1e939250e | 220 | |
Fo170 | 0:70a1e939250e | 221 | a3_f = ain3.read()*3.3; |
Fo170 | 0:70a1e939250e | 222 | sprintf(httpHeader,"A3 = %3.3f;\r\n", a3_f); |
Fo170 | 0:70a1e939250e | 223 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 0:70a1e939250e | 224 | |
Fo170 | 0:70a1e939250e | 225 | printf_send_client("</SCRIPT>\r\n"); |
Fo170 | 0:70a1e939250e | 226 | } |
Fo170 | 0:70a1e939250e | 227 | |
Fo170 | 0:70a1e939250e | 228 | void ETAT(void) |
Fo170 | 0:70a1e939250e | 229 | { |
Fo170 | 0:70a1e939250e | 230 | int i; |
Fo170 | 0:70a1e939250e | 231 | |
Fo170 | 0:70a1e939250e | 232 | // httpHeader |
Fo170 | 0:70a1e939250e | 233 | printf_send_client("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Close\r\n\r\n"); |
Fo170 | 0:70a1e939250e | 234 | |
Fo170 | 0:70a1e939250e | 235 | // Début page Web |
Fo170 | 0:70a1e939250e | 236 | printf_send_client("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\r\n"); |
Fo170 | 0:70a1e939250e | 237 | // meta_refresh |
Fo170 | 0:70a1e939250e | 238 | sprintf(httpHeader,"<meta http-equiv=\"refresh\" content=\"" __Time_between_page_refresh__ ";url=http://%s/\">\r\n", eth.getIPAddress() ); |
Fo170 | 0:70a1e939250e | 239 | //sprintf(httpHeader,"<meta http-equiv=\"refresh\" content=\"1;url=http://%s/\">\r\n", eth.getIPAddress() ); |
Fo170 | 0:70a1e939250e | 240 | //sprintf(httpHeader,"<meta http-equiv=\"refresh\" content=\"%u;url=http://%s/\">\r\n", refresh, eth.getIPAddress() ); |
Fo170 | 0:70a1e939250e | 241 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 0:70a1e939250e | 242 | |
Fo170 | 0:70a1e939250e | 243 | printf_send_client("<html><head>\r\n"); |
Fo170 | 0:70a1e939250e | 244 | // title |
Fo170 | 0:70a1e939250e | 245 | printf_send_client("<title>WIZwiki-W7500 - Flot Examples: Interactivity</title>\r\n"); |
Fo170 | 2:86f52ca432b8 | 246 | // CSS |
Fo170 | 2:86f52ca432b8 | 247 | CSS(); |
Fo170 | 2:86f52ca432b8 | 248 | // JavaScript Interactivity |
Fo170 | 2:86f52ca432b8 | 249 | init_WIZwiki_W7500_Interactivity_JS(); |
Fo170 | 2:86f52ca432b8 | 250 | WIZwiki_W7500_Interactivity_JS(); |
Fo170 | 2:86f52ca432b8 | 251 | /*sprintf(httpHeader,"<script language=\"javascript\" type=\"text/javascript\" src=\"" __hebergement__ "electronique/e/WIZwiki-W7500/js/WIZwiki-W7500_Interactivity_init.js\"></script>\r\n"); |
Fo170 | 0:70a1e939250e | 252 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 2:86f52ca432b8 | 253 | */ |
Fo170 | 2:86f52ca432b8 | 254 | //printf_send_client("<script language=\"javascript\" type=\"text/javascript\">init_WIZwiki_W7500_Interactivity();</script>\r\n"); |
Fo170 | 0:70a1e939250e | 255 | |
Fo170 | 0:70a1e939250e | 256 | // Variables JavaScript |
Fo170 | 0:70a1e939250e | 257 | printf_send_client("<script language=\"javascript\" type=\"text/javascript\">\r\n"); |
Fo170 | 0:70a1e939250e | 258 | printf_send_client("var color_Y = \"#FF0000\";\r\n"); |
Fo170 | 2:86f52ca432b8 | 259 | printf_send_client("var label_Y = \"Meas Moy (V)\";\r\n"); |
Fo170 | 0:70a1e939250e | 260 | // sprintf(httpHeader, "var x_min = -0.5, x_max = 14.5, y_min = -0.5, y_max = 1.5;\r\n"); // TEST |
Fo170 | 0:70a1e939250e | 261 | 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); |
Fo170 | 0:70a1e939250e | 262 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 0:70a1e939250e | 263 | |
Fo170 | 0:70a1e939250e | 264 | // 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 |
Fo170 | 0:70a1e939250e | 265 | // client.send(httpHeader,strlen(httpHeader)); // TEST |
Fo170 | 0:70a1e939250e | 266 | |
Fo170 | 2:86f52ca432b8 | 267 | if(Sample_gph > NB_SAMPLES_GPH) |
Fo170 | 0:70a1e939250e | 268 | { |
Fo170 | 0:70a1e939250e | 269 | printf_send_client("var array_value = ["); |
Fo170 | 2:86f52ca432b8 | 270 | |
Fo170 | 2:86f52ca432b8 | 271 | for(i = 0 ; i < NB_SAMPLES_GPH ; i++) |
Fo170 | 0:70a1e939250e | 272 | { |
Fo170 | 2:86f52ca432b8 | 273 | if(i < NB_SAMPLES_GPH-1) sprintf(httpHeader, "[%.1f,%.1f],", time_samples[i], adc_samples[i]); |
Fo170 | 0:70a1e939250e | 274 | else sprintf(httpHeader, "[%.1f,%.1f]", time_samples[i], adc_samples[i]); |
Fo170 | 0:70a1e939250e | 275 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 0:70a1e939250e | 276 | } |
Fo170 | 0:70a1e939250e | 277 | printf_send_client("];\r\n"); |
Fo170 | 0:70a1e939250e | 278 | } |
Fo170 | 0:70a1e939250e | 279 | |
Fo170 | 2:86f52ca432b8 | 280 | Sample_gph++; |
Fo170 | 0:70a1e939250e | 281 | printf_send_client("</script>\r\n"); |
Fo170 | 0:70a1e939250e | 282 | |
Fo170 | 0:70a1e939250e | 283 | // <SCRIPT> |
Fo170 | 0:70a1e939250e | 284 | variables(); |
Fo170 | 0:70a1e939250e | 285 | // <FIN SCRIPT> |
Fo170 | 0:70a1e939250e | 286 | // Fin Variable JavaScript |
Fo170 | 0:70a1e939250e | 287 | printf_send_client("</head><body><center>\r\n"); |
Fo170 | 0:70a1e939250e | 288 | |
Fo170 | 0:70a1e939250e | 289 | sprintf(httpHeader,"<h2>WIZwiki-W7500 - mBED</h2> ( Compiled at : %s and %s )<p>\r\n", __DATE__ , __TIME__); |
Fo170 | 0:70a1e939250e | 290 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 2:86f52ca432b8 | 291 | |
Fo170 | 0:70a1e939250e | 292 | printf_send_client("<p>(<a href=\"http://www.flotcharts.org/flot/examples/interacting/index.html\">Flot Examples: Interactivity</a>)<p>\r\n"); |
Fo170 | 0:70a1e939250e | 293 | |
Fo170 | 0:70a1e939250e | 294 | printf_send_client("ETAT :<p>\r\n"); |
Fo170 | 0:70a1e939250e | 295 | |
Fo170 | 0:70a1e939250e | 296 | sprintf(httpHeader,"IP: %s, MASK: %s, GW: %s<p>\r\n", |
Fo170 | 0:70a1e939250e | 297 | eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway()); |
Fo170 | 0:70a1e939250e | 298 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 0:70a1e939250e | 299 | |
Fo170 | 2:86f52ca432b8 | 300 | sprintf(httpHeader,"˜A0 : %3.3fV , \r\n", a0_f); |
Fo170 | 0:70a1e939250e | 301 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 0:70a1e939250e | 302 | |
Fo170 | 2:86f52ca432b8 | 303 | sprintf(httpHeader,"˜A1 : %3.3fV , \r\n", a1_f); |
Fo170 | 0:70a1e939250e | 304 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 0:70a1e939250e | 305 | |
Fo170 | 2:86f52ca432b8 | 306 | sprintf(httpHeader,"˜A2 : %3.3fV , \r\n", a2_f); |
Fo170 | 0:70a1e939250e | 307 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 0:70a1e939250e | 308 | |
Fo170 | 2:86f52ca432b8 | 309 | sprintf(httpHeader,"˜A3 : %3.3fV<p>\r\n", a3_f); |
Fo170 | 0:70a1e939250e | 310 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 0:70a1e939250e | 311 | |
Fo170 | 2:86f52ca432b8 | 312 | sprintf(httpHeader, "ADC (A0) :<p>DC : %.3fVmoy ( sum : %.3f - Samples : %u )<br>\r\n", meas_moy, meas_sum, Samples); |
Fo170 | 2:86f52ca432b8 | 313 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 2:86f52ca432b8 | 314 | |
Fo170 | 2:86f52ca432b8 | 315 | sprintf(httpHeader, "DC (0 à 3,3V) : %.3fVmin, %.3fVmax , Vdiff : %.0fmV<br>\r\n", vdc_min, vdc_max, 1000.0*(vdc_max - vdc_min)); |
Fo170 | 2:86f52ca432b8 | 316 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 2:86f52ca432b8 | 317 | |
Fo170 | 2:86f52ca432b8 | 318 | sprintf(httpHeader, "AC (-1,65V à 1,65V) : %.3fVeff<p>\r\n", veff); |
Fo170 | 2:86f52ca432b8 | 319 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 0:70a1e939250e | 320 | |
Fo170 | 2:86f52ca432b8 | 321 | sprintf(httpHeader, "Time : %.1f Seconds - Sample Graphique : %u<p>\r\n", Seconds, Sample_gph);// diplays the human readable Seconds |
Fo170 | 2:86f52ca432b8 | 322 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 0:70a1e939250e | 323 | |
Fo170 | 2:86f52ca432b8 | 324 | WIZwiki_W7500_Interactivity_div(); |
Fo170 | 2:86f52ca432b8 | 325 | //printf_send_client("<p><script language=\"javascript\" type=\"text/javascript\">WIZwiki_W7500_Interactivity();</script><p>\r\n"); |
Fo170 | 2:86f52ca432b8 | 326 | |
Fo170 | 2:86f52ca432b8 | 327 | printf_send_client("<p><p><a href=\"..\">Root</a>\r\n"); |
Fo170 | 2:86f52ca432b8 | 328 | |
Fo170 | 2:86f52ca432b8 | 329 | printf_send_client("</center></body></html>\r\n"); |
Fo170 | 0:70a1e939250e | 330 | } |
Fo170 | 0:70a1e939250e | 331 | |
Fo170 | 0:70a1e939250e | 332 | //-------------------------------------------- |
Fo170 | 0:70a1e939250e | 333 | |
Fo170 | 0:70a1e939250e | 334 | int main(void) |
Fo170 | 0:70a1e939250e | 335 | { |
Fo170 | 0:70a1e939250e | 336 | // initialisation des variables |
Fo170 | 0:70a1e939250e | 337 | int i; |
Fo170 | 0:70a1e939250e | 338 | |
Fo170 | 2:86f52ca432b8 | 339 | init_ADC_sampling(); |
Fo170 | 2:86f52ca432b8 | 340 | //----------------- |
Fo170 | 2:86f52ca432b8 | 341 | |
Fo170 | 2:86f52ca432b8 | 342 | for(i = 0 ; i < NB_SAMPLES_GPH ; i++) |
Fo170 | 0:70a1e939250e | 343 | { |
Fo170 | 0:70a1e939250e | 344 | time_samples[i] = 0; |
Fo170 | 0:70a1e939250e | 345 | adc_samples[i] = 0.0; |
Fo170 | 0:70a1e939250e | 346 | } |
Fo170 | 0:70a1e939250e | 347 | // Init the ticker with the address of the function (add_one_second) to be attached and the interval (1000 ms) |
Fo170 | 0:70a1e939250e | 348 | time_tic.attach(&add_one_tic, __Time_tic_in_Second__); |
Fo170 | 0:70a1e939250e | 349 | //-------------- |
Fo170 | 0:70a1e939250e | 350 | ledTick.attach(&ledTickfunc,0.5); |
Fo170 | 0:70a1e939250e | 351 | // Serial Interface eth; |
Fo170 | 0:70a1e939250e | 352 | // Serial port configuration (valeurs par defaut) : 9600 baud, 8-bit data, no parity, stop bit |
Fo170 | 0:70a1e939250e | 353 | uart.baud(9600); |
Fo170 | 0:70a1e939250e | 354 | uart.format(8, SerialBase::None, 1); |
Fo170 | 0:70a1e939250e | 355 | uart.printf("Initializing\n"); |
Fo170 | 0:70a1e939250e | 356 | wait(1.0); |
Fo170 | 0:70a1e939250e | 357 | // Check File System |
Fo170 | 0:70a1e939250e | 358 | uart.printf("Checking File System\n"); |
Fo170 | 0:70a1e939250e | 359 | DIR *d = opendir("/sd/"); |
Fo170 | 0:70a1e939250e | 360 | if(d != NULL) |
Fo170 | 0:70a1e939250e | 361 | { |
Fo170 | 0:70a1e939250e | 362 | uart.printf("SD Card Present\n"); |
Fo170 | 0:70a1e939250e | 363 | } |
Fo170 | 0:70a1e939250e | 364 | else |
Fo170 | 0:70a1e939250e | 365 | { |
Fo170 | 0:70a1e939250e | 366 | uart.printf("SD Card Root Directory Not Found\n"); |
Fo170 | 0:70a1e939250e | 367 | } |
Fo170 | 0:70a1e939250e | 368 | wait(1.0); |
Fo170 | 0:70a1e939250e | 369 | // EthernetInterface eth; |
Fo170 | 0:70a1e939250e | 370 | uart.printf("Initializing Ethernet\n"); |
Fo170 | 0:70a1e939250e | 371 | #if USE_DHCP |
Fo170 | 0:70a1e939250e | 372 | //eth.init Use DHCP |
Fo170 | 0:70a1e939250e | 373 | int ret = eth.init((uint8_t*)MAC); // Use DHCP for WIZnetInterface |
Fo170 | 0:70a1e939250e | 374 | uart.printf("Connecting DHCP\n"); |
Fo170 | 0:70a1e939250e | 375 | #else |
Fo170 | 0:70a1e939250e | 376 | int ret = eth.init((uint8_t*)MAC,IP,MASK,GATEWAY); //IP,mask,Gateway |
Fo170 | 0:70a1e939250e | 377 | uart.printf("Connecting (IP,mask,Gateway)\n"); |
Fo170 | 0:70a1e939250e | 378 | #endif |
Fo170 | 0:70a1e939250e | 379 | wait(1.0); |
Fo170 | 0:70a1e939250e | 380 | // Check Ethernet Link-Done |
Fo170 | 0:70a1e939250e | 381 | uart.printf("Check Ethernet Link\r\n"); |
Fo170 | 0:70a1e939250e | 382 | |
Fo170 | 0:70a1e939250e | 383 | if(eth.link() == true) |
Fo170 | 0:70a1e939250e | 384 | { |
Fo170 | 0:70a1e939250e | 385 | uart.printf("- Ethernet PHY Link - Done\r\n"); |
Fo170 | 0:70a1e939250e | 386 | //led_r = LED_ON; |
Fo170 | 0:70a1e939250e | 387 | COLOR(_RED_); |
Fo170 | 0:70a1e939250e | 388 | } |
Fo170 | 0:70a1e939250e | 389 | else |
Fo170 | 0:70a1e939250e | 390 | { |
Fo170 | 0:70a1e939250e | 391 | uart.printf("- Ethernet PHY Link - Fail\r\n"); |
Fo170 | 0:70a1e939250e | 392 | //led_r = LED_OFF; |
Fo170 | 0:70a1e939250e | 393 | COLOR(_BLACK_); |
Fo170 | 0:70a1e939250e | 394 | } |
Fo170 | 0:70a1e939250e | 395 | wait(1.0); |
Fo170 | 0:70a1e939250e | 396 | if(!ret) |
Fo170 | 0:70a1e939250e | 397 | { |
Fo170 | 0:70a1e939250e | 398 | uart.printf("Initialized, MAC: %s\r\n", eth.getMACAddress()); |
Fo170 | 0:70a1e939250e | 399 | ret = eth.connect(); |
Fo170 | 0:70a1e939250e | 400 | |
Fo170 | 0:70a1e939250e | 401 | if(!ret) |
Fo170 | 0:70a1e939250e | 402 | { |
Fo170 | 0:70a1e939250e | 403 | uart.printf("IP: %s, MASK: %s, GW: %s\r\n", |
Fo170 | 0:70a1e939250e | 404 | eth.getIPAddress(), eth.getNetworkMask(), eth.getGateway()); |
Fo170 | 0:70a1e939250e | 405 | // led_b = LED_ON, led_g = LED_ON; |
Fo170 | 0:70a1e939250e | 406 | COLOR(_CYAN_); |
Fo170 | 0:70a1e939250e | 407 | } |
Fo170 | 0:70a1e939250e | 408 | else |
Fo170 | 0:70a1e939250e | 409 | { |
Fo170 | 0:70a1e939250e | 410 | uart.printf("Error ethernet.connect() - ret = %d\r\n", ret); |
Fo170 | 0:70a1e939250e | 411 | //led_b = LED_OFF; |
Fo170 | 0:70a1e939250e | 412 | COLOR(_BLUE_); |
Fo170 | 0:70a1e939250e | 413 | exit(0); |
Fo170 | 0:70a1e939250e | 414 | } |
Fo170 | 0:70a1e939250e | 415 | } |
Fo170 | 0:70a1e939250e | 416 | else |
Fo170 | 0:70a1e939250e | 417 | { |
Fo170 | 0:70a1e939250e | 418 | uart.printf("Error ethernet.init() - ret = %d\r\n", ret); |
Fo170 | 0:70a1e939250e | 419 | //led_b = LED_OFF; |
Fo170 | 0:70a1e939250e | 420 | COLOR(_BLACK_); |
Fo170 | 0:70a1e939250e | 421 | exit(0); |
Fo170 | 0:70a1e939250e | 422 | } |
Fo170 | 0:70a1e939250e | 423 | wait(1.0); |
Fo170 | 0:70a1e939250e | 424 | // TCPSocketServer server; |
Fo170 | 0:70a1e939250e | 425 | server.bind(HTTPD_SERVER_PORT); |
Fo170 | 0:70a1e939250e | 426 | server.listen(); |
Fo170 | 0:70a1e939250e | 427 | uart.printf("Server Listening\n"); |
Fo170 | 0:70a1e939250e | 428 | |
Fo170 | 0:70a1e939250e | 429 | while(true) |
Fo170 | 0:70a1e939250e | 430 | { |
Fo170 | 0:70a1e939250e | 431 | uart.printf("\nWait for new connection...\r\n"); |
Fo170 | 0:70a1e939250e | 432 | server.accept(client); |
Fo170 | 0:70a1e939250e | 433 | client.set_blocking(false, 1500); // Timeout after (1.5)s |
Fo170 | 0:70a1e939250e | 434 | |
Fo170 | 0:70a1e939250e | 435 | uart.printf("Connection from: %s\r\n", client.get_address()); |
Fo170 | 0:70a1e939250e | 436 | while(true) |
Fo170 | 0:70a1e939250e | 437 | { |
Fo170 | 0:70a1e939250e | 438 | //led_g = LED_ON; |
Fo170 | 0:70a1e939250e | 439 | COLOR(_GREEN_); |
Fo170 | 0:70a1e939250e | 440 | int n = client.receive(buffer, sizeof(buffer)); |
Fo170 | 0:70a1e939250e | 441 | if(n <= 0) break; |
Fo170 | 0:70a1e939250e | 442 | uart.printf("Recieved Data: %d\r\n\r\n%.*s\r\n",n,n,buffer); |
Fo170 | 0:70a1e939250e | 443 | if(n >= 1024) |
Fo170 | 0:70a1e939250e | 444 | { |
Fo170 | 0:70a1e939250e | 445 | sprintf(httpHeader,"HTTP/1.1 413 Request Entity Too Large \r\nContent-Type: text\r\nConnection: Close\r\n\r\n"); |
Fo170 | 0:70a1e939250e | 446 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 0:70a1e939250e | 447 | client.send(buffer,n); |
Fo170 | 0:70a1e939250e | 448 | break; |
Fo170 | 0:70a1e939250e | 449 | } |
Fo170 | 0:70a1e939250e | 450 | else |
Fo170 | 0:70a1e939250e | 451 | { |
Fo170 | 0:70a1e939250e | 452 | buffer[n]=0; |
Fo170 | 0:70a1e939250e | 453 | } |
Fo170 | 0:70a1e939250e | 454 | if(!strncmp(buffer, "GET ", 4)) |
Fo170 | 0:70a1e939250e | 455 | { |
Fo170 | 0:70a1e939250e | 456 | uristr = buffer + 4; |
Fo170 | 0:70a1e939250e | 457 | eou = strstr(uristr, " "); |
Fo170 | 0:70a1e939250e | 458 | if(eou == NULL) |
Fo170 | 0:70a1e939250e | 459 | { |
Fo170 | 0:70a1e939250e | 460 | sprintf(httpHeader,"HTTP/1.1 400 Bad Request \r\nContent-Type: text\r\nConnection: Close\r\n\r\n"); |
Fo170 | 0:70a1e939250e | 461 | client.send(httpHeader,strlen(httpHeader)); |
Fo170 | 0:70a1e939250e | 462 | client.send(buffer,n); |
Fo170 | 0:70a1e939250e | 463 | } |
Fo170 | 0:70a1e939250e | 464 | else |
Fo170 | 0:70a1e939250e | 465 | { |
Fo170 | 0:70a1e939250e | 466 | *eou = 0; |
Fo170 | 0:70a1e939250e | 467 | //get_file(uristr); |
Fo170 | 0:70a1e939250e | 468 | ETAT(); |
Fo170 | 0:70a1e939250e | 469 | } |
Fo170 | 0:70a1e939250e | 470 | } |
Fo170 | 0:70a1e939250e | 471 | } |
Fo170 | 0:70a1e939250e | 472 | //led_g = LED_OFF; |
Fo170 | 0:70a1e939250e | 473 | COLOR(_BLACK_); |
Fo170 | 0:70a1e939250e | 474 | client.close(); |
Fo170 | 0:70a1e939250e | 475 | } |
Fo170 | 0:70a1e939250e | 476 | } |