Secondary Ethernet buffer

I'm using the EtherCard library by Travis CI and I wish to implement one more ethernet buffer, but I cant figure out how.

Working example follows (single buffer):

#include "EtherCard.h"

EtherCard eth;

byte Ethernet::buffer[400];

static void eth_callback (byte status, word off, word len) {
 Serial.println();
 Ethernet::buffer[off+300] = 0;
 Serial.print((const char*) Ethernet::buffer + off);
}

Callback:

eth.browseUrl(PSTR(""), xUrl, srvIpAddr, eth_callback);

But, I wish to make something like this (double buffer):

#include "EtherCard.h"

EtherCard eth;

byte Ethernet::buffer[400]; // Primary buffer
byte Ethernet::buffer[400]; // Secondary buffer

static void eth_callbackA (byte status, word off, word len) { // Primary callback
 Serial.println();
 Ethernet::buffer[off+300] = 0;
 Serial.print((const char*) Ethernet::buffer + off);
}

static void eth_callbackB (byte status, word off, word len) { // Secondary callback
 Serial.println();
 Ethernet::buffer[off+300] = 0;
 Serial.print((const char*) Ethernet::buffer + off);
}

Callbacks:

eth.browseUrl(PSTR(""), xUrlA, srvIpAddr, eth_callbackA);
eth.browseUrl(PSTR(""), xUrlB, srvIpAddr, eth_callbackB);

how can I achieve that?

Do I need to define two ethernet or?

#include "EtherCard.h"

EtherCard ethA;
EtherCard ethB;

Which Arduino are you using? Using 800 bytes of memory for the two buffers seems unlikely.

The callback function is called to deal with the response from the server, when the GET request completes. Why can't it do more than one thing? You know which URL you browsed to when the callback gets called.

PaulS:
Which Arduino are you using? Using 800 bytes of memory for the two buffers seems unlikely.

The callback function is called to deal with the response from the server, when the GET request completes. Why can't it do more than one thing? You know which URL you browsed to when the callback gets called.

Yeah, I tough that too for the "Using 800 bytes"! :frowning:

I'm using UNO, two kWh meters attached trough pin 2 and 3, so I POSTing the values to Domoticz like this (Single buffer used):

sprintf(xUrl, "/json.htm?type=command&param=udevice&idx=7&nvalue=kWh&svalue=0;0;%s;0;0;%s", cPwrTmp, cPwrTmp);
eth.browseUrl(PSTR(""), xUrl, srvIpAddr, eth_callback);

Both kWh meters fires almost in same time, that is my issue, and I got ERR from in the GET request buffer, because the sketch want to update it on same time.

btw...kWh meters sketch setup:

attachInterrupt(0, onPulseA, FALLING); // kWh Interrupt Attached To IRQ1 = Arduino Pin-2
attachInterrupt(1, onPulseB, FALLING); // kWh Interrupt Attached To IRQ2 = Arduino Pin-3
, cPwrTmp, cPwrTmp);

Why do you need to send the same value twice? Why does a string variable name start with c?

Both kWh meters fires almost in same time, that is my issue

Why? Wait until both have fired, and then send both pieces of information.

PaulS:

, cPwrTmp, cPwrTmp);

Why do you need to send the same value twice? Why does a string variable name start with c?

I need to send the same value for Power and the Energy calculation.
And the "c" mark is only for my internal sketch referencing.

PaulS:
Why? Wait until both have fired, and then send both pieces of information.

Good idea, but what happens if one of the kWh meter don't have any load? It wont fire up!

But, in your case it would be like this, if I'm correct (example sketch diagram):

into Loop procedure

if onPulseA = true and onPulseB = true then
... POST both Http data together
onPulseA = false
onPulseB = false
end if

Good idea, but what happens if one of the kWh meter don't have any load? It wont fire up!

And the values not sent would be 0, so is the fact that they are not sent relevant?

PaulS:
And the values not sent would be 0, so is the fact that they are not sent relevant?

Maybe I can send it in this format for example, because the mentioned url supports two kWh meters.

sprintf(xUrl, "/json.htm?type=command&param=udevice&idx=7&nvalue=kWh&svalue=0;0;%s;%s;%s;%s", cPwrTmpA, cPwrTmpA, cPwrTmpB, cPwrTmpB);

And maybe if no load attached it will send 0 value anyway.

What you think about it?