ENC28J60 +php crash on stm32f103ve

ramgc
Wed Feb 14, 2018 12:49 pm
Hello, i am design a circuit with stm32f103ve, and just connect enc28j60 for internet. I have a server with xampp and work properly with apps in android, i am using Serasidis_EtherCard_STM library, when http get to my php server dont receive nothing good, if put other web equal.

code is webClient for arduino in this library

#include <SPI.h>
#include <EtherCard_STM.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 website[] PROGMEM = "82.221.41.158";

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

void setup () {
Serial.begin(57600);
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(website))
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 ");
ether.browseUrl(PSTR("/comprueba_maq_ON.php?maquina="), "1", website, my_callback); }
}


stevestrong
Wed Feb 14, 2018 2:02 pm
I can only recommend to use W5500 (Wiznet) modules instead of ENC28J60 modules.
The Wiznet chip is much more reliable (my experience) and the lib for that is better supported.
The W5500 module prices are also competitive with those of ENC module: https://www.aliexpress.com/item/Replace … 56354.html

Vassilis
Wed Feb 14, 2018 3:16 pm
@ramgc The IP in your sketch (82.221.41.158) is not functional (at least to me). Please provide us with a sketch that uses a valid public IP or public domain name.

ramgc
Wed Feb 14, 2018 3:21 pm
[Vassilis – Wed Feb 14, 2018 3:16 pm] –
@ramgc The IP in your sketch (82.221.41.158) is not functional (at least to me). Please provide us with a sketch that uses a valid public IP or public domain name.

ok, thanks

#include <SPI.h>
#include <EtherCard_STM.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 website[] PROGMEM = "82.223.11.159";

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

void setup () {
Serial.begin(57600);
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(website))
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 ");
ether.browseUrl(PSTR("/comprueba_maq_ON.php?maquina="), "1", website, my_callback); }
}


Vassilis
Wed Feb 14, 2018 4:04 pm
Pinging 82.223.11.159 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.

Ping statistics for 82.223.11.159:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),


ramgc
Wed Feb 14, 2018 4:15 pm
[Vassilis – Wed Feb 14, 2018 4:04 pm] –
Pinging 82.223.11.159 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.

Ping statistics for 82.223.11.159:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

i just see that dont ping… but php work properly

put http://82.223.11.159/comprueba_maq_ON.php?maquina=1 and return 1 or 0

i dont know that happen


fpiSTM
Wed Feb 14, 2018 4:25 pm
For ENC28J60, I’ve used this lib which now support stm32 boards since version 2.0.5:
https://github.com/UIPEthernet/UIPEthernet

Vassilis
Wed Feb 14, 2018 5:52 pm
#include <SPI.h>
#include <EtherCard_STM.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 website[] PROGMEM = "82.223.11.159";
static byte server_ip[] = { 82,223,11,159};

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

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

if (ether.begin(sizeof Ethernet::buffer, mymac, PA4) == 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(website))
// Serial.println("DNS failed");

ether.copyIp(ether.hisip, server_ip);
ether.printIp("SRV: ", ether.hisip);

}

void loop () {
ether.packetLoop(ether.packetReceive());

if (millis() > timer) {
timer = millis() + 5000;
Serial.println();
Serial.print("<<< REQ ");
ether.browseUrl(PSTR("/comprueba_maq_ON.php?maquina="), "1", website, my_callback); }
}


ramgc
Thu Feb 15, 2018 3:41 pm
[Vassilis – Wed Feb 14, 2018 5:52 pm] –
#include <SPI.h>
#include <EtherCard_STM.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 website[] PROGMEM = "82.223.11.159";
static byte server_ip[] = { 82,223,11,159};

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

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

if (ether.begin(sizeof Ethernet::buffer, mymac, PA4) == 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(website))
// Serial.println("DNS failed");

ether.copyIp(ether.hisip, server_ip);
ether.printIp("SRV: ", ether.hisip);

}

void loop () {
ether.packetLoop(ether.packetReceive());

if (millis() > timer) {
timer = millis() + 5000;
Serial.println();
Serial.print("<<< REQ ");
ether.browseUrl(PSTR("/comprueba_maq_ON.php?maquina="), "1", website, my_callback); }
}


ramgc
Sun Feb 18, 2018 8:09 am
it is crazy…dont work this code for me, i try all but nothing, anything is read bad in my code, i dont know where :(

Vassilis
Mon Feb 19, 2018 9:32 am
I will try to give you another one basic code example. The new example uses a new buffer (buf) with 2048 bytes length. The received bytes are copied to the new buffer. If the <tail> variable is bigger that 0, you can read the received bytes.

As I said before, this is a very basic code example and can be improved a lot (ring buffer etc).

#include <SPI.h>
#include <EtherCard_STM.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;

#define MY_BUFFER_SIZE 2048
byte buf[MY_BUFFER_SIZE];
int tail = 0;

const char website[] PROGMEM = "82.223.11.159";
static byte server_ip[] = { 82,223,11,159};

// called when the client request is complete
static void my_callback (byte status, uint16_t off, uint16_t len) {
if((tail + len) < MY_BUFFER_SIZE){
for(int i=0;i<len;i++){
buf[tail++] = Ethernet::buffer[off + i];
}
}
}

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

if (ether.begin(sizeof Ethernet::buffer, mymac, PA4) == 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(website))
// Serial.println("DNS failed");

ether.copyIp(ether.hisip, server_ip);
ether.printIp("SRV: ", ether.hisip);

}

void loop () {
ether.packetLoop(ether.packetReceive());

if(tail > 0){
Serial.println(">>>");
for(int i=0;i<tail;i++){
Serial.write(buf[i]);
}
tail = 0; //Clear the buffer
}

if (millis() > timer) {
timer = millis() + 5000;
Serial.println();
Serial.print("<<< REQ ");
ether.browseUrl(PSTR("/comprueba_maq_ON.php?maquina="), "1", website, my_callback); }
}


ramgc
Tue Feb 20, 2018 8:44 am
Just work now, thanks, only this for finish my proyect.

Great forum, thanks thanks!!

now only have to process all bytes :roll: :lol:


Leave a Reply

Your email address will not be published. Required fields are marked *