I would like to have webpage data change the status of an led - specifically solar storm conditions displayed at NOAA space weather site.
How can I get started?
Greg
I would like to have webpage data change the status of an led - specifically solar storm conditions displayed at NOAA space weather site.
How can I get started?
Greg
Maybe you should describe it more detailed, such as how many wifi shields you need? How long the distances you need to control? If the distance is not so long, you just need one wifi shield, else, you may need two ones.
There’re a simple demo for controlling a led via single wifi shield.FYI.
#include "Wifly.h"
#include <SoftwareSerial.h>
WiflyClass Wifly(2,3);
void setup()
{
Serial.begin(9600);
pinMode(8, OUTPUT); //the pin of your led
Wifly.init();
Wifly.setConfig("SSID","password"); //you need input SSID and password
Wifly.join("SSID"); //you need input SSID
while(!Wifly.connect("Your IP address","90")); //input IP address
Wifly.writeToSocket("Connected!");
}
char dtaSocket[10]; //the max leng of command
int dtaLen = 0; //actual leng of command
unsigned char getDta = 0;
unsigned char judge(char *str1, char *str2, int n) //discriminant function
{
for(int i = 0; i<n; i++)
{
if(str1[i] != str2[i])
{
return 0;
}
}
return 1;
}
void loop()
{
if(Wifly.canReadFromSocket())
{
dtaSocket[dtaLen++] = Wifly.readFromSocket();
if(dtaSocket[dtaLen-1]=='\n')
{
getDta = 1;
}
if(dtaLen > 8)
{
getDta = 0;
dtaLen = 0;
}
}
if(getDta)
{
getDta = 0;
if(judge(dtaSocket, "on", 2) && dtaLen == 4) //turn led on when you input "on"
{
Serial.print("led on:\t");
Serial.println(dtaLen);
digitalWrite(8, HIGH);
}
else if(judge(dtaSocket, "off", 3) && dtaLen == 5) //turn led off when you input "off"
{
Serial.print("led off:\t");
Serial.println(dtaLen);
digitalWrite(8, LOW);
}
else
{
Serial.println("unavailable command"); //only two command is available,others are not
digitalWrite(8,LOW);
}
dtaLen = 0;
}
while(Serial.available())
{
Wifly.print((char)Serial.read());
}
}
The type of input on the monitor may be “Newline”. And the libraries i have used is wifi shield v1(seeedstudio.com/wiki/Wifi_Shield), you need modify some codes if using the libraries of wifi shield v1.2.
Jacket