Hey, i cant seem to receive TCP commands when using a server.
I can receive TCP commands and print them to the serial window using the below code;
*
SpiUartTerminal - tool to help troubleshoot problems with WiFly shield
This code will initialise and test the SC16IS750 UART-SPI bridge then enable you
to send commands to the WiFly module.
Copyright (c) 2010 SparkFun Electronics. http://sparkfun.com LGPL 3.0
*/
#include <SPI.h>
#include <WiFly.h>
void setup() {
Serial.begin(9600);
Serial.println("Attempting to connect to SPI UART...");
SpiSerial.begin();
Serial.println("Connected to SPI UART.");
Serial.println();
delay(1000);
Serial.write("$$");
SpiSerial.begin();
//exit CMD mode if not already done
SpiSerial.println("");
SpiSerial.println("exit");
Serial.println("Exited CMD mode");
delay(100);
//set into CMD mode
SpiSerial.print("$$");
Serial.println("Into CMD mode");
delay(100);
//switch DHCP on
SpiSerial.println("set ip dhcp 1");
Serial.println("Set DHCP");
delay(100);
//set authorisation level
// SpiSerial.println("set w a 4");
//Serial.println("Set authorisation level");
//delay(1000);
//set passphrase
SpiSerial.println("set wlan key 9d7cdbc6ce");
Serial.println("Set WLAN key");
delay(100);
//set localport
//SpiSerial.println("set i l 80");
//Serial.println("Set port");
delay(100);
//disable *HELLO* default message on connect
SpiSerial.println("set comm remote 0");
Serial.println("Set comm remote 0");
delay(100);
//join wifi network
SpiSerial.println("join BTHub3-HKP4");
Serial.println("Join network");
delay(200);
SpiSerial.println("set ip local 2102");
Serial.println("Listening on port 2102");
delay(200);
SpiSerial.println("set ip protocol 2");
Serial.println("SETTING TCP");
delay(200);
//exit CMD mode
SpiSerial.println("exit");
Serial.println("Exiting SpiSerial");
delay(300);
Serial.print("IP: ");
Serial.println(WiFly.ip());
server.begin();
}
void loop() {
// Terminal routine
// Always display a response uninterrupted by typing
// but note that this makes the terminal unresponsive
// while a response is being received.
while(SpiSerial.available() > 0) {
Serial.write(SpiSerial.read());
}
if(Serial.available()) { // Outgoing data
SpiSerial.write(Serial.read());
}
}
}
Which is no use to me, because i cant use the send TCP packet for any if statements.
I have tried the following code, which worked once, then never worked again!
#include <SPI.h>
#include <WiFly.h>
// Enter a MAC address, IP address and Portnumber for your Server below.
// The IP address will be dependent on your local network:
// Initialize the Ethernet server library
// with the IP address and port you want to use
WiFlyServer server(2102);
void setup()
{
WiFly.begin();
if (!WiFly.join("BTHub3-HKP4", "9d7cdbc6ce")) {
while (1) {
// Hang on failure.
}
}
server.begin();
Serial.println("Server started");//log
}
void loop()
{
// listen for incoming clients
WiFlyClient client = server.available();
if (client) {
Serial.print("1");
String clientMsg ="";
while (client.connected()) {
if (client.available()) {
Serial.print("3");
char c = client.read();
Serial.print(c);
clientMsg+=c;//store the recieved chracters in a string
//if the character is an "end of line" the whole message is recieved
if (c == '\n') {
Serial.println("Message from Client:"+clientMsg);//print it to the serial
// if (clientMsg == "hi"){
//Serial.print("command received");
//}
client.println("You said:"+clientMsg);//modify the string and send it back
clientMsg="";
}
}
}
// give the Client time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
the code gets to while (client.connected()) and no further. I have connected because i get a solid green light upon TCP connection via comms operator.
any help?
Ive ensured all firewalls are open
thanks