Hey Guys,,
I am currently make a project about send many sensor data to database in server. I send data via Wifi and I use Mega2560-ATMega1280 and RN-XV 171 as a wireless transmitter. And now, i get a problem to send data via GET method. This is my code.
// Library
#include <WiFlyHQ.h>
// variable
WiFly wifly;
unsigned long nextMillis;
unsigned long previousMillis = 0;
const unsigned int interval = 1000;
char mac[32]; // MacAddress
/* Change these to match your WiFi network */
const char mySSID[] = "XXXX";
const char myPassword[] = "XXXX";
const char site[] = "192.168.1.101"; // my server
void terminal();
void setup()
{
char buf[32];
Serial.begin(115200);
Serial.println(F("Starting"));
Serial.print(F("Free memory: "));
Serial.println(wifly.getFreeMemory(),DEC);
Serial1.begin(9600);
if (!wifly.begin(&Serial1, &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");
}
//terminal();
Serial.print("MAC: ");
Serial.println(wifly.getMAC(buf, sizeof(buf)));
wifly.getMAC(mac,sizeof(mac));
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();
}
}
void loop()
{
nextMillis = millis();
if (nextMillis - previousMillis > interval) {
// GET Method
if (wifly.open(site, 80)) {
Serial.print(F("Connected to "));
Serial.println(site);
//Send the request and this is the problem
wifly.print("GET /a.php?");
wifly.print(F("i="));
wifly.print(mac);
wifly.print(F("&x=1&y=2&z=345&B=56&l=6.12345&j=107.12345"));
//the maximum URL can be send is only 64 starts from "GET until 107.12345"
previousMillis = nextMillis;
} else {
Serial.println("Failed to connect");
}
}
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());
}
}
}
The code actually works and it can send data to database. But the problem is the maximum URL size that I can send is only 64 So I can't send data completely (My URL > 64). So in data from last Column(bujur) in database, it prints only 10.00000 (it's supposed to be 107.12345). In the end, I upload the picture of my database.
First, I think the problem is the default serial buffer size Arduino because it also has 64 byte size. So, I've tried to change both of RX & TX buffer serial in HardwareSerial.h. But, nothing is changed and the result in my database still same.
Anyone can help? Thanks..