Initially I was sending sensor data to NodeJS using socketIO and this worked perfectly. I had to add a function to control an RGB LED using this. This also works but I'm unable to perform these two functions simultaneously.
I have tried to use two different ports on my Arduino. One to send data and another to control the LED but one overrides the other.
Question: Is there a way around this ? Is it practical to use two different ports?
arduino sketch
if (client.connect(server, 4000)) {
Serial.println("connected");
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
pinMode(pin, OUTPUT);
}
void loop()
{
//if you are connected and data is available
if (client.available()) {
char c = client.read();
// Serial.print("Message is : ");
Serial.print(c);
// '1' was received, return '1' for HIGH
if (c == '1') {
pinVal = HIGH;
// client.print("ON");
}
else if (c == '0') {
pinVal = LOW;
// client.print("OFF");
}
//turn led pin to new position
digitalWrite(pin, pinVal);
}
int chk = DHT.read11(DHT11_PIN);
int t = DHT.temperature;
int h = DHT.humidity;
// send data to the server
sendData(t, h);
Serial.print("Temperature = ");
Serial.print(t);
Serial.print( "," );
Serial.print("Humidity = ");
Serial.print(h);
Serial.print("\n");
delay(6000);
}
void sendData(int temperature, int humidity)
{
if(!client.connected())
{
if (client.connect(server, 3000)) {
Serial.println("Sending data...");
// send the HTTP PUT request:
client.print("GET /weatherserver/");
client.print(temperature);
client.print("/");
client.print(humidity);
client.print("/");
client.println(" HTTP/1.1");
client.println("Host: localhost");
client.println("User-Agent: arduino-barom");
client.println("Connection: close");
client.println();
client.stop();
} else {
Serial.println("Could not connect.");
client.stop();
}
}
delay(6000);
}