here is my code:
- Code: Select all
/*
* Socket App
*
* A simple socket application example using the WiShield 1.0
*/
#include <WiShield.h>
#include <MsTimer2.h>
#include <SHT1x.h>
//jonoxer SHT15 lib
//http://github.com/practicalarduino/SHT1x/
//-------------------------------------------------------------------------------------------------
//
// WiShield data
//
//-------------------------------------------------------------------------------------------------
//Wireless configuration defines ----------------------------------------
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
//Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,10}; // 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 = {"test temp"}; // max 32 bytes
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
prog_uchar wep_keys[] PROGMEM = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 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_ADHOC;
unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
//
//define(s), declaration(s) and global state data
//
//-------------------------------------------------------------------------------------------------
//#define DEBUGPRINT
//The Arduino pin numbers corresponding to the analog pins are 14 through 19.
//Arduino analog input 4 = I2C SDA (pin 18)
//Arduino analog input 5 = I2C SCL (pin 19)
#define PIN_DATA 10
#define PIN_SCLK 11
//SHT15 set up and comm class init
SHT1x sht1x(PIN_DATA, PIN_SCLK);
//timer interrupt flag
volatile boolean intTimer;
//global temp (F) and humidity data
float g_temperature;
float g_humidity;
//-------------------------------------------------------------------------------------------------
//
// ISR code/handler for MsTimer2 interrupt
//
//-------------------------------------------------------------------------------------------------
//MsTimer2 timer ISR
void timerISR() {
intTimer = true;
}
//-------------------------------------------------------------------------------------------------
//
// Arduino setup() code
//
//-------------------------------------------------------------------------------------------------
void setup()
{
#ifdef DEBUGPRINT
//setup output for debugging...
Serial.begin(57600);
#endif //DEBUGPRINT
//set up global state data
intTimer = false;
g_temperature = 0;
g_humidity = 0;
//init the WiShield
WiFi.init();
//setup the MSTimer2 timerISR
MsTimer2::set(60000, timerISR);
MsTimer2::start();
}
//-------------------------------------------------------------------------------------------------
//
// Arduino loop() code
//
//-------------------------------------------------------------------------------------------------
void loop()
{
if(true == intTimer) {
intTimer = false;
//fetch data from the SHT15 (currently only using degrees F)
g_temperature = sht1x.readTemperatureF();
//returns a % value
g_humidity = sht1x.readHumidity();
#ifdef DEBUGPRINT
Serial.print("Temperature: ");
Serial.println(g_temperature);
Serial.print("Humidity : ");
Serial.println(g_humidity);
#endif //DEBUGPRINT
}
WiFi.run();
}
