All the code is based the pachatube tutorial and on someone's else work found on the net but i didn't note whom and where... sorry for that
I just post here the code for printing something over 9100 port. My full program is useless for people I think.
/!\ you need PCL 5E compatible printer or something like that ( Meaning printer which use proprietary protocol should not work)
//
/* test /
/ mac de la carte byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xXX, 0xXX }; /
/ /
/ */
//
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xXX, 0xXX };
byte ip[] = { 192, 168, 1, XXX }; // IP of our arduino
byte server[] = { 192, 168, 1, YYY}; // IP of our printer
Client client(server, 9100);
long lastConnectionTime = 0;
boolean lastConnected = false;
const int postingInterval = 30000;
void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);
delay(1000);
}
void loop()
{
// if there's incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if there's no net connection, but there was one last time
// through the loop, then stop the client:
if (!client.connected() && lastConnected) {
client.stop();
}
// if you're not connected, and ten seconds have passed since
// your last connection, then connect again and send data:
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
sendData();
}
// store the state of the connection for next time through
// the loop:
lastConnected = client.connected();
}
void sendData() {
// if there's a successful connection:
if (client.connect()) {
Serial.println("connecting...");
client.println("Hello Word");
client.stop();
// note the time that the connection was made:
lastConnectionTime = millis();
}
else {
// if you couldn't make a connection:
Serial.println("connection failed");
client.stop();
}
}