electronicramblings.com

Archive for January, 2013

Arduino WiShield WiServer Cosm Pachube DS18S20 Sketch

by on Jan.30, 2013, under Arduino, Arduino ATmega328, Electronic Projects, WiShield

This sketch took couple of days to get to where I was happy with the data being pushed to the Cosm site.

In this sketch I have succeeded on having the unit push temperature data to the Cosm.com site. 

There is some interesting information on doing this all over the web, but the best place I found for how to get float data to be pushed was from a free chapter of this book: Building Internet of things with the Arduino.

http://www.buildinginternetofthings.com/

Have a look, they have done a great job on this book, one I would recommend you buy if you want to get your Arduino on the web.

Have a look at the Sketch and see if there anything that will help on your next project.

Again this is a more of a reminder for me of the sketch and a working sketch for others to start from.

A picture of the data looks like on the COSM site….

cosm

Hardwared use:

Arduino 328 version

AysncLabs V1.0 Wishield

Dallas/Maxium DS18S20 1-wire temperature sensors.

Software:

Arduino Beta 1.1

Latest Dallas  and Wiserver Libraries.

Till next time, thanks for your time.

Sketch:

WiServer_Cosm_DS18S20_Jan_2013_Ver1_3

 

 

/*
* electronicramblings.com
*
* A sketch that uses WiServer to PUT (via POST) to Cosm
* Works with my WiShield ver 1.0 and Arduino 328.
* Very happy on its ability to push data.
* Cosm is setup for 4 variables.
* Have setup two DS18S20 sensors
* Did this to show a four graphs on Cosm.
* Good start to seeing how Cosm works.
* Sends out data every 30 seconds
* Jan 30, 2013
*/

#include <WiServer.h>
#include <string.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
#define ONE_WIRE_BUS 7
#define TEMPERATURE_PRECISION 12

//non WiShield defines
char buf1[16];
char buf2[16];
char buf3[16];
char buf4[16];
char buf5[32];
//Variables
float aB;
float cD;
float eF;
float gH;
//My four DS18S20 sensors address:
//Device is a DS18S20 : 10-EC-A7-48-00-08-00-47
DeviceAddress tempa={0X10, 0XEC, 0XA7, 0X48, 0X00, 0X08, 0X00, 0X47}; //DS18S20 temperature senor MAC address
//Device is a DS18S20 : 10-22-E1-48-00-08-00-BE
DeviceAddress tempb={0X10, 0X22, 0XE1, 0X48, 0X00, 0X08, 0X00, 0XBE}; //DS18S20 temperature senor MAC address
//Device is a DS18S20 : 10-21-D8-48-00-08-00-90
DeviceAddress tempc={0X10, 0X21, 0XD8, 0X48, 0X00, 0X08, 0X00, 0X90}; //DS18S20 temperature senor MAC address
//Device is a DS18S20 : 10-7F-E2-48-00-08-00-94
DeviceAddress tempd={0X10, 0X7F, 0XE2, 0X48, 0X00, 0X08, 0X00, 0X94}; //DS18S20 temperature senor MAC address

OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
//________________________________________________________________________
// Wireless configuration parameters —————————————-
unsigned char local_ip[] = {192,168,0,151}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,0,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 = {“dlink”}; // max 32 bytes

unsigned char security_type = 3; // 0 – open; 1 – WEP; 2 – WPA; 3 – WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {“1234567890″}; // 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 —————————————-

//body data function, provides data for the POST command in comma separated values (CSV)
//currently POSTs one value but more can be added by separating with commas (no spaces)
//Your program will not want to use the hardcoded values below, rather it would read the
//sensor(s) and build the data string shown below.
void feedData()
{
ftoa(buf1, aB, 2);
ftoa(buf2, cD, 2);
ftoa(buf3, eF, 2);
ftoa(buf4, gH, 2);
sprintf(buf5,”%s,%s,%s,%s”,buf1,buf2,buf3,buf4);
WiServer.print(buf5);
}
//__________________________________________________________________
void tempRead()
{
sensors.requestTemperatures(); //Get temperature of all sensors
delay(700);
aB=(sensors.getTempC(tempa));
cD=(sensors.getTempC(tempb));
eF=(sensors.getTempC(tempc));
gH=(sensors.getTempC(tempd));
}
//__________________________________________________________________
// IP Address for Pachube.com
uint8 ip[] = {64,94,18,122};
char hostName[] = “www.cosm.com\nX-PachubeApiKey: gWtWaEag5ytGWwKFsW7KxPyOp6qSAKwweGZhS1lCeUVSWT0g\nConnection: close”;
char url[] = “/api/feeds/100816.csv?_method=put”;

// A request that POSTS data to Pachube
POSTrequest postPachube(ip, 80, hostName, url, feedData);
void setup(void)
{
aB=0.0f;
cD=0.0f;
eF=0.0f;
gH=0.0f;
// Initialize WiServer (we’ll pass NULL for the page serving function since we don’t need to serve web pages)
WiServer.init(NULL);
postPachube.submit();
WiServer.server_task();
}
// 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)
{
postPachube.submit();
// Get/Push another update 30 seconds from now
updateTime += 30000;
// cycle();
tempRead();
}
// Run WiServer
WiServer.server_task();
delay(10);
}
//________________________________________________________________________
//Convert double to char (due to currently sprintf in Arduino fails to do so)
char *ftoa(char *a, double f, int precision)
{
long p[] =
{0,10,100,1000,10000,100000,1000000,10000000,100000000};
char *ret = a;
long heiltal = (long)f;
itoa(heiltal, a, 10);
while (*a != ‘\0’) a++;
*a++ = ‘.’;
long desimal = abs((long)((f – heiltal) * p[precision]));
itoa(desimal, a, 10);
return ret;
}
//________________________________________________________________________

