ENC28J60 +php crash on stm32f103ve

Working libraries, libraries being ported and related hardware
ramgc
Posts: 9
Joined: Fri Dec 01, 2017 11:39 am

ENC28J60 +php crash on stm32f103ve

Post by 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

Code: Select all

#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);  }
}
php have to return '1' but return many characters wrong. Serial print is off in my design, if put this ''http://www.gonzalogalvan.es/arduino/sav ... ?consumo=5'' of other developer just equal...

i am very lost in this, only need read return server...

thanks, i am learning in this forum each day

stevestrong
Posts: 2059
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: ENC28J60 +php crash on stm32f103ve

Post by 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

User avatar
Vassilis
Posts: 336
Joined: Thu May 21, 2015 6:42 am
Location: Thessaloniki, Greece
Contact:

Re: ENC28J60 +php crash on stm32f103ve

Post by 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
Posts: 9
Joined: Fri Dec 01, 2017 11:39 am

Re: ENC28J60 +php crash on stm32f103ve

Post by ramgc » Wed Feb 14, 2018 3:21 pm

Vassilis wrote:
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

Code: Select all

#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);  }
}

my server is 82.223.11.159

User avatar
Vassilis
Posts: 336
Joined: Thu May 21, 2015 6:42 am
Location: Thessaloniki, Greece
Contact:

Re: ENC28J60 +php crash on stm32f103ve

Post by Vassilis » Wed Feb 14, 2018 4:04 pm

Code: Select all

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
Posts: 9
Joined: Fri Dec 01, 2017 11:39 am

Re: ENC28J60 +php crash on stm32f103ve

Post by ramgc » Wed Feb 14, 2018 4:15 pm

Vassilis wrote:
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
Posts: 315
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: ENC28J60 +php crash on stm32f103ve

Post by 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

User avatar
Vassilis
Posts: 336
Joined: Thu May 21, 2015 6:42 am
Location: Thessaloniki, Greece
Contact:

Re: ENC28J60 +php crash on stm32f103ve

Post by Vassilis » Wed Feb 14, 2018 5:52 pm

Code: Select all

#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);  }
}

[webClient]

<<< REQ >>>
HTTP/1.1 200 OK
Date: Wed, 14 Feb 2018 17:44:52 GMT
Server: Apache
X-Powered-By: PHP/7.0.23
X-Frame-Options: SAMEORIGIN
X-Mod-Pagespeed: 1.9.32.14-0
Cache-Control: max-age=0, no-cache
Content-Length: 2
Connection: close
Content-Type: text/html; charset=UTF-8

0 ...
The library that is suggested by fpiSTM is compatible with the Arduino Ethernet library (big advantage !) but it produces larger .bin files. It's excellent library though. I have used both of these two libraries.

ramgc
Posts: 9
Joined: Fri Dec 01, 2017 11:39 am

Re: ENC28J60 +php crash on stm32f103ve

Post by ramgc » Thu Feb 15, 2018 3:41 pm

Vassilis wrote:
Wed Feb 14, 2018 5:52 pm

Code: Select all

#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);  }
}

[webClient]

<<< REQ >>>
HTTP/1.1 200 OK
Date: Wed, 14 Feb 2018 17:44:52 GMT
Server: Apache
X-Powered-By: PHP/7.0.23
X-Frame-Options: SAMEORIGIN
X-Mod-Pagespeed: 1.9.32.14-0
Cache-Control: max-age=0, no-cache
Content-Length: 2
Connection: close
Content-Type: text/html; charset=UTF-8

0 ...
The library that is suggested by fpiSTM is compatible with the Arduino Ethernet library (big advantage !) but it produces larger .bin files. It's excellent library though. I have used both of these two libraries.


I dont know that happen, but receive bad characters:

i have a lcd:

lcd.setCursor(0, 0);

lcd.print((int) Ethernet::buffer[0]);
lcd.setCursor(3, 0);
lcd.print((int) Ethernet::buffer[1]);
lcd.setCursor(6, 0);
lcd.print((int) Ethernet::buffer[2]);

just received t - i - i

...

ramgc
Posts: 9
Joined: Fri Dec 01, 2017 11:39 am

Re: ENC28J60 +php crash on stm32f103ve

Post by 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 :(

Post Reply