Wellington, New Zealand
Offline
Sr. Member
Karma: 1
Posts: 404
|
 |
« Reply #30 on: May 10, 2012, 02:26:41 pm » |
I have a question - do you have plans to support flow control? I'm losing bytes while ftp-ing large amounts of data at high speed from Arduino.
Do you have a suggestion for how to implement hardware flow control on an atmega328p? You may have a poorly matched baud rate selected based on the crystal speed on your arduino. Here's a nice break-down of the rate errors for different crystal speeds: http://www.wormfood.net/avrbaudcalc.php. You might get better results if you switch to a 14.7456 Mhz crystal. The WiFly datasheet claims that you can use rates above 115200 if your packes are uniform and you ensure the last packet has been sent before sending the next. So you may have some options there. Another problem may be that the RX serial buffer is overflowing before yor sketch empties it. Optimizing the sketch and/or increasing the size of the serial buffer may help.
|
|
|
|
|
Logged
|
|
|
|
|
Louisville, CO
Offline
Full Member
Karma: 2
Posts: 172
Arduino rocks
|
 |
« Reply #31 on: May 10, 2012, 02:41:32 pm » |
I'm sending data, not receiving. That's how I do it. I pick a digital pin, make it an input and connect CTS to it. I configure flow control on WiFly. in write() I read the pin and don't send until it's low. It can easily be done by modifying write(); I just though it would be nice to have it configurable instead.
[EDIT] I meant RTS, not CTS, sorry. Also, when you have flow control enabled, tie CTS to ground, otherwise you won't be receiving anything from the module's UART. You can also drive CTS if you need flow control in this direction. [/EDIT]
|
|
|
|
« Last Edit: May 10, 2012, 03:53:08 pm by felis »
|
Logged
|
/felis
|
|
|
|
Offline
Edison Member
Karma: 4
Posts: 1129
If you're not living on the Edge, you're taking up too much space!
|
 |
« Reply #32 on: May 11, 2012, 08:27:43 am » |
I have implemented my own "flow control" at 460k baud. It is also required when using FTP at 115k. You must know the default buffer size for each baud rate. You send that much at a time, then wait x milliseconds. Find x by trial and error. This is exactly the problem I'm referring to above. It appears to depend on the internet connection speed, ping time, and ISP. But not the Wifi maximum bitrate as much. My solution works great. Is there any way to decrease x? I'm only able to get 5K/sec at 460k.
|
|
|
|
|
Logged
|
If you fall... I'll be there for you! -Floor
Skype Brighteyes3333 (262) 696-9619
|
|
|
|
Offline
Edison Member
Karma: 4
Posts: 1129
If you're not living on the Edge, you're taking up too much space!
|
 |
« Reply #33 on: May 11, 2012, 06:52:17 pm » |
400 kbaud should be 50kB/sec. I would have so many applications for this if I could decrease x to get the average rate to 10k bytes/sec. Any ideas how? Is it waiting for a response from the router after each packet sent? Or from the FTP server? I would instead by happy if I could get to 10k even with a 1% data loss. 5% loss? Will experiment and post my results here.
|
|
|
|
|
Logged
|
If you fall... I'll be there for you! -Floor
Skype Brighteyes3333 (262) 696-9619
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 37
Arduino rocks
|
 |
« Reply #34 on: May 11, 2012, 07:00:42 pm » |
Thanks I've added it to the wiki. I assume you have one and its working with your WiFly? Yup it's the model I included in the title of my threads...  the one you helped me with my Internet dog treat dispenser...  cheers and thanks again for your help with that 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 4
Posts: 1129
If you're not living on the Edge, you're taking up too much space!
|
 |
« Reply #35 on: May 12, 2012, 11:19:27 am » |
Has anyone figured this out? Someone must want to send FTP data fast. Please post working code with speed test results.
|
|
|
|
|
Logged
|
If you fall... I'll be there for you! -Floor
Skype Brighteyes3333 (262) 696-9619
|
|
|
|
Offline
Edison Member
Karma: 4
Posts: 1129
If you're not living on the Edge, you're taking up too much space!
|
 |
« Reply #36 on: May 18, 2012, 02:10:17 pm » |
I'm having trouble with your httpserver example on github. Should I download the newest library again? Mine download is weeks old.
Got GET request Sent index page Unexpected: GET /favicon.ico HTTP/1.1 Sending 404
It displays the index page just fine in my browser, then nothing. Please help!
|
|
|
|
|
Logged
|
If you fall... I'll be there for you! -Floor
Skype Brighteyes3333 (262) 696-9619
|
|
|
|
|
|
Amsterdam, Netherlands
Offline
Jr. Member
Karma: 0
Posts: 52
|
 |
