How to use Arduino WiFi Bee to connect Cloudant

We are trying to connect the Arduino-based wifi bee (ATmega 328P) to the Cloudant database. The wifi bee uses the wiwhield library to connect to the network. We can use it to connect to cosm(xively) and post /get data. However, for cloudant, we are unable to do so and continue to get 503 Service unavailable requests.

I think the problem is that Wishield expects to specify an IP address, and Cloudant uses DNS. .I use wipeid to add a code snippet, the function is suitable for GET data from weather.com, but when we modify the variable of cloudant.com, it only gives me 503 requests.

Please find a different one Code:
Code snippet: GetDatafromCloudant.ino: We just changed the IP address/port details of the cloudant GET request.

/*
* A simple sketch that uses WiServer to get the hourly weather data from LAX and prints
* it via the Serial API
*/

#include
< br />#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

// Wireless configuration parameters ---------------------- ------------------
unsigned char local_ip[] = {192,168,1,2}; // 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 netw ork
const prog_char ssid[] PROGMEM = {"BSNL_AP"}; // 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 = {"bhutoriafamily"}; // 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++));
}
}< br />

// IP Address for www.weather.gov
//uint8 ip[] = {140,90,113,200};
uint8 ip[] = {50, 23,104,75};
// A request that gets the latest METAR weather data for LAX
GETrequest getWeather(ip, 5984, "http://alfatek.cloudant.com", "/wifi/_all_docs ");


void setup() {
// Initialize WiServer (we'll pass NULL for the page serving function since we don't need to serve web pages)
WiServer.init(N ULL);

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

// Have the processData function called when data is returned by the server
getWeather.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) {
getWeather.submit();
// Get another update one hour from now
updateTime += 1000 * 20 ;< br /> }

// Run WiServer
WiServer.server_task();

delay(10);
}

Code snippet: GetDatafromWeather.ino: This is very useful, we can extract LA weather data data from weather.com.

/*
* A simple sketch that uses WiServer to get the hourly weather data from LAX and prints
* it via the Serial API
*/

#include
< br />#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

// Wireless configuration parameters ---------------------- ------------------
unsigned char local_ip[] = {192,168,1,2}; // 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 = {"BSNL_AP"}; // 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 = {"bhutoriafamily"}; // 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++));
}
}


// IP Address for www.weather.gov
uint8 ip[] = {140,90,113,200};

// A request that gets the latest METAR weather data for LAX
GETrequest getWeather(ip, 80, "www. weather.gov", "/data/METAR/KLAX.1.txt");


void setup() {
// 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(57600);
WiServer.enableVerboseMode(true);

// Have the processData function called when data is returned by the server
getWeather. 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) {
getWeather.submit(); < br /> // Get another update one hour from now
updateTime += 1000 * 20 ;
}

// Run WiServer
WiServer.server_task();

delay(10);
}
You are right, Cloudant routes your request based on the provided headers. You can handle this by specifying the Host header as follows Question: Host: USERNAME.cloudant.com

The 503 status code you get from Cloudant means that the load balancer you log in does not know how to route your request because it does not have your account name.

You can connect to the IP (Bash terminal) like this: host USERNAME.cloudant.com

However, this is not a good idea.

Cloudant uses DNS The reason is that the IP can be changed in the whims of the service. In addition, failover to a different load balancing server and/or data center is handled by DNS (local failover within the data center is handled by the load balancer). Therefore, you Will not create a stable environment-Cloudant can and will change your IP, thereby terminating your setup.

Sorry, the best solution that sounds like it is to let DNS run in your environment.

[Source: I work in Cloudant.]

We are trying to connect the Arduino-based wifi bee (ATmega 328P) to the Cloudant database. wifi The bee uses the wiwhield library to connect to the network. We can use it to connect to cosm (xively) and post/get data. However, for cloudant, we cannot do this and continue to get 503 Service unavailable requests.

I think the problem is that Wishield expects to specify an IP address, and Cloudant uses DNS.. I use Wishield to add code snippets, the function works with GET data from weather.com, but when we modify the variables of cloudant.com , It only gave me a 503 request.

Please find a different code:
Code snippet: GetDatafromCloudant.ino: We just changed the IP address/port details of the cloudant GET request.

 /*
* A simple sketch that uses WiServer to get the hourly weather data from LAX and prints
* it via the Serial API
*/

#include < WiServer.h>

#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

// Wireless configuration parameters ------------- ---------------------------
unsigned char local_ip[] = {192,168,1,2}; // 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 = {"BSNL_AP"}; // 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 = {"bhutoriafamily"}; // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x 07, 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 packet s, and
// includes the HTTP header.
while (len--> 0) {
Serial.print(*(data++));
}
}


// IP Address for www.weather.gov
//uint8 ip[] = {140,90,113,200};
uint8 ip[] = { 50,23,104,75};
// A request that gets the latest METAR weather data for LAX
GETrequest getWeather(ip, 5984, "http://alfatek.cloudant.com", "/wifi /_all_docs");


void setup() {
// 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(57600);
WiServer.enableVerboseMode(true);

// Have the processData function called when data is returned by the server
getWeather.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) {
getWeather.submit();
// Get another update one hour from now
updateTime += 1000 * 20 ;
}

// Run WiServer
WiServer.server_task();
< br /> delay(10);
}

Code snippet: GetDatafromWeather.ino: This is very useful, we can extract LA weather data data from weather.com.

< p>

/*
* A simple sketch that uses WiServer to get the hourly weather data from LAX and prints
* it via the Serial API
*/

#include

#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

// Wireless configuration parameters ---- ------------------------------------
unsigned char local_ip[] = {192,168,1 ,2}; // 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 s sid[] PROGMEM = {"BSNL_AP"}; // 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 = {"bhutoriafamily"}; // 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< br /> };

// 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++));
}
}


// IP Address for www.weather.gov
uint8 ip[] = {140,90,113,200};

// A request that gets the latest METAR weather data for LAX
GETrequest getWeather(ip, 80, "www.weather.gov", "/data/METAR/KLAX.1.txt");


void setup() {
// 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(57600);
WiServer.enableVerboseMode(true);

// Have the processData function called when data is returned by the server
getWeather.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) {
getWeather .submit();
// Get another update one hour from now
updateTime += 1000 * 20 ;
}

// Run WiServer
WiServer.server_task();

delay(10);
}

You are right, Cloudant provides Header to route your request. You can handle this issue by specifying the Host header as follows: Host: USERNAME.cloudant.com

The 503 status code you get from Cloudant indicates that you are logged in The load balancer does not know how to route your request because it does not have your account name.

You can connect to the IP (Bash terminal) like this: host USERNAME.cloudant.com

However, this is not a good idea.

The reason Cloudant uses DNS is that the IP can be changed in the whims of the service. In addition, failover to a different load balancing server and/or data center by DNS Processing (local failover in the data center is handled by the load balancer). Therefore, You will not create a stable environment-Cloudant can and will change your IP, thereby terminating your settings.

Sorry, the best solution that sounds like it is to let DNS run in your environment .

[Source: I work at Cloudant.]

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4210 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.