Offline
God Member
Karma: 4
Posts: 931
|
 |
« on: February 17, 2012, 05:31:16 am » |
bonjour à tous, me revoilà enfin après une surcharge de boulot, je me penche enfin sur le joujou offert pour noel. merci encore  voila le projet je désire récupérer des données sur mes servers contenues dans un fichier txt. jusque là, pas de problème pour afficher dans la console, je suis parti du script simpleclient du wishield. là ou ca se corse, c'est pour récupérer les valeurs de certaines variables et les afficher sur ma page web. mais avant d'aller plus loin, la question est: est ce possible?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
God Member
Karma: 4
Posts: 931
|
 |
« Reply #1 on: February 17, 2012, 06:28:46 am » |
voici le code #include <WiServer.h> #define WIRELESS_MODE_INFRA 1 #define WIRELESS_MODE_ADHOC 2
int sensibilite = 0; int i = 1; int line ; int nbr ; // Wireless configuration parameters ---------------------------------------- unsigned char local_ip[] = {192,168,2,200}; // IP address of WiShield unsigned char gateway_ip[] = {192,168,2,2}; // router or gateway IP address unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network const prog_char ssid[] PROGMEM = {"infobarquee-maison"};
unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters
// WEP 128-bit keys // sample HEX keys prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3 };
// setup the wireless mode // infrastructure - connect to AP // adhoc - connect to another WiFi device unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len; unsigned char security_passphrase_len; // End of wireless configuration parameters ----------------------------------------
// Function that prints data from the server void printData(char* data, int len) { // Print the data returned by the server // Note that the data is not null-terminated, may be broken up into smaller packets, and // includes the HTTP header. while (len-- > 0) { Serial.print(*(data++)); } }
// IP Address for my ip server uint8 ip[] = {xx,xx,xx,xx};
// A request that gets the data for test GETrequest getWeather(ip, 80, "yyyyy.fr", "/test.txt");
void setup() {
//initialize sendMyPage WiServer.init(sendMyPage); // Enable Serial output and ask WiServer to generate log messages (optional) Serial.begin(9600); WiServer.enableVerboseMode(true);
// Have the processData function called when data is returned by the server getWeather.setReturnFunc(printData); } char *ar_strstr(const char *haystack, const char *needle) int getNbr(char *line) {
nbr = 0; while (*line >= '0' && *line <= '9') { nbr *= 10; nbr += *line - '0'; line++; } return (nbr); } int getConf(char *val) {
char line[100]; char i;
i = 0; while ((line[i] > 0) { if (line[i] == '\n') { line[i] = '\0'; i = 0; if (ar_strstr(line, val) && line[ar_strlen(val)] == '=') {
return (getNbr(line + ar_strlen(val) + 1)); } i++; } return 0;
} boolean sendMyPage(char* URL) { if (strcmp(URL, "/") == 0) { WiServer.print("<html>"); WiServer.print("<h1>test</h1>"); WiServer.print("</html>"); return true; } return false; }
// Time (in millis) when the data should be retrieved long updateTime = 0;
void loop(){
// Check if it's time to get an update if (millis() >= updateTime) { getWeather.submit(); // Get another update one hour from now updateTime += 1000 * 60 * 60; }
// Run WiServer WiServer.server_task();
delay(10); } retour erreur SimpleClient1.cpp:88: erreur: expected initializer before ‘int’
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Faraday Member
Karma: 8
Posts: 2616
|
 |
« Reply #2 on: February 17, 2012, 06:49:41 am » |
retour erreur
SimpleClient1.cpp:88: erreur: expected initializer before ‘int’
bonjour tu es sous quel IDE ? intuitivement ça vient peut être du "probleme" du fichier apps-conf.h (dans la librarie wishield) dont cette partie doit être modifiée selon l'utilisation de la wishield ----- //#define APP_WEBSERVER //#define APP_WEBCLIENT //#define APP_SOCKAPP //#define APP_UDPAPP #define APP_WISERVER ----
|
|
|
|
|
Logged
|
|
|
|
|
Offline
God Member
Karma: 4
Posts: 931
|
 |
« Reply #3 on: February 17, 2012, 07:00:20 am » |
salut Artouste, j'y avais pensé aussi, mais la ligne est bien décommentée.
|
|
|
|
|
Logged
|
|
|
|
|
France
Offline
Edison Member
Karma: 14
Posts: 1841
There is an Arduino for that
|
 |
« Reply #4 on: February 17, 2012, 09:06:36 am » |
A l'endroit indiqué, il y a deux définitions de fonctions char *ar_strstr(const char *haystack, const char *needle) int getNbr(char *line) { ....... Je n'ai pas de temps d'approfondir, mais j'ai l'impression que tu as collé 2 fonctions à l'intérieur d'une autre.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
God Member
Karma: 4
Posts: 931
|
 |
« Reply #5 on: February 17, 2012, 09:39:23 am » |
oui, je reprends mon script qui tourne bien sous ethernetshield pour voir si je peux l'adapter au wishield. mais je commence a douter de la faisabilité de la chose. surtout que j'ai plus le SD card avec le wishield.
A ce propos, peut on mettre sur le uno, un ethernet shield et le wishield en même temps?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 84
|
 |
« Reply #6 on: February 17, 2012, 10:14:22 am » |
Je pense que c'est cette ligne-là qui pose problème : char *ar_strstr(const char *haystack, const char *needle) Elle ressemble à un début d'implémentation de fonction mais il manque les accolades et l'implémentation elle-même. Ou alors c'est une déclaration mais il manque un point virgule !
|
|
|
|
|
Logged
|
|
|
|
|
France
Offline
Edison Member
Karma: 14
Posts: 1841
There is an Arduino for that
|
 |
« Reply #7 on: February 17, 2012, 10:36:26 am » |
Je pense que c'est cette ligne-là qui pose problème : char *ar_strstr(const char *haystack, const char *needle) Elle ressemble à un début d'implémentation de fonction mais il manque les accolades et l'implémentation elle-même. Ou alors c'est une déclaration mais il manque un point virgule ! Mais pas seulement c'est pour ça que j'ai dit que je n'avais pas pu voir le problème à fond. En corrigeant cette erreur, il en sort d'autres du bois.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
God Member
Karma: 4
Posts: 931
|
 |
« Reply #8 on: February 17, 2012, 11:01:32 am » |
petite avancée de la chose, plus d'erreur, mais je récupère pas les données pour les afficher sur ma page. dans la console je les récupère mis à part un léger bug que je ne comprends pas trop Last-Modified: Mon, 13 Feb 2012 18:12:16 GMT
ETag: "24234-75-4b8dc6b19a000"
Accept-Ranges: bytes
Content-Length: 117
Vary: Accept-Encoding
Connection: close
Content-Type: text/plain
sensibilite=3; lumiere=255; lumieretemps=10;
BUG ICI lumiereRX 65 bytes from yyyyyyy.fr 1=199; FIN DU BUG
lumieretemps1=10; lumiere2=99; lumieretemps2=10; twit=1;
Ended connection with yyyyyyyy.fr
Server connected
Processing request for /
TX 51 bytes
Server connection closed
#include <WiServer.h> #define WIRELESS_MODE_INFRA 1 #define WIRELESS_MODE_ADHOC 2
int sensibilite = 0; int i = 1; int line ; int nbr ;
// Wireless configuration parameters ---------------------------------------- unsigned char local_ip[] = {192,168,2,200}; // IP address of WiShield unsigned char gateway_ip[] = {192,168,2,2}; // router or gateway IP address unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network const prog_char ssid[] PROGMEM = {"infobarquee-maison"};
unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters
// WEP 128-bit keys // sample HEX keys prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3 };
// setup the wireless mode // infrastructure - connect to AP // adhoc - connect to another WiFi device unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len; unsigned char security_passphrase_len; // End of wireless configuration parameters ----------------------------------------
// Function that prints data from the server void printData(char* data, int len) { // Print the data returned by the server // Note that the data is not null-terminated, may be broken up into smaller packets, and // includes the HTTP header. while (len-- > 0) { Serial.print(*(data++)); } }
// IP Address for my ip server uint8 ip[] = {xx,xx,xx,xx};
// A request that gets the data for test GETrequest getWeather(ip, 80, "yyyyyyyy.fr", "/test.txt");
void setup() {
//initialize sendMyPage WiServer.init(sendMyPage); // Enable Serial output and ask WiServer to generate log messages (optional) Serial.begin(9600); WiServer.enableVerboseMode(true);
// Have the processData function called when data is returned by the server getWeather.setReturnFunc(printData); }
int ar_strlen(const char *s) { const char *p = s;
while (*p != '\0') p++; return (size_t)(p - s); }
char *ar_strchr(const char *s, int c) { while (*s != '\0' && *s != (char)c) s++; return ( (*s == c) ? (char *) s : NULL ); }
char *ar_strstr(const char *haystack, const char *needle) { size_t needlelen;
if (*needle == '\0') return (char *) haystack; needlelen = ar_strlen(needle); for (; (haystack = ar_strchr(haystack, *needle)) != NULL; haystack++) if (ar_strncmp(haystack, needle, needlelen) == 0) return (char *) haystack; return NULL; }
int ar_strncmp(const char *s1, const char *s2, size_t n) { unsigned char uc1, uc2;
if (n == 0) return 0; while (n-- > 0 && *s1 == *s2) { if (n == 0 || *s1 == '\0') return 0; s1++; s2++; } uc1 = (*(unsigned char *) s1); uc2 = (*(unsigned char *) s2); return ((uc1 < uc2) ? -1 : (uc1 > uc2)); }
int getNbr(char *line) { int nbr;
nbr = 0; while (*line >= '0' && *line <= '9') { nbr *= 10; nbr += *line - '0'; line++; } return (nbr); }
int getConf(char *val) {
char line[100]; char i;
i = 0;
if (line[i] == '\n') { line[i] = '\0'; i = 0; if (ar_strstr(line, val) && line[ar_strlen(val)] == '=') { return (getNbr(line + ar_strlen(val) + 1)); } } else { ++i; }
return 0; }
boolean sendMyPage(char* URL) { if (strcmp(URL, "/") == 0) { WiServer.print("<html>"); WiServer.print("<h1>test</h1>"); //WiServer.print("sensibilite : "); WiServer.println(getConf("sensibilite"));
//WiServer.print("lumieretemps : ")); WiServer.println(getConf("lumieretemps"));
WiServer.print("</html>"); return true; } return false; }
// Time (in millis) when the data should be retrieved long updateTime = 0;
void loop(){
// Check if it's time to get an update if (millis() >= updateTime) { getWeather.submit(); // Get another update one hour from now updateTime += 1000 * 60 * 60; }
// Run WiServer WiServer.server_task();
delay(10); }
|
|
|
|
|
Logged
|
|
|
|
|
France
Offline
Edison Member
Karma: 14
Posts: 1841
There is an Arduino for that
|
 |
« Reply #9 on: February 17, 2012, 02:02:07 pm » |
Lorsque tu entres dans la fonction getConf, la variable line (variable locale) n'est pas initialisée. Donc ta fonction recopie le contenu de la pile jusqu'à trouver un \n.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
God Member
Karma: 4
Posts: 931
|
 |
« Reply #10 on: February 17, 2012, 02:13:19 pm » |
tout a fait. c'est là ou je cherche a placer ce bout de code quelque part pour récupérer les données. mais je vois pas comment mettre toutes ces données dans un tableau sachant que le header est inclus dans la réponse du server.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
God Member
Karma: 4
Posts: 931
|
 |
« Reply #11 on: February 18, 2012, 06:37:47 am » |
bon je galère toujours sur ce problème. par contre, un autre intervient, au bout d'un moment, impossible d'accéder à la page web, le wifi s'éteind sur la carte. ping de son ip idem. il faut que je la reset pour la relancer???????
|
|
|
|
|
Logged
|
|
|
|
|
Offline
God Member
Karma: 4
Posts: 931
|
 |
« Reply #12 on: February 19, 2012, 05:33:16 am » |
bonjour, je continue de m'arracher les cheveux ce matin sur mon script. si quelqu'un voit pourquoi la récupération des données ne se met pas en tableau, je suis preneur. #include <WiServer.h> #define WIRELESS_MODE_INFRA 1 #define WIRELESS_MODE_ADHOC 2
int sensibilite = 0; int i = 1; int line ; int nbr ; int linetotal =0; char buffer[2] = { '\0', '\0'}; // buffer pour stocker le char avant/aprés char data[8]; // buffer pour stocker les donnée recu byte index = 0; // index pour le buffer circulaire // Wireless configuration parameters ---------------------------------------- unsigned char local_ip[] = {192,168,2,200}; // IP address of WiShield unsigned char gateway_ip[] = {192,168,2,2}; // router or gateway IP address unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network const prog_char ssid[] PROGMEM = {"infobarquee-maison"};
unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters
// WEP 128-bit keys // sample HEX keys prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3 };
// setup the wireless mode // infrastructure - connect to AP // adhoc - connect to another WiFi device unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len; unsigned char security_passphrase_len; // End of wireless configuration parameters ----------------------------------------
// Function that prints data from the server void printData(char* data, int len) { // Print the data returned by the server // Note that the data is not null-terminated, may be broken up into smaller packets, and // includes the HTTP header. while (len-- > 0) { Serial.print(*(data++)); linetotal++;
}
}
// IP Address for my ip server uint8 ip[] = {xx,xx,xx,xx};
// A request that gets the data for test GETrequest getWeather(ip, 80, "yyyyyyyy.fr", "/test.txt");
int ar_strlen(const char *s) { const char *p = s;
while (*p != '\0') p++; return (size_t)(p - s); }
char *ar_strchr(const char *s, int c) { while (*s != '\0' && *s != (char)c) s++; return ( (*s == c) ? (char *) s : NULL ); } char *ar_strstr(const char *haystack, const char *needle) { size_t needlelen;
if (*needle == '\0') return (char *) haystack; needlelen = ar_strlen(needle); for (; (haystack = ar_strchr(haystack, *needle)) != NULL; haystack++) if (ar_strncmp(haystack, needle, needlelen) == 0) return (char *) haystack; return NULL; }
int ar_strncmp(const char *s1, const char *s2, size_t n) { unsigned char uc1, uc2;
if (n == 0) return 0; while (n-- > 0 && *s1 == *s2) { if (n == 0 || *s1 == '\0') return 0; s1++; s2++; } uc1 = (*(unsigned char *) s1); uc2 = (*(unsigned char *) s2); return ((uc1 < uc2) ? -1 : (uc1 > uc2)); }
int getNbr(char *line) { int nbr;
nbr = 0; while (*line >= '0' && *line <= linetotal) { nbr *= 10; nbr += *line - '0'; line++; } return (nbr); }
int getConf(char *data) { char line[100]; char i; i = 0; if (line[i] == '\n') { line[i] = '\0'; i = 0; if (ar_strstr(line, data) && line[ar_strlen(data)] == '=') { return (getNbr(line + ar_strlen(data) + 1)); } } else { ++i; } return 0; }
void setup() {
//initialize sendMyPage WiServer.init(sendMyPage); // Enable Serial output and ask WiServer to generate log messages (optional) Serial.begin(9600); WiServer.enableVerboseMode(true);
// Have the processData function called when data is returned by the server getWeather.setReturnFunc(printData); }
boolean sendMyPage(char* URL) { if (strcmp(URL, "/") == 0) { WiServer.print("<html>"); WiServer.print("<h1>test</h1>"); //WiServer.print("sensibilite : "); WiServer.println(getConf("sensibilite"));
//WiServer.print("lumieretemps : ")); WiServer.println(getConf("lumieretemps"));
WiServer.print("</html>"); return true; } return false; }
// Time (in millis) when the data should be retrieved long updateTime = 0;
void loop(){
// Check if it's time to get an update if (millis() >= updateTime) { getWeather.submit(); // Get another update one hour from now updateTime += 1000 * 60 ; }
// Run WiServer WiServer.server_task();
delay(10); }
|
|
|
|
|
Logged
|
|
|
|
|
|