ENC28J60 Ethernet Module and EtherCard Library

Hi there,

I’m trying to send analog data just for test purposes to my local Domoticz Server, but I can’t figure out how to use the “ether.browseUrl” function in this case.

EtherCard Library what I’m using, GitHub link

The link what I’m trying to trigger:

http://192.168.0.1:8002/json.htm?type=command&param=udevice&hid=1&did=7D0000043F24BA23&dunit=1&dsubtype=9&dtype=80&nvalue=0&svalue=

and my Arduino code:

#include "EtherCard.h"

// Ethernet interface mac address, must be unique on the LAN
static byte mymac[] = {0x74,0x69,0x69,0x2D,0x30,0x31};

byte Ethernet::buffer[700];
static uint32_t timer;

const char sServer[] PROGMEM = "192.168.0.1";

String sPort = ":8002";
String sUrl = "/json.htm?type=command&param=udevice&hid=1&did=7D0000043F24BA23&dunit=1&dsubtype=9&dtype=80&nvalue=0&svalue=";
String sSnz = "";
String dataInput = "";
int sSnzVal = 0;

// Called when the client request is complete
static void brw_cb (byte status, word off, word len) {
 Serial.println(">>>");
 Ethernet::buffer[off+300] = 0;
 Serial.print((const char*) Ethernet::buffer + off);
 Serial.println("...");
}

void setup () {
  Serial.begin(9600);
  Serial.println(F("\n[webClient]"));

  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
    Serial.println(F("Failed to access Ethernet controller"));
  if (!ether.dhcpSetup())
    Serial.println(F("DHCP failed"));

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);  
  ether.printIp("DNS: ", ether.dnsip);  

  if (!ether.dnsLookup(sServer))
    Serial.println("DNS failed");
    
  ether.printIp("SRV: ", ether.hisip);
}

void loop () {
  ether.packetLoop(ether.packetReceive());
  
  if (millis() > timer) {
    timer = millis() + 5000;
    Serial.println();
    Serial.print("<<< REQ ");
    sSnzVal = analogRead(A0);
    sSnz = String(sSnzVal);
    dataInput = String(sPort + sUrl + sSnz); // Combine all together (Port, JSon link and Analog Value)
    Serial.print(dataInput);
    char charBuf[50];
    dataInput.toCharArray(charBuf, 50);
    ether.browseUrl(PSTR(""), charBuf, sServer, brw_cb);
  }
}

Can someone help me out?! :confused:

Can someone help me out?

Ditch this crap. There is no excuse for pissing away resources on the String class.

String sPort = ":8002";
String sUrl = "/json.htm?type=command¶m=udevice&hid=1&did=7D0000043F24BA23&dunit=1&dsubtype=9&dtype=80&nvalue=0&svalue=";
String sSnz = "";
String dataInput = "";
    dataInput = String(sPort + sUrl + sSnz); // Combine all together (Port, JSon link and Analog Value)

Just how big IS that String? 5 + 108 + somewhere between 1 and 4 = 114 to 117.

    char charBuf[50];
    dataInput.toCharArray(charBuf, 50);

So, lets grab the first 49 characters, and wonder why things don't work.

I have an idea...

PaulS: Ditch this crap. There is no excuse for pissing away resources on the String class.

You are a very funny guy, I like that! ;)

PaulS: Just how big IS that String? 5 + 108 + somewhere between 1 and 4 = 114 to 117.

97 chars

PaulS: So, lets grab the first 49 characters, and wonder why things don't work.

I have an idea...

Yeah, I figured that out after 5 minutes, now the buffer size is 100 chars! :D

Also this was needed to shrink a little bit from 700 to 400

byte Ethernet::buffer[700];

And the main issue is with the EtherCard Library that there is no function for PORT definition, so I edited the EtherCard.cpp file on line 399

From:

uint16_t EtherCard::hisport = 80; // tcp port to browse to

To:

uint16_t EtherCard::hisport = 8002; // tcp port to browse to

97 chars

How did you arrive at that value? I pasted the value of sURL into Notepad++, and it said that there were 108 characters in that string alone.

PaulS: How did you arrive at that value? I pasted the value of sURL into Notepad++, and it said that there were 108 characters in that string alone.

Because the sensor identifier was too long in the link...

did=7D0000043F24BA23