« Reply #38 on: June 01, 2012, 09:11:44 am » |
Hi! I'm trying to get any of the example sketches working from the library, but i seem to get the same error that ndanl got: Starting Free memory: 1283 setPrompt failed Failed to enter command mode Failed to start wifly Terminal ready I use this board and this module with the WiFlyHQ library. I think it's the baudrate of the xbee that's not right, but how do i enter command mode? i have 2 tiny microswitches on the breakout board, one for switching between XBEE/USB and one for RUN/PROG. It seems to me that if i should set it to XBEE and PROG i should be able to enter command mode with '$$$' right? and then issue the command set baud rate 115200 for example? The sketch i'm using is the example HTTPSERVER sketch, so i've not included it. Cany anyone help me? Thanks a bunch! i can make a photo of my setup if that's what's needed. but i just connected the module to the shield, and the shield to the arduino. i've decoupled all of my other electronic stuff... [EDIT] I've tried different baudrates, from 9600 up to 230400, doesn't make any difference. Also, switching between XBEE/USB and RUN/PROG doesn't seem to make any difference either.. i'm at a loss what i can do to analyse / debug this :/ [edit2] i've also tried to just enter command mode, but thats not working either.. how can i know for sure that i'm connecting to the wifly module? or is this why you guys all use the softserial thing? because switching just doesnt work well? if i want to use softserial, how should i be able to read the output on my mac? is that done with these FTDI - USB Boards? help!
|
|
|
|
« Last Edit: June 01, 2012, 12:33:04 pm by supermaggel »
|
Logged
|
|
|
|
|
Amsterdam, Netherlands
Offline
Jr. Member
Karma: 0
Posts: 52
|
 |
« Reply #39 on: June 05, 2012, 04:51:55 am » |
I now finally understand how it all works, i did not before. The library uses the hardware serial to send debug information, and uses a 'soft' serial to communicate with the RN-XV module (you cannot see this communication, only the debug messages in the sketch). Another problem i ran into, is that i could not enter command mode using this blasted shield. The shield is from DFrobot and is mentioned in compatible shields earlier in this thread i think. See these comments (scroll down to ahmad's comments on Sparkfun. So, i connected the RN-XV directly (because without cutting pins i can still return the shield, as i don't need it apparently) to 3.3V, ground, Din to arduino pin 8, Dout to arduino pin 9 and used the softserial. I might mix this up, maybe its Din to pin 9 and Dout to pin 8. Anyway, this time it worked (after resetting the ad-hoc mode) However, i can only enter command mode by using Telnet on port 2000. Kinda sucks. in Ad-hoc mode this is no problem, as the RN-XV will have it's own chosen IP, and so that IP + port 2000 is it's telnet port. But in client mode, as in joining an existing WiFi network, you'd have to find out what it's IP is and then be able to connect to it, a bit annoying. I hope this helps anyone who experiences the same problem with the mentioned shield!
|
|
|
|
« Last Edit: June 05, 2012, 05:00:24 am by supermaggel »
|
Logged
|
|
|
|
|
Amsterdam, Netherlands
Offline
Jr. Member
Karma: 0
Posts: 52
|
 |
« Reply #40 on: June 05, 2012, 05:02:18 am » |
Also, i am now with my limited C++ knowledge going to find out if i can make a WebSocketServer using the WebSocketClient example, and Per Ejeklint's WebSocketServer code. If there's anyone with a lot of C++ experience who'd like to help me get this working, YES PLEASE! drop me a line: maggelo@gmail.com. I've also started a new topic in programming questions in which i will run into problems concerning getting the 2 libraries to play nice together 
|
|
|
|
« Last Edit: June 05, 2012, 07:26:33 am by supermaggel »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 1
|
 |
« Reply #41 on: July 04, 2012, 12:36:50 pm » |
- Starting
Free memory: 1065 Joining network Failed to join wifi network
I always get this using the rn-xv (rev3) with Arduino and trying to start the "httpclient". I'm using the software serial. Reseted the board. Tried storing the auth data on the chip itself. Nothing works. Any idea what's going wrong?
|
|
|
|
« Last Edit: July 04, 2012, 01:09:09 pm by eszespeter »
|
Logged
|
|
|
|
|
Fidenza (PR)
Offline
Full Member
Karma: 3
Posts: 136
Arduino rocks
|
 |