Leave a Comment more...

Arduino WiShield WiServer Cosm upload (Put, Push) Sketch

by on Jan.28, 2013, under Arduino, Arduino ATmega328, Electronic Projects, WiShield

Arduino 328 with WiShield V1.0 to Cosm (Pachube)

In this sketch I have succeeded on having the unit push data to the Cosm.com site. Which is pretty cool if you want to see your data without building a web page on your WiServer.

Again this is a more of a reminder for me of the sketch and a working sketch for others to start from.

After much reading many posts and blogs I was able to get this little gem of code working. I wanted to see numbers changing on the site so I setup the unit with four variables that will change at different rates to show activity on the graph that comes up in the Cosm.com site.

Hope this helps one to move forward on using the Arduino and WiShield.

WiServer_Cosm_Basic_Skectch

The Sketch:

/*electronicramblings.com
* A sketch that uses WiServer to PUT (via POST) to Cosm
* Works with my WiShield ver 1.0 and Arduino 328.
* Very happy on its ability to push data.
* Cosm is setup for 4 variables.
* Have setup four variables that will increase or decrease depending on the math
* Did this to show a fast four graphs on Cosm.
* Good start to seeing how Cosm works.
* Sends out data every 30 seconds
* Jan 28, 2013
*/

#include <WiServer.h>

#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

//Variables
int aB;
int cD;
int eF;
int gH;

// Wireless configuration parameters
unsigned char local_ip[] = {192,168,0,151}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,0,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 = {“dlink”}; // max 32 bytes

unsigned char security_type = 3; // 0 – open; 1 – WEP; 2 – WPA; 3 – WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {“1234567890”}; // 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++));
}
}

//body data function, provides data for the POST command in comma separated values (CSV)
//currently POSTs one value but more can be added by separating with commas (no spaces)
//Your program will not want to use the hardcoded values below, rather it would read the
//sensor(s) and build the data string shown below.
void feedData()
{
//e.g. a single value
//WiServer.print(“21”);
//e.g. two values
//WiServer.print(“10,20,30,40″);
char buf[16];
sprintf(buf,”%d,%d,%d,%d”, aB, cD, eF, gH);
WiServer.print(buf);
}

void cycle()
{
aB=(aB+8);
cD=(cD+5);
eF=(eF++);
gH=(gH-5);
if (aB>=200)
{
aB=1;
}
if (cD>=200)
{
cD=1;}
if (eF>=200)
{
eF=1;
}
if (gH<=5)
{
gH=200;
}
Serial.print(“”);
Serial.print(“AB: “);
Serial.println(aB);
Serial.print(“CD: “);
Serial.println(cD);
Serial.print(“EF: “);
Serial.println(eF);
Serial.print(“GH: “);
Serial.println(gH);
}

// IP Address for Pachube.com
uint8 ip[] = {64,94,18,122};
char hostName[] = “www.cosm.com\nX-PachubeApiKey: }YOURAPICODE]\nConnection: close”;
char url[] = “/api/feeds/9999.csv?_method=put”;

// A request that POSTS data to Pachube
POSTrequest postPachube(ip, 80, hostName, url, feedData);
void setup() {
aB=1;
cD=15;
eF=25;
gH=150;
// Initialize WiServer (we’ll pass NULL for the page serving function since we don’t need to serve web pages)
WiServer.init(NULL);

// Enable Serial output and ask WiServer to generate log messages (optional)
Serial.begin(9600);
WiServer.enableVerboseMode(true);

// Have the printData function called when data is returned by the server
postPachube.setReturnFunc(printData);
}
// 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)
{
postPachube.submit();
// Get another update 30 seconds from now
updateTime += 30000;
Serial.print(millis());
cycle();
}

// Run WiServer
WiServer.server_task();
delay(10);
}

1 Comment more...

Arduino WiShield WiServer DS18S20 Alarm Control Back Ground Routine

by on Jan.27, 2013, under Arduino, Arduino ATmega328, Electronic Projects, WiShield

 

Well here we go again:
Arduino with a Async Labs WiServer 1.0 WiShield and two DS18S20 Dallas Temperature Senors and control …. count them…. 5 LEDs.

Again this is a more of a reminder for me of the sketch and a working sketch for others to start from.

Good Stuff  to report!!!!

Now the system can server a simple web page, read temperature from two 1-wire sensors (Dallas one wire DS18x20 Sensors), control three LEDs, and best part is it will control two LEDs (outputs) off the temperature in a background routine.

Now the sketch is ready to something useful. Don’t know what, but something.

 

Pic of the Web Page:

 

Jan 27 2013 003

 

Jan 27 2013 004

 

Till next time, thanks for your time.

 

 

The Sketch:(21,288 or 30,720 bytes)

Wiserver_Multi_LED_Jan2013_WAP_V3Alarm

