Jump to content


Photo

Using the Redback as a client


  • Please log in to reply
5 replies to this topic

#1 chain

chain

    Advanced Member

  • Members
  • PipPipPip
  • 756 posts

Posted 08 April 2014 - 01:24 AM

I'm interested in using my Redback WiFi device to upload some sensor information to a web server. To be more specific, I currently have a temperature sensor attached to one of the Redback's pins, and I want to post the data the sensor collects to a database located on a web server. As I'm not that familiar with HTML, I'm looking for a library-based solution based on GET/POST etc.

To give you some more information about my situation, I have viewed your tutorial video on youku and have the SimpleServer example you provided up and running. 

Can you give me some guidance on where I can get some more information on my project, or example code I can base it on? I've looked for documentation on the WiShield and WiServer libraries that your ZG2100WiFiShield library seems to be based on, but there doesn't seem to be much out there as WiShield is an older(?) library.

Thank you,



#2 chain

chain

    Advanced Member

  • Members
  • PipPipPip
  • 756 posts

Posted 15 April 2014 - 05:15 AM

Please refer to below sample code:

 

 

#include <WiServer.h>
 
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
#define AREF_VOLTAGE 5
const int tmpPin = A0;
int tmpReading = 0;
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,31,199}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,31,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 = {"Linksprite-02"}; // 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 = {"Linksprite123456"}; // 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 ----------------------------------------
float testTmp (void){
  tmpReading = analogRead (tmpPin);
  float voltage = tmpReading * AREF_VOLTAGE;
  voltage /= 1023;
  float tmpC = (voltage - 0.5) * 100;
  return tmpC;
}
 
// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {
  
    // Check if the requested URL matches "/"
    if (strcmp(URL, "/") == 0) {
        // Use WiServer's print and println functions to write out the page content
        float tmpC = testTmp ();
        WiServer.print("<html>");
//        WiServer.print("Hello World!");
        WiServer.print(tmpC);
        WiServer.print("</html>");
        
        // URL was recognized
        return true;
    }
    // URL not found
    return false;
}
 
 
void setup() {
  // 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);
}


#3 chain

chain

    Advanced Member

  • Members
  • PipPipPip
  • 756 posts

Posted 16 April 2014 - 12:54 AM

Thanks so much for the sample code! I've gotten it working without the sensor actually plugged in, but have one more problem I was hoping you could help me with. The connector I have for the sensor is loose in the Redback's connection pins (or should I say holes?) Could you tell me how I can use a temperature sensor with connection pins designed for the standard arduino uno on the Redback?



#4 chain

chain

    Advanced Member

  • Members
  • PipPipPip
  • 756 posts

Posted 16 April 2014 - 01:10 AM

You can solder Pin Header on your Redback, either you can use wires:

image010

 



#5 chain

chain

    Advanced Member

  • Members
  • PipPipPip
  • 756 posts

Posted 24 April 2014 - 12:42 AM

I'm trying to do some testing with my Redback using netcats. So far, netcats detects a connection attempt from my Redback, but says it is invalid because the MAC address of the device is unknown. Are there any simple functions in the ZG2100BasedWiFiShield library that would allow me to specify the MAC address of the Redback?



#6 chain

chain

    Advanced Member

  • Members
  • PipPipPip
  • 756 posts

Posted 24 April 2014 - 01:23 AM

You can find the MAC address on the label:

redback Mac





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users