I am close to have my project working, but still stucked with the printer.
I created a php web page populated with a MySql. It displays one entry at a time, and it's updated everytime it is loaded. There is just plain text.
My yun connects to this web page and uses Process to get the text, in order to send it ton a Sparkfun Thermal Printer.
Web page works perfectly, and I get some content but it is really buggy.
In the serial, it's displaying well. I have a one minute delay in my loop so the web page is refreshed every minute to get new content.
But every time I connect the printer, it sucks. I have a linebreak between every letter, or the text populates one letter at a time and loops so I have 10 A's...
Here is my code, if you're able to help me...
#include <Process.h>
#include "SoftwareSerial.h"
#include "Adafruit_Thermal.h"
int printer_RX_Pin = 5; // This is the green wire
int printer_TX_Pin = 6; // This is the yellow wire
Adafruit_Thermal printer(printer_RX_Pin, printer_TX_Pin);
void setup() {
Bridge.begin();
pinMode(7, OUTPUT); digitalWrite(7, LOW); // To also work w/IoTP printer
printer.begin();
printer.println("OK ! Let's print");
printer.sleep();
Serial.begin(9600);
while (!Serial);
}
void loop() {
runCurl();
delay(10000);
}
void runCurl() {
char c;
Process p;
p.begin("curl");
p.addParameter("http://remote-servor/print.php");
p.run();
while (p.available()>0) {
char c = p.read();
Serial.print(c);
}
delay(10000);
printer.wake();
printer.print(c);
printer.println('\n');
printer.sleep();
printer.setDefault();
Serial.flush();
}
void runText() {
}
A local variable, not initialized, and never used.
while (p.available()>0) {
char c = p.read();
Serial.print(c);
}
A new local variable of the same name that is initialized and used, but goes out of scope as soon as all the data has been read (and, effectively discarded). This whole while loop is useless as far as collecting data to be printed.
printer.print(c);
Here you are printing the uninitialized variable, not anything read from the process.
Serial.flush();
Block until all pending serial data has been sent. After sleeping for 10 seconds, do you seriously think that there is any data still waiting to be sent?