Connecting Two YellowJackets to Request Web Page Using Local Network —
Hardware:
- YJ Arduino board (YJ56) at ip=10.0.1.56
- Sensor Shield stacked with YJ56 for Vin power
- YJ Arduino board (YJ57) at ip=10.0.1.57
- Local network gateway 10.0.1.1
Software: WiClient YJ57 requests web page from WiServer YJ56.
- Load sketch SimpleServer_V3 (Ref: Part 4 of this series) into YJ56. Sketch uses “WiServer.init(sendMyPage);” to transmit web page content by Wifi.
- Load sketch SimpleWiClientReadWiServer_V3 into YJ57. Sketch uses GetRequest to Host: “10.0.1.56”, URL=“/“
- Result: WiServer web page is requested every 10 seconds by WiClient
- WiClient prints returned HTTP stream on Serial Monitor
/* SimpleWiClientReadWiServer_V3
*
* A simple sketch that uses MRF24 WiClient to read web page from MRF24 WiServer
*
* Compiled with WiShield_V3 library
*
* Uses apps-conf.h "#define APP_WISERVER"
*
* Connecting Two YellowJackets for Data Transfer
*
* Hardware:
* YJ Arduino board (YJ56) at ip=10.0.1.56
* YJ Arduino board (YJ57) at ip=10.0.1.57
* Local network gateway ip 10.0.1.1
*
* Example 1: WiClient YJ57 requests web page from WiServer YJ56.
* a) Load sketch SimpleWiServer_V3 into YJ56. Sketch uses
* “WiServer.init(sendMyPage);” to transmit web page content by Wifi.
* b) Load sketch SimpleWiClientReadWiServer_V3 into YJ57. Sketch uses
* GetRequest to Host: “10.0.1.56”, URL=“/“
* c) Result: WiServer web page is requested every 10 seconds by WiClient
*
*/
//#include <WiShield.h>
#include <WiServerIO.h>
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {10, 0, 1, 57}; // IP address of WiShield
unsigned char gateway_ip[] = {10, 0, 1, 1}; // router or gateway IP address
unsigned char subnet_mask[] = {255, 255, 255, 0}; // subnet mask for the local network
const char ssid[] PROGMEM = {"Network"}; // max 32 bytes
const char* myhost = "WiServer";
char* myhost_ip = "10.0.1.56";
unsigned char security_type = 3; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const char security_passphrase[] PROGMEM = {"Network_Passcode"}; // max 64 characters
// WEP 128-bit keys
// sample HEX keys
const uint8_t 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++));
}
Serial.println (" ."); // terminate messages with CR
}
uint8 server_ip[] = {10, 0, 1, 56}; // IP Address for WiServer YJ56
// A request that gets web page from server
GETrequest getWebPage(server_ip, 80, myhost_ip, "/"); // return Hello webpage
void setup() {
// Enable Serial output
Serial.begin(115200);
Serial.println (" ");
Serial.println (F("=== Initializing WiClient to display WiServer web page on Serial Monitor ==="));
// Initialize WiServer (we'll pass NULL for the page serving function since we don't need to serve web pages)
WiServer.init(NULL);
// Ask WiServer to generate log messages (optional)
WiServer.enableVerboseMode(true);
// Have the processData function called when data is returned by the server
getWebPage.setReturnFunc(printData);
Serial.println (" ");
Serial.println (F("=== WiClient is running... ==="));
Serial.println (F(">>> Request response on 10 second intervals... "));
Serial.println (" ");
}
// Time (in millis) when the data should be retrieved
unsigned long updateTime = 0;
unsigned long waitTime = 1000UL * 10UL; // * UL unsigned long number format used to avoid overflow
void loop() {
// Check if it's time to get an update
if (millis() >= updateTime) {
getWebPage.submit();
// Get another update 10 seconds from now
updateTime += waitTime;
}
// Run WiServer
WiServer.server_task();
delay(10);
}
Serial Monitor display output of web page request over wifi:
=== Initializing WiClient to display WiServer web page on Serial Monitor === === WiClient is running... === >>> Request response on 10 second intervals... Connected to 10.0.1.56 TX 61 bytes RX 0 bytes from 10.0.1.56 RX 83 bytes from 10.0.1.56 HTTP/1.0 200 OK <html>Hello from YellowJacket Wifi MRF24 SimpleServer_V3!</html> . Ended connection with 10.0.1.56 . Connected to 10.0.1.56 TX 61 bytes RX 0 bytes from 10.0.1.56 RX 83 bytes from 10.0.1.56 HTTP/1.0 200 OK <html>Hello from YellowJacket Wifi MRF24 SimpleServer_V3!</html> . Ended connection with 10.0.1.56
(Mar 4, 2016)
No comments:
Post a Comment