Hi!
I try to make the code, which will read the data on the server and write to LCD.
There's something wrong with the code.
Code running in loop about 10 times, then all stops.
In serialmonitor all freezes, the values on lcd are no longer refreshed.
Strangely for me is, when I close the Serialmonitor and re-open, the code starts to run again. :o
Can you help me ?
CODE:
#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>
#include <LiquidCrystal_I2C.h>
byte mac[] = { 0x84, 0x42, 0x8B, 0xBA, 0xB2, 0x31 }; //mac address of ethernet shield
IPAddress server(192, 168, 5, 91);
IPAddress ip(192, 168, 5, 98);
IPAddress gateway(192, 168, 5, 1);
IPAddress subnet(255, 255, 255, 0);
EthernetClient client;
TextFinder finder( client );
LiquidCrystal_I2C lcd1(0x3B, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup()
{
Serial.begin(115200);
Ethernet.begin(mac, ip);
lcd1.begin(20, 4);
Serial.println("connecting...");
delay(10000);
}
void loop(){
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("/search?q=arduino HTTP/1.1");
client.println("Host: 192.168.5.91");
client.println("Connection: close");
client.println();
}
else {
Serial.println("connection failed");
}
while(client.connected() && !client.available()) delay(3000); //waits for data
finder.find("TEMP1:");
float value1 = finder.getFloat(".");
Serial.println(value1);
Serial.print('\n');
finder.find("TEMP2:");
float value2 = finder.getFloat(".");
Serial.println(value2);
Serial.print('\n');
finder.find("TEMP3:");
float value3 = finder.getFloat(".");
Serial.println(value3);
Serial.print('\n');
lcd1.setCursor(0, 0);
lcd1.print("TEMP1:");
lcd1.setCursor(14, 0 );
lcd1.print(value1,2);//
lcd1.setCursor(0, 1);
lcd1.print("TEMP2:");
lcd1.setCursor(14, 1);
lcd1.print(value2,2);//
lcd1.setCursor(0, 2);
lcd1.print("TEMP3:");
lcd1.setCursor(14, 2);
lcd1.print(value3,2);//
client.stop();
client.flush();
}