/*

*** WiServer using WiShield***
elelctronicramblings.com
I work with the sketch that kim messed with for the Web page LED control.
Added in my DS18x20 code and added in Alarms for temperature.
Add in Routine to do alarm without a web page call.
Jan 27,2013
***
Was compiled on Beta 1.0.1
Latest AysncLab WiServer Library for Jan 2013
Latest Dallas one-wire Library for Jan 2013
***
Pins used
1,3 for alarm LEDS
4,5,6 for control LEDS
7 for Onewire(DS18S20)
13(SCK),12(SD0),11(SDI),10(SS_N),9(LED WIFI),8(INTX),2(who knows) for WiShield
***
It works as a 3 LED control and Read Temperture from 2 DS18S20 senosors.
Alarms with LED control for the alarm for both temperatures.
Set able Alarm levels for each alarm from the web page.
Was well as give the up time of the Arduino system.
*************************
IMPORTANT
It can get temperature with a web page refresh or embedded link in the page has been used.
Temperature updates for alarms every xx seconds.
Alarms activate/deactivate when the temperature has been read.
*************************
All fits just on a iphone 3S screen.
***
Router needs to have this setup:
WAP needs to be TPIK and PSK
WAP2 needs to be AES and PSK
***
*/
#include <WiServer.h>
#include <string.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

#define alarmPin2 1 //not a good one to use(specially if you put a relay there to control something)…but ran out of pins
#define alarmPin3 3
#define ledPin1 4
#define ledPin2 5
#define ledPin3 6
#define ONE_WIRE_BUS 7
#define TEMPERATURE_PRECISION 12

int tempAlarm =25;
int tempAlarma =25;
long previousMillis = 0; // will store last time Temperature and Alarm routine was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 5000; // interval at which to get temperature and run Alarm routine(milliseconds)

//Device is a DS18S20 : 10-EC-A7-48-00-08-00-47
DeviceAddress tempa={0X10, 0XEC, 0XA7, 0X48, 0X00, 0X08, 0X00, 0X47}; //DS18S20 temperature senor MAC address
//Device is a DS18S20 : 10-22-E1-48-00-08-00-BE
DeviceAddress tempb={0X10, 0X22, 0XE1, 0X48, 0X00, 0X08, 0X00, 0XBE}; //DS18S20 temperature senor MAC address

OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
//________________________________________________________________________
// Wireless configuration parameters —————————————-
unsigned char local_ip[] = {192,168,0,151}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,0,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 = {“dlink”}; // 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 = {“1234567890”}; // 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 —————————————-

