Hi
i need help urgently as i am very stuck on a code i am developing. I have a arduino mega connected to a wifly shield (connected to the main serial), i also have a Bluetooth device connected to the mega as well (connected on Serial 3). i want to be able to read client information when it is available. once the client is disconnected i want to be able to configure the wifly shield using the Bluetooth module. my code works separately however wont work when i put it together, i have tried so many combinations and nothing has worked. i will post my code so far below. if anyone can help i will be so grateful
#include <SPI.h>
#include <WiFly.h>
WiFlyServer server(2000);
int led = 31;
String readString;
char c;
void setup() {
Serial.begin(9600);
Serial3.begin(9600);
SpiSerial.begin();
WiFly.begin();
server.begin();
pinMode(led, OUTPUT);
}
void loop() {
WiFlyClient client = server.available();
if (client.connect()) {
while (client.available()) {
c = client.read();
readString += c; //makes the string readString
delay(5); //slow looping to allow buffer to fill with next character
}
if (readString.length() >0){
int commaIndex = readString.indexOf(',');
int secondCommaIndex = readString.indexOf(',', commaIndex+1);
String firstValue = readString.substring(0, commaIndex);
String secondValue = readString.substring(commaIndex+1, secondCommaIndex);
String thirdValue = readString.substring(secondCommaIndex+1); // To the end of the string
int x = firstValue.toInt();
int y = secondValue.toInt();
int z = thirdValue.toInt();
Serial.println(x);
if(x == 5){
digitalWrite(led, HIGH);
}else{
digitalWrite(led, LOW);
}
}
}
if (!client.connected() || !server.available()){
while(SpiSerial.available() > 0) {
#if ARDUINO >= 100
Serial3.write(SpiSerial.read());
#else
Serial3.print(SpiSerial.read(), BYTE);
#endif
}
if(Serial3.available()) { // Outgoing data
#if ARDUINO >= 100
SpiSerial.write(Serial3.read());
#else
SpiSerial.print(Serial3.read(), BYTE);
#endif
}
}
readString=""; //empty for next input
}
////////
i have update my code while i have been working on it, i have gotten closer to my answer, however when i connect using my phone via bluetooth on my phone terminal i only get the first letter of my commands when i enter the command config part of my wifly device. i know it is a delay issue but cant seem to figure out where to put the delay
thank you