wifly problems
eduardoa opened this issue · 6 comments
eduardoa commented
Can anyone provide an example with Wifly shield?
errordeveloper commented
@frasermac does it still require a patch or it actually works out-of-the box? You've had an example somewhere, IIRC?
frasermac commented
@eduardoa give this one a try - it's from a while back but might make a good start?
#include <SPI.h>
#include <WiFly.h>
#include <HttpClient.h>
#include <xively_arduino.h>
#define API_KEY "INSERT_API_KEY_HERE" // your Xively API key
#define FEED_ID INSER_FEED_ID_HERE // your Xively feed ID
char ssid[] = "MyWiFiAccessPointSSID";
char passphrase[] = "MyWiFiPassword";
unsigned long lastConnectionTime = 0; // last time we connected to Xively
const unsigned long connectionInterval = 3000; // delay between connecting to Xively in milliseconds
int sensorPin = 2;
char sensorId1[] = "Binary"; // Give a name to our datastream ID
char sensorId2[] = "Float"; // Give a name to our datastream ID
char sensorId3[] = "Int"; // Give a name to our datastream ID
String stringId("String");
XivelyDatastream datastreams[] = {
XivelyDatastream(sensorId1, strlen(sensorId1), DATASTREAM_INT),
XivelyDatastream(sensorId2, strlen(sensorId2), DATASTREAM_FLOAT),
XivelyDatastream(sensorId3, strlen(sensorId3), DATASTREAM_INT),
XivelyDatastream(stringId, DATASTREAM_STRING),
};
XivelyFeed feed(FEED_ID, datastreams, 4 /* number of datastreams */); // Wrap the datastream into a feed
WiFlyClient client;
XivelyClient xivelyclient(client);
void setup() {
Serial.begin(9600);
Serial.println("Starting sketch.");
randomSeed(analogRead(0));
WiFly.begin();
if (!WiFly.join(ssid, passphrase)) {
Serial.println("Association failed.");
while (1) {
// Hang on failure.
}
}
WiFly.setAntenna(1);
Serial.print("WiFly IP: ");
Serial.println(WiFly.ip());
}
void loop() {
//if (millis() - lastConnectionTime > connectionInterval) {
Serial.println();
sendData();
// getData(); // read the datastream back from Xively
lastConnectionTime = millis(); // update connection time so we wait before connecting again
//}
}
// send the supplied value to Xively, printing some debug information as we go
void sendData() {
int val1 = random(0,2);
Serial.println(val1);
datastreams[0].setInt(val1);
int val2 = random(20,50);
Serial.println(val2);
datastreams[1].setFloat(val2);
int val3 = random(20,50);
Serial.println(val3);
datastreams[2].setInt(val3);
// Pick a random number to send up in a string
String stringValue(random(100));
stringValue += " is random";
datastreams[3].setString(stringValue);
//Serial.println(datastreams[3].getString());
Serial.println("Uploading to Xively");
int timeStart = millis();
int ret = xivelyclient.put(feed, API_KEY);
int timeFinish = millis() - timeStart;
Serial.print("PUT time (ms): ");
Serial.println(timeFinish);
Serial.print("PUT return code: ");
Serial.println(ret);
Serial.println();
}
// get the value of the datastream from Xively, printing out the value we received
void getData() {
Serial.println("Reading data from Xively");
int timeStart = millis();
int ret = xivelyclient.get(feed, API_KEY);
int timeFinish = millis() - timeStart;
Serial.print("GET time (ms): ");
Serial.println(timeFinish);
Serial.print("GET return code: ");
Serial.println(ret);
}
errordeveloper commented
@eduardoa have that example worked for you?
eduardoa commented
No, I have multiple errors. The library I think it isn't the same ... I tried to adapt it without luck, so far I have not much time to spend.
eduardoa commented
Hi @frasermac
Can you tell me which library Wifly used? The Sparkfun not ... latest version say ...
errordeveloper commented
I am closing this issue as the WiFly shield is not officially supposed.