void listenForEthernetClients() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("Got a client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()){
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
// client.println("HTTP/1.1 200 OK");
client.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">");
client.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
client.println("<meta http-equiv=\"refresh\" content=\"10\">");
client.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" / >");
client.println("<PRE>");
//print the current readings, in HTML format:
client.print("<body>");
client.print("<body bgcolor=\"#CAE1FF\">");
client.println("*** ARDUINO Webserver *** (c) G6EJD 2012");
client.println("Currently serving out Temperature, Air Pressure, Distance and Time");
client.println("Sensors: BMP085 Temp and Pressure, Ultrasonic HC-SR04 for Distance and DS1307 for time");
client.println();
client.print("Air Temperature : ");
client.print(temperature);
client.print("°C");
client.println();
client.print("CPU Temperature : ");
client.print(GetTemp());
client.print("°C");
client.println();
client.print(" Air Pressure : ");
client.print(float(int((pressure+545)/10))/10);
client.print(" mB");
client.println();
float duration; // Define the variable we will use to store the pulse duration
digitalWrite(trigPin, HIGH); // Set the trigPin high, start of pulse to get module working
delayMicroseconds(10); // Wait 10 uS
digitalWrite(trigPin, LOW); // Set the trigPin low, module will now send a pulse
duration = pulseIn(echoPin, HIGH); // Read the pulse length from the module
client.print(" Distance : ");
client.print(float(int(duration / 61*10))/10); // Send the distance in cm to the serial port
client.println(" cm");
DateTime now = RTC.now();
client.print(" Current Time : ");
if (now.day() < 10) { client.print("0"); }
client.print(now.day(), DEC);
client.print('/');
if (now.month() < 10) { client.print("0"); }
client.print(now.month(), DEC);
client.print('/');
client.print(now.year(), DEC);
client.print(' ');
if (now.hour() < 10) { client.print("0"); }
client.print(now.hour(), DEC);
client.print(':');
if (now.minute() < 10) { client.print("0"); }
client.print(now.minute(), DEC);
client.print(':');
if (now.second() < 10) { client.print("0"); }
client.print(now.second(), DEC);
client.println();
client.println("<BR />");
client.println("</PRE>");
client.println("</body>");
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
ftp:
wait 5
serout c.4, T2400, ("ftp put data.txt")
wait 3
serout c.4, T2400, ("test text")
wait 10
debug
goto ftp
ftp put data.txt
test text
Does the serial lead also use CTS/RTS? If so try linking those two pins together when using the PICAXE.Its simple to setup the unit through a serial lead, I used the same shield that are used for zigbee, that has the serial to usb chip plus the 3.3v regulated supply.
Just had a look at the schematic for the xbee-explorer you indicated that you were using.
It has an FTDI chip on it. It is the serial in that chip that you need to consider.
Working circuit for another device that only requires TXD/RXD and GND (like the picaxe serial) has a number of connections on the FTDI end to sort this issue.
CTS connected to RTS Leg 11 to 3 on FTDI
&
DTR connected to DSR & DCD Leg 2 to 9 & 10.
I would try just CTS--RTS first.
Also the WiFly does not expect these to be connected so hopefully the board allows you to connect these at the FTDI without that connection also being seen by the WiFly.
If not then there may be more work to do in the WiFly to cope with that configuration.
So how are you connecting the 5V PICAXE signal to the 3V3 Wifly?. I am using a 5v rail for picaxe and have powered the Wifly via 3v3 reg off the same 5v rail.
So how are you connecting the 5V PICAXE signal to the 3V3 Wifly?Well spotted but I am actually connecting the pin via 4 IN4001 s in series to give me a volt drop to near enough 3.5 v measured.
Two potential problems with that; 3.5V would seem to be above the maximum voltage allowed on the WiFly inputs, and it makes the signal 'open emitter'; 5V output will pull the input high, but 0V output will leave the input floating.I am actually connecting the pin via 4 IN4001 s in series to give me a volt drop to near enough 3.5 v measured.
symbol counter= w0
counter = 1
high c.4
serout c.4, T2400, ("exit")
wifly:
wait 10
serout c.4, T2400, ("$$$")
;CMD
wait 1
serout c.4, T2400, ("ftp put data.txt",counter)
;*OPEN*
wait 1
serout c.4, T2400, ("test text")
;*CLOS*
wait 1
serout c.4, T2400, ("exit")
;EXIT
counter = counter + 1
debug
goto wifly
symbol counter= w0
counter = 1
high c.4
serout c.4, T2400, ("exit")
wifly:
wait 10
serout c.4, T2400, ("$$$")
;CMD
serin c.x, T2400, b1,b1,b1
serout c.4, T2400, ("ftp put data.txt",counter)
;*OPEN*
serin c.x, T2400, b1,b1,b1,b1,b1,b1
etc.
symbol counter= b0
symbol letter1 = b1
symbol letter2 = b2
symbol letter3 = b3
symbol letter4 = b4
symbol letter5 = b5
symbol letter6 = b6
symbol place = b7
counter = 1
high c.4
place = 0
debug
wait 20
goto wifly
resetletter:
letter1 = 0
letter2 = 0
letter3 = 0
letter4 = 0
letter5 = 0
letter6 = 0
return
wifly:
place = 1
debug
wait 5
place = 2
debug
serout c.4, T2400, ("$$$")
;CMD
place = 3
debug
serin c.3, T2400, ("CMD"), letter1,letter2,letter3
place = 4
debug
wait 5
;goto resetletter
;serout c.4, T2400, ("ftp put data.txt",counter)
;*OPEN*
;serin c.3, T2400, b10,b10,b10,b10,b10,b10
;serout c.4, T2400, ("test text")
;*CLOS*
;serin c.3, T2400, b10,b10,b10,b10,b10,b10
serout c.4, T2400, ("exit")
;EXIT
serin c.3, T2400, ("EXIT"), letter1,letter2,letter3,letter4
counter = counter + 1
wait 5
;goto resetletter
goto wifly
Not sure how you mean by some other way, but it did draw attention to the fact it seems you are not sending any 'enter' to the module from your PICAXE program and that would likely be required. That 'enter' is likely to be CR, LF or CR then LF. The datasheet or user manual should indicate which.I am wondering is there some other way of sending an "Enter" key press other then using "lf" or "cr" as I now believe the Wifly unit does not correctly process the next command which is to open the FTP connection to the server.
setfreq m32
symbol counter= b0
counter = 1
high c.4
wait 60
wait 60
goto wifly
wifly:
serout c.4, T9600_32, ("$$$")
;CMD
serin c.3, T9600_32, ("CMD")
wait 16
serout c.4, T9600_32, ("ftp put ",#counter,"data.txt",cr)
;*OPEN*
serin c.3, T9600_32, ("*OPEN*")
serout c.4, T9600_32, ("Lots of info line 1",lf,"Lots of info line 2",lf)
;*CLOS*
serin c.3, T9600_32, ("*CLOS*")
wait 16
serout c.4, T9600_32, ("exit",cr)
;EXIT
serin c.3, T9600_32, ("EXIT")
wait 60
wait 60
counter = counter + 1
goto wifly
I was thinking that may be root cause alright as it is intermittent.It could be that the WiFly is responding sooner than the PICAXE is ready to receive its reply. It is possible to timeout if no reply is received, but if you do that you don't know if entering command mode was successful or not which makes it difficult to decide how to proceed.
The ideal solution is to use an X2 and high-speed background receive which will always catch any reply sent no matter how soon after a command is issued. This will also allow data returned that is of variable length to be more easily parsed.
waitcmd:
hsersetup B9600_32, %00
;Wait for "CMD" to be returned and then proceed with the next step
hserin [ 1000, waitcmd] ,0,3, ("C")
ptr = 0
b1=@ptrinc : if b1 = "M" then waitcmd
b1=@ptrinc : if b1 = "D" then waitcmd
goto wifly
wifly:
;Send the command to enter AT mode on the WiFly
hserout 0, ("$$$")
hsersetup B9600_32, %000
wifly1:
;CMD
hserin [ 1000, wifly1] ,0,3, ("C")
ptr = 0
b2=@ptrinc : if b2 <>"M" then wifly1
b2=@ptrinc : if b2 <>"D" then wifly1
goto wifly2
wifly:
;bit0 - background receive serial data to the scratchpad (not M2 parts)
;bit1 - invert serial output data (0 = ‘T’, 1 = “N”)
;bit 2 - invert serial input data (0 = “T”, 1 = “N”)
;bit 3 - disable hserout (1 = hserout pin normal i/o)
;bit 4 - disable hserin (1 = hserin pin normal i/o)
hsersetup B9600_32, %000
hserout 0, ("$$$")
goto wifly1
wifly1:
;CMD
hserin [ 1000, wifly1] ,0,3, ("C")
ptr = 0
b2=@ptrinc : if b2 <>"M" then wifly1
b2=@ptrinc : if b2 <>"D" then wifly1
goto wifly2
wifly2:
success = 1
debug
You are not using HSERIN in background receive mode. Rather you are using HSERIN similar to how you were using SERIN after SEROUT earlier, though I would guess it is taking advantage of the double buffering of the serial receive buffer.Ok, I think this is correct as now I am able to process the returned "CMD, but I am unsure if the hersin is definetlly listening in the background?
I'm sure I have set bit 0 correctly to 0 in the hsersetup:
Code:hsersetup B9600_32, %000
One would normally use background receive or the HSERIN command not both so there are potential problems. I was really only clarifying that you weren't using background receive. If what you have works then stick with that.So will I be ok with my existing example once I change the hsersetup to %001?