PSTR Issue

I have an Arduino Nano hooked up to a ENC28J60 Ethernet board, and I’m using the Ethercard library. The setup works fine with the demo code.

What I’m trying to do is present a barcode, but I’m getting weird results.

Here’s my code:

// This is a demo of the RBBB running as webserver with the Ether Card
// 2010-05-28 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php

#include <EtherCard.h>

// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
static byte myip[] = { 192,168,1,230 };

byte Ethernet::buffer[500];
BufferFiller bfill;
char bcode1;
long bcode2;

void setup () {
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
    Serial.println( "Failed to access Ethernet controller");
  ether.staticSetup(myip);
  
  bcode1 = '933242';
}

static word homePage() {
  long t = millis() / 1000;
  word h = t / 3600;
  byte m = (t / 60) % 60;
  byte s = t % 60;
  bfill = ether.tcpOffset();
  bfill.emit_p(PSTR(
    "HTTP/1.0 200 OK\r\n"
    "Content-Type: text/html\r\n"
    "Pragma: no-cache\r\n"
    "\r\n"
    "<title>Shopping Server</title>"
    "barcode $D$D"),
     bcode1);
  return bfill.position();
}

void loop () {
  word len = ether.packetReceive();
  word pos = ether.packetLoop(len);
  
  if (pos)  // check if valid tcp data is received
    ether.httpServerReply(homePage()); // send web page data
}

From the documentation, I should be using %s as the placeholder, but the html returns the literal %s, not the variable. I’ve tried using a long variable, but I get an output of 5057857 instead of 933242.

Please help, I’m getting frustrated!

bcode1 = '933242';

?

(Did you see what I did with code tags there?)

Which are what on this site?

Hash mark (#) button above the smileys

beerbotboffin: Which are what on this site?

The button or

Manually:

[code=title]//Your code here[/code]

Produces:

//Your code here

and what BulldogLowell said, beat me...

Thanks guys. That's slightly more helpful than sarcasm.

Also here and here

Well, that's very exciting. Do you have a solution, or do you just take pleasure from being annoying?

char bcode1;bcode1 = '933242'; OK, now do you see the problem?

Do you have a solution, or do you just take pleasure from being annoying?

Maybe YOU need to lay off the beer for a while, until the programming is done.

Single quotes are for single characters. Please post a picture of your keyboard, with the ONE key circled that you pressed to get the ONE character in the single quotes:

bcode1 = '933242';

My keyboard doesn't have a key like that...

Your sentence is malformed.

beerbotboffin: Your sentence is malformed.

So is your code.

AWOL: char bcode1;bcode1 = '933242'; OK, now do you see the problem?

sorry I pressed send too quick

try:

long bcode1;

and change your assignment to:

bcode1 = 933242;

or a string

String bcode1;

and

bcode1 = "933242";

and most importantly try not to get too upset about the snarky commentary. They mean well and teach much... even if it comes off strong :cold_sweat:

Cheers mate. That’s resolved the issue thankfully. Thank you.

I ended using

char bcode1[15] = "9332428001316";

and

  bfill.emit_p(PSTR(
    "HTTP/1.0 200 OK\r\n"
    "Content-Type: text/html\r\n"
    "Pragma: no-cache\r\n"
    "\r\n"
    "<meta http-equiv='refresh' content='1'/>"
    "<title>RBBB server</title>"
    "<h1>$S</h1>"),
      bcode1);

Now seeing precisely what I was expecting to see.

and most importantly try not to get too upset about the snarky commentary. They mean well and teach much… even if it comes off strong smiley-roll-sweat

I’ve been struggling with a temperamental proto board and dodgy code all afternoon, so snarky comments don’t help.

It's a form of triage - if someone sees bcode1 = '933242';pointed-out to them, smacks their forehead and says "Gah! How could I have been so stupid?" and fixes it, we can all move on from there.

If they don't understand the response, we can deploy a different approach and guide them in.

beerbotboffin: I've been struggling with a temperamental proto board and dodgy code all afternoon...

great to see it worked out!

we can deploy a different approach

Yeah. We get "snarky". Whatever the heck that means... 8)

8)

PaulS:

we can deploy a different approach

Yeah. We get "snarky". Whatever the heck that means... 8)

it's bizzaro for helpful, charming and maybe even handsome. :)