Thanks for the information. Don't worry i got what you told me the first time. I will definitly use the proper hd44780 library but I must sort what is coming out of the server first.
It seems the first thing client.read() is getting is some kind of init string. I was able to print it to the LCD, it's a first step but I must decode what data i'm suppose to print and not the entire TCP paquet. I tought the ESP8266WIFI library was handling all the TCP stuff and returning the raw data but i was wrong.
The LCD prints;
HD44780 16X2
TCP b1
It seems I need to send back some data to the lcdproc client.
When i write back with client.write(0x01) etc i get some response from the linux driver and more data.
Here is my slimmed down code if anywais is interesested in helping me try to debug this I would greatly appreciate.
//#include <avr/io.h>
//#include <util/delay.h>
#include <Arduino.h>
// vim: ts=4 ai
// based on info got from here:
// http://lcdproc.cvs.sourceforge.net/viewvc/lcdproc/lcdproc/server/drivers/hd44780-serial.h?content-type=text%2Fplain
#define LED_PIN 15 // This is the pin the backlight is controlled by, it must be a PWM pin
#define STARTUP_BRIGHTNESS 128 // What backlight brightness to start up with (50% by default).
# define BAUDRATE 9600 // What baudrate to use for the serial port
// There was a reason I did not use these as defines, but I can't
// remember it :-/
const int LCDW = 16;
const int LCDH = 2;
// include the LCD library code:
#include <LiquidCrystal.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
//#include <WiFi.h>
#include <ESP8266WebServer.h>
#ifndef STASSID
#define STASSID "ssid"
#define STAPSK "passw"
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
//const char* host = "test.net";
//const uint16_t port = 17;
#define LCD_PORT 2425
WiFiServer server(LCD_PORT);
// And this is ths Hardware serial port (which is also bound to the UART->USB chip)
//#include <HardwareSerial.cpp>
// initialize the library with the numbers of the interface pins
/* Note, while all the ardu documentation and schematics show 4-bit operation.
It seems the library actually supports both 8-bit and 4-bit mode. It attempts
8-bit, then falls back to 4-bit */
//LiquidCrystal lcd(12, 11, 2, 3, 4, 5, 6, 7, 8, 9);
const int rs = 16, en = 5, d4 = 4, d5 = 13, d6 = 12, d7 = 14;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void set_backlight(int value) {
// We can control the backlight via PWM here, range from 0 to 255 values
// 0 is "off", 255 is "on" (max brightness).
analogWrite(LED_PIN, value); // pin 10 is PWM, so we can vary brightness this way
}
void setup() {
pinMode(LED_PIN, OUTPUT); // set pin to output
// We first set the backlight to 50% brightness
set_backlight(STARTUP_BRIGHTNESS);
// set up the LCD's number of columns and rows:
lcd.begin(LCDW, LCDH);
// set up serial
lcd.display();
lcd.clear();
lcd.write("Ready");
Serial.begin(BAUDRATE);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
Serial.println(String("Starting server on port: ") + LCD_PORT);
}
void loop() {
// server.handleClient();
// Todo: Investigate how to to interrupt driven serial I/O, like on PICs.
// sitting in a tight loop like this is quite wasteful.
int x = 0;
//char cmd; //will hold our sent command
// int cmd; //will hold our sent command
int cursor = 0; //current cursor position (emulated)
int scursor = 0;
char data[5]; //data buffer for (un)signed int printing
WiFiClient client = server.available();
/*
if (!client) {
Serial.println("connection failed");
delay(5000);
return;
}
*/
if (client) { // if we have a connection
if (client.connected())
{
Serial.println("Client Connected");
}
while (client.connected()) { // keep the client open
while (client.available() > 0) { // while client is available
int8_t cmd = client.read(); // store the incoming char
//char cmd = client.read(); // store the incoming char
Serial.println(String("Incoming string: ") + cmd);
client.flush();
switch (cmd) { // switch it
case 0x01:
// set cursor position, next byte is pos
while (client.available() == 0) {
delay(1);
}
cmd = client.read();
Serial.println(String("LCD_SETDDRAMADDR: ") + cmd);
Serial.println(cmd, HEX);
lcd.command(LCD_SETCGRAMADDR | cmd);
client.write(1);
cursor = cmd;
break;
case 0x02:
cmd = client.read();
Serial.println(String("case 0x02: ") + cmd);
Serial.println(cmd, HEX);
lcd.write(cmd);
client.write(0x02);
//cursor = cmd;
break;
case 0x06:
cmd = client.read();
Serial.println(String("case ETHLCD_GET_FIRMWARE_VERSION 0x06: ") + cmd);
Serial.println(cmd, HEX);
//lcd.write(cmd);
client.write(0x06);
//cursor = cmd;
break;
default:
while (1) {
Serial.println(String("Default case: ") + cmd);
Serial.println(cmd, HEX);
if (cmd != -1) {
break;
}
break;
}
} // end switch cmd
} //end while client available
} // end whie client connected
// client.stop();
Serial.println("Client disconnected");
} // end if client
}// end main loop
Basically this comes to how can i store the raw data coming from the server? I'm guessing this will envolve storing into an array etc but I need some guidance on how to proceed.
Thanks again.