Qualcuno è riuscito ad utilizzare uno scketch per accendere/spegnere un LED ?
Io sto testando questo, ma il LED non risponde. IL modulo è regolarmente connesso alla rete, invio da browser 192.168.1.155/on , la pagina si aggiorna correttamente, ma il LED rimane spento. Ho provato altri esempi trovati in rete e sempre lo stesso problema. Visualizzo le pagine, ma il LED non risponde.
Qualche idea?
M.
/*
* A simple sketch that uses WiServer to serve a web page
*/
#include <WiServer.h>
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
int ledPin = 7; // LED connected to digital pin 7
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,155}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {......}; // max 32 bytes
unsigned char security_type = 2; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {.....}; // 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 wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------
// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {
// Check if the requested URL matches "/"
if (strcmp(URL, "/on") == 0) {
digitalWrite(ledPin, HIGH); // set the LED on
// Use WiServer's print and println functions to write out t\he page content
WiServer.print("<html><body><meta name=\"viewport\" content=\"width=device-width, user-scalable=no\" />");
WiServer.print("<table width=\"320\"><tr><td>");
WiServer.print("<a href=\"off\">Hello I'm on! Turn me off.</a></td></tr>");
WiServer.print("</table></body></html>");
// URL was recognized
return true;
}
if (strcmp(URL, "/off") == 0) {
digitalWrite(ledPin, LOW); // set the LED off
// Use WiServer's print and println functions to write out the page content
WiServer.print("<html><body><meta name=\"viewport\" content=\"width=device-width, user-scalable=no\" />");
WiServer.print("<table width=\"320\"><tr><td>");
WiServer.print("<a href=\"on\">Goodbye I'm off! Turn me on.</a></td></tr>");
WiServer.print("</table></bdy></html>");
// URL was recognized
return true;
}
// URL not found
Serial.println("error");
WiServer.print("<html>");
WiServer.print("No such page!");
WiServer.print("</html>");
return false;
}
void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
// Initialize WiServer and have it use the sendMyPage function to serve pages
WiServer.init(sendMyPage);
// Enable Serial output and ask WiServer to generate log messages (optional)
Serial.begin(57600);
WiServer.enableVerboseMode(true);
}
void loop(){
// Run WiServer
WiServer.server_task();
delay(10);
}
edit by mod:
per favore, leggere il regolamento del forum prima di postare