-->
Page 1 of 1

Thermal Printer Issue...

PostPosted: Mon May 08, 2017 2:16 pm
by johnnyaio
So I'm trying to set-up a wifi thermal printer and want to be able to do a url or a 'form' data entry.
My webserver works and this works as well http://192.168.1.100/?TEXT=123

However I'm getting this error

Code: Select allSoft WDT reset

ctx: cont
sp: 3fff0530 end: 3fff08a0 offset: 01b0

>>>stack>>>
3fff06e0:  00000001 00000028 3fff0760 402076df 
3fff06f0:  00000001 3fff07a0 3fff0760 40206a92 
3fff0700:  3ffef5e8 0000000a 3ffef5e8 40206abc 
3fff0710:  0000001b 00000022 3fff27c6 402083e0 
3fff0720:  0000001d 00000021 3ffef5e8 4020415c 
3fff0730:  00000002 3ffeecd0 3ffef5e8 40208411 
3fff0740:  00000002 3ffeecd0 3ffef5e8 402073d1 
3fff0750:  00000002 3ffeecd0 3ffef5e8 4020211d 
3fff0760:  00000000 00000000 00000000 00000000 
3fff0770:  00000000 00000000 3fff27a4 0000002f 
3fff0780:  00000028 3fff07e0 00000000 40207634 
3fff0790:  00000002 00000001 3ffeecd0 40202184 
3fff07a0:  00000000 00000000 00000000 4010020c 
3fff07b0:  00000002 00000001 3fff247c 40208036 
3fff07c0:  00000000 00000000 3fff247c 40204152 
3fff07d0:  3fff247c 3ffeed10 3fff247c 4020418e 
3fff07e0:  00000000 00000000 00000000 40207840 
3fff07f0:  3fff247c 3ffeed10 3ffeecd0 40204221 
3fff0800:  3fff25a4 0000000f 00000001 402030f8 
3fff0810:  00000000 0000002d 0000002d 00000001 
3fff0820:  00000002 0000002d 0000000f 3ffef880 
3fff0830:  00000000 00000000 3ffeecd0 3ffef878 
3fff0840:  00000001 3ffeecf4 3ffeecd0 4020445b 
3fff0850:  3ffe87d8 00000000 000003e8 4020247e 
3fff0860:  00000000 3fff257c 40208040 4020802c 
3fff0870:  3fffdad0 00000000 3ffef870 4020249c 
3fff0880:  3fffdad0 00000000 3ffef870 40207e64 
3fff0890:  feefeffe feefeffe 3ffef880 40100718 
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(1,6)


 ets Jan  8 2013,rst cause:4, boot mode:(1,6)



Here is my code.
Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include "Adafruit_Thermal.h"
#include "SoftwareSerial.h"
#define TX_PIN 12 // Arduino transmit BLUE WIRE  labeled RX on printer
#define RX_PIN 5 // Arduino receive GREEN WIRE   labeled TX on printer


SoftwareSerial mySerial(RX_PIN, TX_PIN); // Declare SoftwareSerial obj first
Adafruit_Thermal printer(&mySerial);     // Pass addr to printer constructor

// Fill in your WiFi router SSID and password
const char* ssid = "...........";
const char* password = "..........";
MDNSResponder mdns;

ESP8266WebServer server(80);

const char INDEX_HTML[] =
"<!DOCTYPE HTML>"
"<html>"
"<head>"
"<meta name = \"viewport\" content = \"width = device-width, initial-scale = 1.0, maximum-scale = 1.0, user-scalable=0\">"
"<title>ESP8266 Web Form Demo</title>"
"<style>"
"\"body { background-color: #808080; font-family: Arial, Helvetica, Sans-Serif; Color: #000000; }\""
"</style>"
"</head>"
"<body>"
"<h1>Thermal Printer Type and Print</h1>"
"<FORM action=\"/\" method=\"post\">"
"<P>"
"TEXT<br>"
"<INPUT type=\"textarea\" name=\"TEXT\" value=\"test\">On<BR>"
"<INPUT type=\"submit\" value=\"Send\"> <INPUT type=\"reset\">"
"</P>"
"</FORM>"
"</body>"
"</html>";

void handleRoot()
{
  if (server.hasArg("TEXT")) {
    handleSubmit();
  }
  else {
    server.send(200, "text/html", INDEX_HTML);
  }
}

void returnFail(String msg)
{
  server.sendHeader("Connection", "close");
  server.sendHeader("Access-Control-Allow-Origin", "*");
  server.send(500, "text/plain", msg + "\r\n");
}

void handleSubmit()
{
  String TEXTVAL="";
  TEXTVAL = server.arg("TEXT");
  printer.wake();
  printer.setSize('L');
  printer.println(TEXTVAL);
  Serial.println(TEXTVAL);
  delay(3000);
  printer.sleep();
  server.send(200, "text/html", INDEX_HTML);
 
}



void handleNotFound()
{
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET)?"GET":"POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i=0; i<server.args(); i++){
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
}


void setup(void)
{

  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.println("");
  printer.begin();

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
 
  if (mdns.begin("esp8266WebForm", WiFi.localIP())) {
    Serial.println("MDNS responder started");
  }

  server.on("/", handleRoot);
  server.onNotFound(handleNotFound);

  server.begin();
  Serial.print("Connect to http://esp8266WebForm.local or http://");
  Serial.println(WiFi.localIP());
  printer.feed(1);
  printer.sleep();
}

void loop(void)
{
  server.handleClient();
}


I'm not sure if I need the mdns thing (not quite sure what it is, I assume it's an easier way to access the webpage without knowing the ip.

So I am assuming its the thermal printer as when going over 32 characters is usually an automatic crash.
e.g. http://192.168.1.100/?TEXT=123456789012 ... 4567890123
If I turn comment out the printer aspect, it works =/

any ideas how to fix this? I'm not sure if its a buffer issue or something... I was thinking that cutting the input into small chunks and print in chunks might fix this, but not sure how to do it.

Thanks in advance.

Re: Thermal Printer Issue...

PostPosted: Tue May 09, 2017 8:51 am
by johnnyaio
Well I figured out how to 'cut' a long phrase and that seems to fix it. Seems like the thermal printer has a small buffer.
My code below purely cuts every '16 block' (I'm pretty sure I have a redundant line as well, but didn't bother testing yet).

I was wondering if it was possible to do a smart cut though; meaning it wouldn't partially cut words.

Heres the code for cutting it into 16 characters. Had to add delay(10) or it would crash.
Code: Select all  float numstring;
  String TEXTVAL="";
  TEXTVAL = server.arg("TEXT");
  numstring = (TEXTVAL.length()/16.0);
  printer.wake();
  if (numstring - (TEXTVAL.length()/16)>=0) {
    numstring = (TEXTVAL.length()/16)+1;
  }
    else {
    numstring = (TEXTVAL.length()/16);
  }
  if (numstring < 2) {
  Serial.println(TEXTVAL);
  }
  else {
    int countd = numstring;
    while (countd > 0) {
      Serial.println(TEXTVAL.substring(0+(16*(numstring-countd)),16+(16*(numstring-countd))));
      printer.setSize('L');
      printer.println(TEXTVAL.substring(0+(16*(numstring-countd)),16+(16*(numstring-countd))));
      countd = countd - 1;
      delay(10);
    }
  }
  delay(3000);
  printer.sleep();
  server.send(200, "text/html", INDEX_HTML);