GOT THIS SORTED OUT....CANNOT REMOVE MYSELF....
MODERATOR PLEASE REMOVE...
THANKS...
LENGTHY BACKGROUND EXPLANATION
So I've progressed a bit in my networking efforts.
-
First I ran a BT example where I controlled a LED from my BT module HC-05. I guess I understand that BT signals are 'somehow' converted to serial data, which can be of course monitored in the Serial Monitor.
-
Then I moved onto trying to control a servo via BT and something went wrong, so Im going back to the LED example in order to move back into the servo scenario and do some troubleshooting.
-
Yesterday I started off on my Wifi testing. First I had no idea what module I was dealing with, I now know its a TinySine wifi shield which is to say, a WifiBee module from Roving Networks, which shows up as WiFly-EZX module in the dhcp clients table.
I managed to connect to it from the Serial Monitor and used $$$ to configure it. It pops up on my network and I ping it fine.
Now Im uploading a sketch to test its tcp/ip capabilities because Im interested in making the arduino post data to my web server. At first I got a little confused because I had downloaded the WiFlySerial library. Not sure what the difference was, maybe I just didn't dig deeper after failing to run any commands with its samples. So then I quickly ran into the WiFly library and now the WiFlyHQ library. I haven't looked under the hood into each but they might be quite similar. In any event, Im on WiFlyHQ.
I tried the sketch that used pins 8,9 and it fails every time. So I've figured it out I need to use pins 2,3.
Im running this code which works perfectly and downloads the entire website into the serial monitor, its crazy:
#include <WiFlyHQ.h>
#include <SoftwareSerial.h>
SoftwareSerial wifiSerial(2,3);
WiFly wifly;
String data;
const char mySSID[] = "myssid";
const char myPassword[] = "mykey"
const char site[] = "servers.com";
void terminal();
void setup()
{
char buf[32];
//hardcoded data to post
data = "";
data = "name=Santiago&age=6";
Serial.begin(9600);
Serial.println("Starting");
Serial.print("Free memory: ");
Serial.println(wifly.getFreeMemory(),DEC);
wifiSerial.begin(9600);
if (!wifly.begin(&wifiSerial, &Serial)) {
Serial.println("Failed to start wifly");
terminal();
}
/* Join wifi network if not already associated */
if (!wifly.isAssociated()) {
/* Setup the WiFly to connect to a wifi network */
Serial.println("Joining network");
wifly.setSSID(mySSID);
wifly.setPassphrase(myPassword);
wifly.enableDHCP();
if (wifly.join()) {
Serial.println("Joined wifi network");
} else {
Serial.println("Failed to join wifi network");
terminal();
}
} else {
Serial.println("Already joined network");
}
Serial.print("MAC: ");
Serial.println(wifly.getMAC(buf, sizeof(buf)));
Serial.print("IP: ");
Serial.println(wifly.getIP(buf, sizeof(buf)));
Serial.print("Netmask: ");
Serial.println(wifly.getNetmask(buf, sizeof(buf)));
Serial.print("Gateway: ");
Serial.println(wifly.getGateway(buf, sizeof(buf)));
wifly.setDeviceID("Wifly-WebClient");
Serial.print("DeviceID: ");
Serial.println(wifly.getDeviceID(buf, sizeof(buf)));
if (wifly.isConnected()) {
Serial.println("Old connection active. Closing");
wifly.close();
}
if (wifly.open(site, 80)) {
Serial.print("Connected to ");
Serial.println(site);
/* Send the request */
wifly.println("GET / HTTP/1.0");
wifly.println();
} else {
Serial.println("Failed to connect");
}
}
void loop()
{
if (wifly.available() > 0) {
char ch = wifly.read();
Serial.write(ch);
if (ch == '\n') {
/* add a carriage return */
Serial.write('\r');
}
}
if (Serial.available() > 0) {
wifly.write(Serial.read());
}
}
/* Connect the WiFly serial to the serial monitor. */
void terminal()
{
while (1) {
if (wifly.available() > 0) {
Serial.write(wifly.read());
}
if (Serial.available() > 0) {
wifly.write(Serial.read());
}
}
}
This works fine.
Im a little confused on how to proceed. Here I am setting my shield up as a client, which is requesting a web page. I will need to make a client request to post data as well.
- Why does my GET request fail when I change it to this:
At the moment Im referencing this:
where a Ethernet client is created and a get request sent:
client.println("GET /search?q=arduino HTTP/1.1");
So if I wanted to query a db with a GET from this server resource:
I would do this:
const char site[] = "santiapps.com";
wifly.println("GET /arduino/query.php HTTP/1.0");
but I get:
open santiapps.com/arduino 80
Failed to connect
Another option would be to make the shield a server and create a web page with some data to be visible at the shield's ip.
- This means I would have to configure my shield as a server, right? I can't find in the WiFlyHQ library code how to create a server object, any help would be appreciated.
Had to leave the primary domain as the host and tag the folder substructure to the GET request.
Please help