« Reply #42 on: July 06, 2012, 04:05:51 am » |
how to send a few GET request with this device?? I proof this #include <SPI.h> #include <WiFlyHQ.h> #include <SoftwareSerial.h> #include "DHT.h"
#define Light_PIN A1 //imposto il pin a cui è connesso il sensore #define Smoke_PIN A2 //imposto il pin a cui è connesso il sensore #define DHT22_PIN 2 //imposto il pin a cui è connesso il sensore
#define DHTTYPE DHT22 // DHT 22 (AM2302) DHT dht(DHT22_PIN, DHTTYPE);
#define ledLight_PIN 6 #define ledSmoke_PIN 7 #define ledTemp_PIN 8 #define ledHum_PIN 9
#define Periodo_Invio_Dati 10000 //10s = tempo minimo tra un'invio sul web e l'altro.(ms) #define Periodo_Lettura_Sensore 2000 //2s = tempo minimo tra una lettura del sensore e l'altra (ms)
#define id_Light 2000 #define id_Smoke 3000 #define id_Temp 4000 #define id_Hum 5000
char username[] = "root"; //username per login sito char password[] = ""; //password per login sito
/*WIFI SETTING*/ WiFly wifly;
/* Change these to match your WiFi network */ const char mySSID[] = "DSG"; const char myPassword[] = "";
//const char site[] = "192.168.1.2";
void terminal(); void print_P(const prog_char *str); void println_P(const prog_char *str);
char serverName[] = "192.168.1.200";//URL del server a cui connettersi #define serverPort 80 //porta di connessione char pageName[] = "pagina_server.php";//nome pagina php per la ricezione dei dati
SoftwareSerial wifiSerial(8,9);
int light_accum = 0; float temp_accum = 0.0; float smoke_accum = 0.0; float hum_accum = 0.0;
long n_camp = 0;
float avg_light = 0.0; float avg_smoke = 0.0; float avg_temp = 0.0; float avg_hum = 0.0;
unsigned long time = 0; unsigned long SendTime = 0; unsigned long ReadTime = 0;
void setup() { // start the serial library: Serial.begin(9600); configWIFI(); pinMode(ledLight_PIN, OUTPUT); pinMode(ledSmoke_PIN, OUTPUT); pinMode(ledTemp_PIN, OUTPUT); pinMode(ledHum_PIN,OUTPUT); Serial.println("Connessione Configurata."); delay(1000);//aspetto un secondo per far avviare lo shield ethernet Serial.println("Programma Avviato, Setup Terminato!");
}
void loop() { time = millis(); if(time > SendTime + Periodo_Invio_Dati){ SendTime = millis(); avg_light = float(light_accum / double(n_camp));//calcolo la media delle lettura avg_smoke = float(smoke_accum / double(n_camp));//calcolo la media delle lettura avg_temp = float(temp_accum / double(n_camp));//calcolo la media delle lettura avg_hum = float(hum_accum / double(n_camp)); if(n_camp > 0) { Serial.println("connessione..."); digitalWrite(ledLight_PIN, HIGH); Serial.println("invio light sensor"); InvioWIFIHttp(serverName,serverPort,pageName,username,password,id_Light,avg_light); Serial.println("fine invio"); delay(100); digitalWrite(ledLight_PIN, LOW); digitalWrite(ledSmoke_PIN, HIGH); Serial.println("invio smoke sensor"); InvioWIFIHttp(serverName,serverPort,pageName,username,password,id_Smoke,avg_smoke); Serial.println("fine invio"); delay(100); digitalWrite(ledSmoke_PIN, LOW); digitalWrite(ledTemp_PIN, HIGH); Serial.println("invio temp sensor"); InvioWIFIHttp(serverName,serverPort,pageName,username,password,id_Temp,avg_temp); Serial.println("fine invio"); delay(100); digitalWrite(ledTemp_PIN, LOW); digitalWrite(ledHum_PIN, HIGH); Serial.println("invio temp sensor"); InvioWIFIHttp(serverName,serverPort,pageName,username,password,id_Hum,avg_hum); Serial.println("fine invio"); delay(100); digitalWrite(ledHum_PIN, LOW); }else Serial.println("Nessuna Campionatura, controllare sensore"); n_camp = 0; //azzero le variabili per iniziare nuovamente il calcolo della media light_accum = 0; smoke_accum = 0.0; temp_accum = 0.0; hum_accum = 0.0; Serial.flush(); wifly.flushRx(1); }
if(time > ReadTime + Periodo_Lettura_Sensore){ ReadTime = millis(); light_accum += readLightSensor(); smoke_accum += readSmokeSensor(); temp_accum += readTempSensor(); hum_accum += readHumiditySensor(); n_camp++; Serial.print("Campione : "); Serial.print(n_camp); Serial.print(" - "); Serial.println(time); } }
float readSmokeSensor(){ int val = analogRead(Smoke_PIN); // read the value from the analog sensor float Ro = 12000.0; // this has to be tuned 12K Ohm float Vrl = val * ( 5.00 / 1024.0 ); // V float Rs = 20000 * ( 5.00 - Vrl) / Vrl ; // Ohm float ratio = Rs/Ro; float ppm = 0.0; ppm = 37143 * pow (ratio, -3.178); return ppm; }
int readLightSensor(){ int luce = analogRead(Light_PIN); // Inserisco il valore della lettura dell'input analogico sull'intero ValoreSensore luce = (5.0* luce * 200.0) / 1024.0; return luce; }
float readTempSensor(){ // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong! if (isnan(t)) { Serial.println("Failed to read from DHT"); } else { return t; } }
float readHumiditySensor(){ // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float h = dht.readHumidity();
// check if returns are valid, if they are NaN (not a number) then something went wrong! if (isnan(h)) { Serial.println("Failed to read from DHT"); } else { return h; } }
void configWIFI(){ println_P(PSTR("Starting")); print_P(PSTR("Free memory: ")); Serial.println(wifly.getFreeMemory(),DEC);
wifiSerial.begin(9600); if (!wifly.begin(&wifiSerial, &Serial)) { println_P(PSTR("Failed to start wifly")); terminal(); }
char buf[32]; /* Join wifi network if not already associated */ if (!wifly.isAssociated()) { /* Setup the WiFly to connect to a wifi network */ println_P(PSTR("Joining network")); wifly.setSSID(mySSID); //wifly.setPassphrase(myPassword); wifly.enableDHCP();
if (wifly.join()) { println_P(PSTR("Joined wifi network")); } else { println_P(PSTR("Failed to join wifi network")); terminal(); } } else { println_P(PSTR("Already joined network")); }
print_P(PSTR("MAC: ")); Serial.println(wifly.getMAC(buf, sizeof(buf))); print_P(PSTR("IP: ")); Serial.println(wifly.getIP(buf, sizeof(buf))); print_P(PSTR("Netmask: ")); Serial.println(wifly.getNetmask(buf, sizeof(buf))); print_P(PSTR("Gateway: ")); Serial.println(wifly.getGateway(buf, sizeof(buf))); print_P(PSTR("SSID: ")); Serial.println(wifly.getSSID(buf, sizeof(buf)));
wifly.setDeviceID("Wifly-WebClient"); print_P(PSTR("DeviceID: ")); Serial.println(wifly.getDeviceID(buf, sizeof(buf)));
if (wifly.isConnected()) { println_P(PSTR("Old connection active. Closing")); wifly.close(); } if (wifly.open(serverName, 80)) { print_P(PSTR("Connected to ")); Serial.println(serverName);
Serial.println("WIFI ALREADY"); } else { println_P(PSTR("Failed to connect")); } }
/* Print a string from program memory */ void print_P(const prog_char *str) { char ch; while ((ch=pgm_read_byte(str++)) != 0) { Serial.write(ch); } }
void println_P(const prog_char *str) { print_P(str); Serial.println(); }
/* 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()); } } }
void InvioWIFIHttp(char server[], int porta, char pagina[], char username[], char password[], int idSensore, float dato) { /* Send the request */ //wifly.println("GET /arduino/pagina_server.php?username=&password=&sensore=5&dato=5 HTTP/1.0"); //wifly.println(); wifly.print("GET /arduino/"); wifly.print(pagina); wifly.print("?username="); wifly.print(username); wifly.print("&password="); wifly.print(password); wifly.print("&sensore="); wifly.print("5"); //wifly.print(idSensore); wifly.print("&dato="); wifly.print("12"); //wifly.print(dato); wifly.println(" HTTP/1.1"); wifly.print("Host: "); wifly.println(server); wifly.println(); }
the first data is sent ... After the device does not send anything more .. seems that the connection is closed .. how can I do?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #43 on: July 14, 2012, 01:34:16 am » |
- Starting
Free memory: 1065 Joining network Failed to join wifi network
I always get this using the rn-xv (rev3) with Arduino and trying to start the "httpclient". I'm using the software serial. Reseted the board. Tried storing the auth data on the chip itself. Nothing works. Any idea what's going wrong? eszespeter - did u try first connecting to your wifi network manually (writing to wifly directly using Ad-Hoc or serial)? If it is connected this way, try to avoid the setup re-connection and see if it's working
|
|
|
|
« Last Edit: July 14, 2012, 01:39:06 am by gilboash »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #44 on: July 14, 2012, 01:53:05 am » |
dhunt - Thanks alot for this library, I was looking for a reliable TCP client solution to communicate with python TCP server app on my home PC and it works great also with low memory consumption. From some reason i had to switch the #include <XX>, with #include "XX"
TX!!!
|
|
|
|
|
Logged
|
|
|
|
|
|