boolean states[3]; //holds led states
char stateCounter; //used as a temporary variable
char tmpStrCat[64]; //used in processing the web page
char stateBuff[4]; //used in text processing around boolToString()
char numAsCharBuff[2];
char ledChange;
//__________________________________________________________________
void tempRead()
{
sensors.requestTemperatures(); //Get temperature of all sensors
}
//__________________________________________________________________
void alarmLoop()
{
if ((sensors.getTempC(tempa))>=(tempAlarm)) // easily changed to a less then value, say for turning on a heater
{
digitalWrite(alarmPin2, HIGH);
}
else
{
digitalWrite(alarmPin2, LOW);
}

if ((sensors.getTempC(tempb))>=(tempAlarma))
{
digitalWrite(alarmPin3, HIGH);
}
else
{
digitalWrite(alarmPin3, LOW);
}
}
//__________________________________________________________________
void boolToString (boolean test, char returnBuffer[4])
{
returnBuffer[0] = ‘\0’;
if (test)
{
strcat(returnBuffer, “On”);
}
else
{
strcat(returnBuffer, “Off”);
}
}
//__________________________________________________________________
void writeStates()
{
//set led states
digitalWrite(ledPin1, states[0]);
digitalWrite(ledPin2, states[1]);
digitalWrite(ledPin3, states[2]);
}
//__________________________________________________________________
// This is our page serving function that generates web pages
boolean sendPage(char* URL) {
writeStates();
//check whether we need to change the led state
if (URL[1] == ‘?’ && URL[2] == ‘L’ && URL[3] == ‘E’ && URL[4] == ‘D’) //url has a leading /
{
ledChange = (int)(URL[5] – 48); //get the led to change.

for (stateCounter = 0 ; stateCounter < 3; stateCounter++)
{
if (ledChange == stateCounter)
{
states[stateCounter] = !states[stateCounter];

}
}

//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}

;
//Alarm set point 0
if (URL[1] == ‘A’) //add 1 to the alarm set point
{
tempAlarm = tempAlarm++;
//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}

if (URL[1] == ‘B’) //minus 1 to the alarm set point
{ tempAlarm = tempAlarm–;
//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}
//Alarm setpoint 1
if (URL[1] == ‘C’) //add 1 to the alarm set point
{
tempAlarma = tempAlarma++;
//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}

if (URL[1] == ‘D’) //minus 1 to the alarm set point
{ tempAlarma = tempAlarma–;
//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}

if (strcmp(URL, “/”) == false) //why is this not true, just refresh the page
{
WiServer.print(“<html><body><meta name=\”viewport\” content=\”width=device-width, user-scalable=no\” />”);
WiServer.print(“<b><center>Arduino WiShield Web Server</center></b><hr/>”);
WiServer.print(“<b><center>LED Control<center>\n<center></b>”);
for (stateCounter = 0; stateCounter < 3; stateCounter++) //for each led
{
numAsCharBuff[0] = (char)(stateCounter + 49); //as this is displayed use 1 – 3 rather than 0 – 2
numAsCharBuff[1] = ‘\0’; //strcat expects a string (array of chars) rather than a single character.
//This string is a character plus string terminator.

tmpStrCat[0] = ‘\0’; //initialise string
strcat(tmpStrCat, “<a href=?LED”); //start the string
tmpStrCat[12] = (char)(stateCounter + 48); //add the led number
tmpStrCat[13] = ‘\0’; //terminate the string properly for later.

strcat(tmpStrCat, “>Led “);
strcat(tmpStrCat, numAsCharBuff);
strcat(tmpStrCat, “: “);

boolToString(states[stateCounter], stateBuff);
strcat(tmpStrCat, stateBuff);
strcat(tmpStrCat, “</a>”); //we now have something in the range of <a href=?LED0>Led 0: Off</a>
WiServer.print(” “);
WiServer.print(tmpStrCat);
}
sensors.requestTemperatures(); //Get temperature of all sensors
WiServer.print(“<BR><hr/>”);
WiServer.print(“Arduino has been running: “);
WiServer.printTime(millis()); //prints millis timer in hours:minutes:seconds format
WiServer.print(“<hr/>”);
WiServer.print(“<b>Temperature</b>”);
WiServer.print(“<BR>”);
WiServer.print(“Sensor 0 (Deg C): “);
WiServer.print(sensors.getTempC(tempa)); //print temperature from DS18x20 sensor
WiServer.print(“<BR>”);
WiServer.print(“Alarm Set Point: “);
WiServer.print(tempAlarm);
WiServer.print(“<button><a href=\”/A\”> UP </a></button>”);
WiServer.print(“<button><a href=\”/B\”>DOWN</a></button>”);
WiServer.print(“<BR>”);
WiServer.print(“Sensor 1 (Deg C): “);
WiServer.print(sensors.getTempC(tempb));//print temperature from DS18x20 sensor
WiServer.print(“<BR>”);
WiServer.print(“Alarm Set Point: “);
WiServer.print(tempAlarma);
WiServer.print(“<button><a href=\”/C\”> UP </a></button>”);
WiServer.print(“<button><a href=\”/D\”>DOWN</a></button>”);
WiServer.print(“<BR><hr/>”);
WiServer.print(“<b>Alarms</b>”);
WiServer.print(“<BR>”);
if ((sensors.getTempC(tempa))>=(tempAlarm)) // easily changed to a less then value, say for turning on a heater
{
WiServer.print(“****Sensor 0 HIGH TEMPERATURE****”);
digitalWrite(alarmPin2, HIGH);
}
else
{
digitalWrite(alarmPin2, LOW);
WiServer.print(“Sensor 0 None”);
}

if ((sensors.getTempC(tempb))>=(tempAlarma))
{
WiServer.print(“<BR>”);
WiServer.print(“****Sensor 1 HIGH TEMPERATURE****”);
digitalWrite(alarmPin3, HIGH);
}
else
{
digitalWrite(alarmPin3, LOW);
WiServer.print(“<BR>”);
WiServer.print(“Sensor 1 None”);
}

WiServer.print(“<hr/>”);
WiServer.print(“</body></html>”);
return true;
}
}
//__________________________________________________________________
void setup() {
// Initialize WiServer and have it use the sendMyPage function to serve pages
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(alarmPin2, OUTPUT);
pinMode(alarmPin3, OUTPUT);

WiServer.init(sendPage);
states[0] = false;
states[1] = false;
states[2] = false;
sensors.setResolution(tempa, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
sensors.setResolution(tempb, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
}
//__________________________________________________________________
void loop()
{
// Run WiServer
WiServer.server_task();
// here is where you’d put code that needs to be running all the time.
// check to see if it’s time to get temperature and run alarm routine; that is, if the
// difference between the current time and last time you got temperature and run the alarm routine
// is bigger than the interval at which you want to
// get temperature and alarm routine.
unsigned long currentMillis = millis();
if(currentMillis – previousMillis > interval)
{
// save the last time you got the temperature and alarm routine.
previousMillis = currentMillis;
tempRead();
alarmLoop();
}
}
//__________________________________________________________________
//That all Folks!!!!

 

Leave a Comment more...

Arduino WiShield WiServer DS18S20 Temperature Alarms with LED control.

by on Jan.26, 2013, under Arduino, Arduino ATmega328, Electronic Projects, WiShield

Well here we go again:

Arduino with a Async Labs WiServer 1.0 Shield and two DS18S20 Dallas Temperature Senors and count them….Control 5 LEDS.

Again this is a more of a reminder for me of the sketch and a working sketch for others to start from.

To start off this is a not a sketch to run your BBQ or home AC, but one to start with to get a idea of what can be done.

****Important****

This sketch does not run the alarm or temperature capture in the main loop, but only when a web page is refreshed or a embedded link is used. That will come in the next adventure!!!!

This is a short description of what this sketch does:

Severs up a web page that has three LED control links, Time the Arduino has been running, Temperature read from two DS18S20 Temperature sensors, Alarm setpoints(That are can be changed through control Links), and show if the set points have been reached.

Pretty simple, but took me sometime to get all of it working together.

Here is a picture of the web pages on a iphone 3s.

Jan 26 2013 004

A picture of my setup:

Jan 26 2013 003

Till next time, thanks for your time.

 

Below is the sketch: Wiserver_Multi_LED_Jan2013_WAP_V2Alarm

/*
elelctronicramblings.com
*** A simple sketch that uses WiServer to serve a web page !! that kim messed with.***
I work with the sketch that kim messed with and added in my DS18x20 code and added in Alarms for temperature.
Jan 26,2013
***
Was compiled on Beta 1.0.1
Latest AysncLab WiServer Library
Latest Dallas one-wire Library
***
Pins used
1,3 for alarm LEDS
4,5,6 for control LEDS
7 for Onewire(DS18S20)
13(SCK),12(SD0),11(SDI),10(SS_N),9(LED WIFI),8(INTX),2(who knows) for WiShield
***
It works as a 3 LED control and Read Temperture from 2 DS18S20 senosors.
Alarms with LED control for the alarm for both temperatures.
Set able Alarm levels for each alarm from the web page.
Was well as give the up time of the Arduino system.
*************************
IMPORTANT
Nothing happens without a web page refresh or embedded link in the page has been used.
Temperature only updates when the above condition is met.
Alarms will only activate/deactivate when the above condition is met.
*************************
All fits just on a iphone 3S screen.
***
Router needs to have this setup:
WAP needs to be TPIK and PSK
WAP2 needs to be AES and PSK
***
*/
#include <WiServer.h>
#include <string.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

#define alarmPin2 1 //not a good one to use(specially if you put a relay there to control something)…but ran out of pins
#define alarmPin3 3
#define ledPin1 4
#define ledPin2 5
#define ledPin3 6
#define ONE_WIRE_BUS 7
#define TEMPERATURE_PRECISION 12

int tempAlarm =25;
int tempAlarma =25;

 

//Device is a DS18S20 : 10-EC-A7-48-00-08-00-47
DeviceAddress tempa={0X10, 0XEC, 0XA7, 0X48, 0X00, 0X08, 0X00, 0X47}; //DS18S20 temperature senor MAC address
//Device is a DS18S20 : 10-22-E1-48-00-08-00-BE
DeviceAddress tempb={0X10, 0X22, 0XE1, 0X48, 0X00, 0X08, 0X00, 0XBE}; //DS18S20 temperature senor MAC address

OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
//________________________________________________________________________

// Wireless configuration parameters —————————————-
unsigned char local_ip[] = {192,168,0,151}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,0,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 = {“dlink”}; // 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 = {“1234567890”}; // 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 —————————————-

boolean states[3]; //holds led states
char stateCounter; //used as a temporary variable
char tmpStrCat[64]; //used in processing the web page
char stateBuff[4]; //used in text processing around boolToString()
char numAsCharBuff[2];
char ledChange;

void boolToString (boolean test, char returnBuffer[4])
{
returnBuffer[0] = ‘\0’;
if (test)
{
strcat(returnBuffer, “On”);
}
else
{
strcat(returnBuffer, “Off”);
}
}

void writeStates()
{
//set led states
digitalWrite(ledPin1, states[0]);
digitalWrite(ledPin2, states[1]);
digitalWrite(ledPin3, states[2]);
}

// This is our page serving function that generates web pages
boolean sendPage(char* URL) {

writeStates();

//check whether we need to change the led state
if (URL[1] == ‘?’ && URL[2] == ‘L’ && URL[3] == ‘E’ && URL[4] == ‘D’) //url has a leading /
{
ledChange = (int)(URL[5] – 48); //get the led to change.

for (stateCounter = 0 ; stateCounter < 3; stateCounter++)
{
if (ledChange == stateCounter)
{
states[stateCounter] = !states[stateCounter];

}
}

//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}

;
//Alarm set point 0
if (URL[1] == ‘A’) //add 1 to the alarm set point
{
tempAlarm = tempAlarm++;
//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}

if (URL[1] == ‘B’) //minus 1 to the alarm set point
{ tempAlarm = tempAlarm–;
//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}
//Alarm setpoint 1
if (URL[1] == ‘C’) //add 1 to the alarm set point
{
tempAlarma = tempAlarma++;
//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}

if (URL[1] == ‘D’) //minus 1 to the alarm set point
{ tempAlarma = tempAlarma–;
//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}

if (strcmp(URL, “/”) == false) //why is this not true, just refresh the page
{
WiServer.print(“<html><body><meta name=\”viewport\” content=\”width=device-width, user-scalable=no\” />”);
WiServer.print(“<b><center>Arduino WiShield Web Server</center></b><hr/>”);
WiServer.print(“<b><center>LED Control<center>\n<center></b>”);
for (stateCounter = 0; stateCounter < 3; stateCounter++) //for each led
{
numAsCharBuff[0] = (char)(stateCounter + 49); //as this is displayed use 1 – 3 rather than 0 – 2
numAsCharBuff[1] = ‘\0’; //strcat expects a string (array of chars) rather than a single character.
//This string is a character plus string terminator.

tmpStrCat[0] = ‘\0’; //initialise string
strcat(tmpStrCat, “<a href=?LED”); //start the string
tmpStrCat[12] = (char)(stateCounter + 48); //add the led number
tmpStrCat[13] = ‘\0’; //terminate the string properly for later.

strcat(tmpStrCat, “>Led “);
strcat(tmpStrCat, numAsCharBuff);
strcat(tmpStrCat, “: “);

boolToString(states[stateCounter], stateBuff);
strcat(tmpStrCat, stateBuff);
strcat(tmpStrCat, “</a>”); //we now have something in the range of <a href=?LED0>Led 0: Off</a>
WiServer.print(” “);
WiServer.print(tmpStrCat);
}
sensors.requestTemperatures(); //Get temperature of all sensors
WiServer.print(“<BR><hr/>”);
WiServer.print(“Arduino has been running: “);
WiServer.printTime(millis()); //prints millis timer in hours:minutes:seconds format
WiServer.print(“<hr/>”);
WiServer.print(“<b>Temperature</b>”);
WiServer.print(“<BR>”);
WiServer.print(“Sensor 0 (Deg C): “);
WiServer.print(sensors.getTempC(tempa)); //print temperature from DS18x20 sensor
WiServer.print(“<BR>”);
WiServer.print(“Alarm Set Point: “);
WiServer.print(tempAlarm);
WiServer.print(“<button><a href=\”/A\”>+++</a></button>”);
WiServer.print(“<button><a href=\”/B\”>—</a></button>”);
WiServer.print(“<BR>”);
WiServer.print(“Sensor 1 (Deg C): “);
WiServer.print(sensors.getTempC(tempb));//print temperature from DS18x20 sensor
WiServer.print(“<BR>”);
WiServer.print(“Alarm Set Point: “);
WiServer.print(tempAlarma);
WiServer.print(“<button><a href=\”/C\”>+++</a></button>”);
WiServer.print(“<button><a href=\”/D\”>—</a></button>”);
WiServer.print(“<BR><hr/>”);
WiServer.print(“<b>Alarms</b>”);
WiServer.print(“<BR>”);
if ((sensors.getTempC(tempa))>=(tempAlarm)) // easily changed to a less then value, say for turning on a heater
{
WiServer.print(“****Sensor 0 HIGH TEMPERATURE****”);
digitalWrite(alarmPin2, HIGH);
}
else
{
digitalWrite(alarmPin2, LOW);
// WiServer.print(“<BR>”);
WiServer.print(“Sensor 0 None”);
}

if ((sensors.getTempC(tempb))>=(tempAlarma))
{
WiServer.print(“<BR>”);
WiServer.print(“****Sensor 1 HIGH TEMPERATURE****”);
digitalWrite(alarmPin3, HIGH);
}
else
{
digitalWrite(alarmPin3, LOW);
WiServer.print(“<BR>”);
WiServer.print(“Sensor 1 None”);
}

WiServer.print(“<hr/>”);
WiServer.print(“</body></html>”);
return true;
}
}

void setup() {
// Initialize WiServer and have it use the sendMyPage function to serve pages
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(alarmPin2, OUTPUT);
pinMode(alarmPin3, OUTPUT);

WiServer.init(sendPage);
states[0] = false;
states[1] = false;
states[2] = false;
sensors.setResolution(tempa, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
sensors.setResolution(tempb, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
}

void loop(){
// Run WiServer
WiServer.server_task();

delay(10);
}

Leave a Comment more...

Arduino WiServer with Multiple DS18S20 Temperature Sensors

by on Jan.07, 2013, under Arduino, Arduino ATmega328, Electronic Projects, WiShield

Arduino with a Async Labs WiServer 1.0 Shield and four DS18S20 Dallas Temperature Senors.

Again this is a more of a reminder for me of the sketch and a working sketch for others to start from.

As I played with this idea, did some searching and found a sketch “that kim messed with”.  It had for me the ultimate LED control, it worked very good. Then added in my DS18S20 temperature sensor sketch and BAM…. all worked and works dam good.

Found the sketch very stable. In fact it ran for almost a week (518,654 seconds) before I got back to it and start working on the SD card logging and file server ideas.

This is what the web page looks like on a iphone/ipod:

Jan 06 2013

This sketch will poll the DS18S20 every time you request a web page, either by refreshing the page or changing one of the LED states.

The running time is good way of know how long the Arduino has been running.  I have not had a bad responses from the DS18S20 so far, which is pretty good for a one-wire devices.

It takes about 4 seconds for the web page to refresh, this is  do to the time it takes to read all four of the DS18S20 sensors.

Till next time, thanks for your time.

 

Sketch:

/*
elelctronicramblings.com
*** A simple sketch that uses WiServer to serve a web page !! that kim messed with.***
I work with the sketch that kim messed with and added in my DS18x20 code. Dam it works good.
Jan 2013
***
The code is stable.
Was compiled on Beta 1.0.1
Latest AysncLab WiServer Library
Latest Dallas one-wire Library
***
It works as a 3 LED control and Read Temperture from 4 DS18S20 senosors.
Was well as give the up time of the Arduino system.
***
All fits just on a iphone/ipod screen.
***

*/
#include <WiServer.h>
#include <string.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

#define ledPin1 5
#define ledPin2 6
#define ledPin3 3
#define ONE_WIRE_BUS 7
#define TEMPERATURE_PRECISION 12

//Device is a DS18S20 : 10-EC-A7-48-00-08-00-47
DeviceAddress tempa={0X10, 0XEC, 0XA7, 0X48, 0X00, 0X08, 0X00, 0X47}; //DS18S20 temperature senor MAC address
//Device is a DS18S20 : 10-22-E1-48-00-08-00-BE
DeviceAddress tempb={0X10, 0X22, 0XE1, 0X48, 0X00, 0X08, 0X00, 0XBE}; //DS18S20 temperature senor MAC address
//Device is a DS18S20 : 10-21-D8-48-00-08-00-90
DeviceAddress tempc={0X10, 0X21, 0XD8, 0X48, 0X00, 0X08, 0X00, 0X90}; //DS18S20 temperature senor MAC address
//Device is a DS18S20 : 10-7F-E2-48-00-08-00-94
DeviceAddress tempd={0X10, 0X7F, 0XE2, 0X48, 0X00, 0X08, 0X00, 0X94}; //DS18S20 temperature senor MAC address

OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
//________________________________________________________________________

// Wireless configuration parameters —————————————-
unsigned char local_ip[] = {192,168,0,151}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,0,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 = {“dlink”}; // max 32 bytes

unsigned char security_type = 1; // 0 – open; 1 – WEP; 2 – WPA; 3 – WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {“123456780”}; // 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 —————————————-

boolean states[3]; //holds led states
char stateCounter; //used as a temporary variable
char tmpStrCat[64]; //used in processing the web page
char stateBuff[4]; //used in text processing around boolToString()
char numAsCharBuff[2];
char ledChange;

void boolToString (boolean test, char returnBuffer[4])
{
returnBuffer[0] = ‘\0’;
if (test)
{
strcat(returnBuffer, “On”);
}
else
{
strcat(returnBuffer, “Off”);
}
}
/*
void printStates()
{
for (stateCounter = 0 ; stateCounter < 3; stateCounter++)
{
boolToString(states[stateCounter], stateBuff);

Serial.print(“State of “);
Serial.print(stateCounter);
Serial.print(“: “);
Serial.println(stateBuff);
}
}
*/
void writeStates()
{
//set led states
digitalWrite(ledPin1, states[0]);
digitalWrite(ledPin2, states[1]);
digitalWrite(ledPin3, states[2]);
}

// This is our page serving function that generates web pages
boolean sendPage(char* URL) {

// Serial.println(“Page printing begun”);

// printStates();
writeStates();

//check whether we need to change the led state
if (URL[1] == ‘?’ && URL[2] == ‘L’ && URL[3] == ‘E’ && URL[4] == ‘D’) //url has a leading /
{
ledChange = (int)(URL[5] – 48); //get the led to change.

for (stateCounter = 0 ; stateCounter < 3; stateCounter++)
{
if (ledChange == stateCounter)
{
states[stateCounter] = !states[stateCounter];
// Serial.print(“Have changed “);
//Serial.println(ledChange);
}
}

//after having change state, return the user to the index page.
WiServer.print(“<HTML><HEAD><meta http-equiv=’REFRESH’ content=’0;url=/’></HEAD></HTML>”);
return true;
}

if (strcmp(URL, “/”) == false) //why is this not true?
{

WiServer.print(“<html><body><meta name=\”viewport\” content=\”width=device-width, user-scalable=no\” />”);
WiServer.print(“<b><center>Arduino Web Server<center>\n<center><hr/></b>”);
WiServer.print(“<b><center>Please select the led state:<center>\n<center></b>”);
for (stateCounter = 0; stateCounter < 3; stateCounter++) //for each led
{
numAsCharBuff[0] = (char)(stateCounter + 49); //as this is displayed use 1 – 3 rather than 0 – 2
numAsCharBuff[1] = ‘\0’; //strcat expects a string (array of chars) rather than a single character.
//This string is a character plus string terminator.

tmpStrCat[0] = ‘\0’; //initialise string
strcat(tmpStrCat, “<a href=?LED”); //start the string
tmpStrCat[12] = (char)(stateCounter + 48); //add the led number
tmpStrCat[13] = ‘\0’; //terminate the string properly for later.

strcat(tmpStrCat, “>Led “);
strcat(tmpStrCat, numAsCharBuff);
strcat(tmpStrCat, “: “);

boolToString(states[stateCounter], stateBuff);
strcat(tmpStrCat, stateBuff);
strcat(tmpStrCat, “</a>”); //we now have something in the range of <a href=?LED0>Led 0: Off</a>
WiServer.print(“<hr/>”);
WiServer.print(tmpStrCat);
sensors.requestTemperatures(); //Get temperature of all sensors
}
WiServer.print(“<BR><hr/>”);
WiServer.print(“Arduino has been running: “);
WiServer.print((millis()/1000));
WiServer.print(” seconds<br>”);
WiServer.print(“<hr/>”);
WiServer.print(“Sensors”);
WiServer.print(“<BR>”);
WiServer.print(“0(Deg C): “);
WiServer.print(sensors.getTempC(tempa));
WiServer.print(“<BR>”);
WiServer.print(“1(Deg C): “);
WiServer.print(sensors.getTempC(tempb));
WiServer.print(“<BR>”);
WiServer.print(“2(Deg C): “);
WiServer.print(sensors.getTempC(tempc));
WiServer.print(“<BR>”);
WiServer.print(“3(Deg C): “);
WiServer.print(sensors.getTempC(tempd));
WiServer.print(“<BR><hr/>”);
WiServer.print(“</body></html>”);
return true;
}
}

void setup() {
// Initialize WiServer and have it use the sendMyPage function to serve pages
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);

//Serial.begin(9600);
WiServer.init(sendPage);
states[0] = false;
states[1] = false;
states[2] = false;
sensors.setResolution(tempa, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
sensors.setResolution(tempb, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
sensors.setResolution(tempc, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
sensors.setResolution(tempd, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
}

void loop(){
// Run WiServer
WiServer.server_task();

delay(10);
}

Leave a Comment more...

Arduino + DS18S20 + WiServer

by on Jan.03, 2013, under Arduino, Arduino ATmega328, Electronic Projects, WiShield

Arduino WiServer and DS18S20 Temperature Sensor adventure.
(This post is not meant to be a tell all on how to use the DS18S20 or Microchip Wifi module, but to reminder for me and maybe help others with a working sketch.)
This is my adventure of the the Microchip Wifi MRF24WB0A module and DS18S20 Temperature semiconductor.
I did not want to pay 85 dollars for a fancy Arduino shield. So I bought a Microchip MRF2424WB0A  from ebay for $9 and looked around for a way to hook up. I started with this web page: http://theiopage.blogspot.ca/2011/10/connecting-mrf24wb0ma-to-arduino.html
But decided l wanted a shield to work with. So found on the Aysnclab Wiki site the Eagle Cad files for the WiServer Shield V1.0.
http://asynclabs.com/wiki/index.php?title=WiShield_1.0
I checked out the schematic and Board PCB found on the above pages and sent them to OSH Park prototype batch PCB operation. http://oshpark.com/
For the size of the shield it cost me under $25 with shipping for three boards.(Just over $8 per board, dam good price in my world)
These boards came with silkscreen and solder mask for this price.

(yes they arrived with purple solder mask!)

It took just over two weeks for the boards to show up.

Went with the through hole design as I already had the parts in my archives to build up the shields and not have to buy or order anything to assemble shields.
So at this point it was going to cost me about $20 to make my first Wifi shield.

Now the fun part, programming the unit to work.
I started by upgrading the Arduino Interface to Beta….bad choice. Everything I originally found was written for sketches were written for the Arduino Alpha interface….but with much reading of forums and blogs I got it working!!!!!
Places I found my help with this simple projects programming:
http://asynclabs.com/forums/
http://arduino.cc/  (the site that if you search hard enough you will find the answer…
So many good responses to the questions asked about the arduino system. Thanks!!!!)
If all else fails search using google and Yahoo. Amazing how different sites come up between the two search engines.

So to use the sketch below, you will need:
Arduino Beta interface
Wiserver Library(https://github.com/asynclabs/WiShield), with some changes
Dallas 1-Wire Library(http://playground.arduino.cc/Learning/OneWire).
LED and a 330 ohm resistor on pin 5
DS18S20 attached using pin 7
These should be all you need to run the sketch below.

Added Note:
The changes needed in the WiServer Library are in the apps-conf file to hav this work:
What needs to change:
//Here we include the header file for the application(s) we use in our project.
comment out–>#define APP_WEBSERVER
//#define APP_WEBCLIENT
//#define APP_SOCKAPP
//#define APP_UDPAPP
uncomment–>//#define APP_WISERVER

Should end up with this:
//Here we include the header file for the application(s) we use in our project.
//#define APP_WEBSERVER
//#define APP_WEBCLIENT
//#define APP_SOCKAPP
//#define APP_UDPAPP
#define APP_WISERVER

Load the sketch below into the Arduino Interface and modify the wifi network information for your network.
I am not going to go into much detail as the Asynclab site has already done it.

Here as promised, the Sketch:

//******************************************************************************************
/*
electronicramblings.com
Written Jan 2013.
A simple sketch that will read a DS18S20 temperature sensor, serve up a web page that
will count each time the page is served, and also turn on/off a LED on pin 5
*/

#include <WiServer.h>

#define WIRELESS_MODE_INFRA    1
#define WIRELESS_MODE_ADHOC    2
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 7
#define TEMPERATURE_PRECISION 12

DeviceAddress tempa={0X10, 0X7F, 0XE2, 0X48, 0X00, 0X08, 0X00, 0X94}; //DS18S20 temperature senor MAC address
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.

int ledPin5 =  5;    // LED connected to digital pin 5
int Count = 1; //Setup of page counter

//________________________________________________________________________________
//For the temperature time delay loop
long previousMillis = 0;        // will store last time TEMP was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 10000;           // interval at which to blink (milliseconds)
//________________________________________________________________________________
// Wireless configuration parameters —————————————-
unsigned char local_ip[] = {192,168,0,151}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,0,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 = {“dlink”}; // max 32 bytes

unsigned char security_type = 1; // 0 – open; 1 – WEP; 2 – WPA; 3 – WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {“123456780”}; // 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 —————————————-

// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {

// Check if the requested URL match es “/”
if (strcmp(URL, “/on”) == 0) {
digitalWrite(ledPin5, HIGH);   // set the LED on
// 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(“<b>Simple webserver<BR></b>”);
WiServer.print(“<hr /><BR>”);
WiServer.print(“<button><a href=\”off\”>LED OFF  </a></button><BR>”);
WiServer.print(“<BR>”);
WiServer.print(“Web Page Served:  “);
WiServer.print(Count);
WiServer.print(”  Times<BR>”);
WiServer.print(“<hr /><BR>”);
Count=Count++; // Counter +1
WiServer.print(“Temperature(Deg C): “);
WiServer.print(sensors.getTempC(tempa));
WiServer.print(“</table></body></html>”);
// URL was recognized
return true;
}
if (strcmp(URL, “/off”) == 0) {
digitalWrite(ledPin5, 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(“<b>Simple webserver<BR></b>”);
WiServer.print(“<hr /><BR>”);
WiServer.print(“<button><a href=\”on\”>LED ON</a></button><BR>”);
WiServer.print(“<BR>”);
WiServer.print(“Web Page Served:  “);
WiServer.print(Count);
WiServer.print(”  Times<BR>”);
WiServer.print(“<hr /><BR>”);
Count=Count++; // Counter +1
WiServer.print(“Temperature(Deg C): “);
WiServer.print(sensors.getTempC(tempa));
WiServer.print(“</table></body></html>”);
// URL was recognized
return true;
}}

void setup() {

pinMode(ledPin5, OUTPUT); // Make pin a output
WiServer.init(sendMyPage);   // Initialize WiServer and have it use the sendMyPage function to serve pages
sensors.setResolution(tempa, TEMPERATURE_PRECISION); //Setup Dallas sensor resolution and address
}

void loop(){
//___________________________________________________________________________
// Here is where you’d put code that needs to be running all the time.
// Check to see if it’s time to get temperature; that is, if the
// Difference between the current time and last time you get the temperature
unsigned long currentMillis = millis(); // From Blink without delay statment

if(currentMillis – previousMillis > interval) {
WiServer.server_task();
// save the last time you get temperature
previousMillis = currentMillis;
//____________________________________________________________________________
sensors.requestTemperatures();    //Get temperature:
}
WiServer.server_task(); //Run wiserver and wait for a connection
}

//******************************************************************************************

What the web page looks like on a iphone:

The I am off to see now to make the unit read and display multiple DS18x20 sensors.
Also the next time I build one of these shields I will find the design with the SD card as well and modify it to have the RTC on it as well.(to make a fancy data logger)

Till Next time, thanks for your time.

4 Comments more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...