Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
Major Release v1.0.5
Browse files Browse the repository at this point in the history
### Major Release v1.0.5

1. Add support to new [**`EthernetENC library`**](https://github.com/jandrassy/EthernetENC) for ENC28J60.
2. Add support to [`Ethernet2`](https://github.com/adafruit/Ethernet2), [`Ethernet3`](https://github.com/sstaub/Ethernet3) and [`EthernetLarge`](https://github.com/OPEnSLab-OSU/EthernetLarge) libraries on top of [`Ethernet`](https://www.arduino.cc/en/Reference/Ethernet).
2. Add debug feature. Clean up code. Restructure examples.
  • Loading branch information
khoih-prog authored Sep 17, 2020
1 parent 80f3ffc commit 4cf1f6c
Show file tree
Hide file tree
Showing 37 changed files with 2,985 additions and 1,551 deletions.
685 changes: 516 additions & 169 deletions README.md

Large diffs are not rendered by default.

249 changes: 87 additions & 162 deletions examples/AdvancedWebServer/AdvancedWebServer.ino
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
/****************************************************************************************************************************
AdvancedWebServer.h - Dead simple web-server for Ethernet shields
For STM32 with built-in Ethernet (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 Ethernet
EthernetWebServer_STM32 is a library for the STM32 run built-in Ethernet WebServer
Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases
Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32
Licensed under MIT license
Copyright (c) 2015, Majenko Technologies
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
Neither the name of Majenko Technologies nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Version: 1.0.4
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 26/02/2020 Initial coding for STM32 with built-in Ethernet (Nucleo-144, DISCOVERY, etc) and ENC28J60
1.0.1 K Hoang 28/02/2020 Add W5x00 Ethernet shields using Ethernet library
1.0.2 K Hoang 05/03/2020 Remove dependency on functional-vlpp
1.0.3 K Hoang 22/07/2020 Fix bug not closing client and releasing socket. Add features.
1.0.4 K Hoang 23/07/2020 Add support to all STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash.
AdvancedWebServer.h - Dead simple web-server for Ethernet shields
For STM32 with built-in Ethernet (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 Ethernet
EthernetWebServer_STM32 is a library for the STM32 run built-in Ethernet WebServer
Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases
Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32
Licensed under MIT license
Copyright (c) 2015, Majenko Technologies
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
Neither the name of Majenko Technologies nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Version: 1.0.5
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 26/02/2020 Initial coding for STM32 with built-in Ethernet (Nucleo-144, DISCOVERY, etc) and ENC28J60
1.0.1 K Hoang 28/02/2020 Add W5x00 Ethernet shields using Ethernet library
1.0.2 K Hoang 05/03/2020 Remove dependency on functional-vlpp
1.0.3 K Hoang 22/07/2020 Fix bug not closing client and releasing socket. Add features.
1.0.4 K Hoang 23/07/2020 Add support to all STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash.
1.0.5 K Hoang 16/09/2020 Add support to Ethernet2, Ethernet3, Ethernet Large for W5x00
Add support to new EthernetENC library for ENC28J60. Add debug feature.
*****************************************************************************************************************************/
/*
Currently support
Expand All @@ -58,115 +60,10 @@
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
*/

#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
defined(STM32WB) || defined(STM32MP1) )
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
#endif

#define DEBUG_ETHERNET_WEBSERVER_PORT Serial

// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 1

#define USE_BUILTIN_ETHERNET false
// If don't use USE_BUILTIN_ETHERNET, and USE_UIP_ETHERNET => use W5x00 with Ethernet library
#define USE_UIP_ETHERNET false //false

#if (USE_BUILTIN_ETHERNET)
#define ETHERNET_NAME "Built-in LAN8742A Ethernet"
#elif (USE_UIP_ETHERNET)
#define ETHERNET_NAME "ENC28J60 Ethernet Shield"
#else
#define ETHERNET_NAME "W5x00 Ethernet Shield"
#endif

#if defined(STM32F0)
#warning STM32F0 board selected
#define BOARD_TYPE "STM32F0"
#elif defined(STM32F1)
#warning STM32F1 board selected
#define BOARD_TYPE "STM32F1"
#elif defined(STM32F2)
#warning STM32F2 board selected
#define BOARD_TYPE "STM32F2"
#elif defined(STM32F3)
#warning STM32F3 board selected
#define BOARD_TYPE "STM32F3"
#elif defined(STM32F4)
#warning STM32F4 board selected
#define BOARD_TYPE "STM32F4"
#elif defined(STM32F7)
#warning STM32F7 board selected
#define BOARD_TYPE "STM32F7"
#elif defined(STM32L0)
#warning STM32L0 board selected
#define BOARD_TYPE "STM32L0"
#elif defined(STM32L1)
#warning STM32L1 board selected
#define BOARD_TYPE "STM32L1"
#elif defined(STM32L4)
#warning STM32L4 board selected
#define BOARD_TYPE "STM32L4"
#elif defined(STM32H7)
#warning STM32H7 board selected
#define BOARD_TYPE "STM32H7"
#elif defined(STM32G0)
#warning STM32G0 board selected
#define BOARD_TYPE "STM32G0"
#elif defined(STM32G4)
#warning STM32G4 board selected
#define BOARD_TYPE "STM32G4"
#elif defined(STM32WB)
#warning STM32WB board selected
#define BOARD_TYPE "STM32WB"
#elif defined(STM32MP1)
#warning STM32MP1 board selected
#define BOARD_TYPE "STM32MP1"
#else
#warning STM32 unknown board selected
#define BOARD_TYPE "STM32 Unknown"
#endif

#ifndef BOARD_NAME
#define BOARD_NAME BOARD_TYPE
#endif

#include <EthernetWebServer_STM32.h>

// Enter a MAC address and IP address for your controller below.
#define NUMBER_OF_MAC 20

byte mac[][NUMBER_OF_MAC] =
{
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
};
// Select the IP address according to your local network
IPAddress ip(192, 168, 2, 232);
#include "defines.h"

EthernetWebServer server(80);

int reqCount = 0; // number of requests received

const int led = 13;

void handleRoot()
Expand Down Expand Up @@ -252,17 +149,45 @@ void setup(void)
digitalWrite(led, 0);

Serial.begin(115200);
Serial.println("\nStart AdvancedWebServer on " + String(BOARD_NAME) + " board, running " + String(ETHERNET_NAME));

// start the ethernet connection and the server
// Use random mac
srand(1);
uint16_t index = rand() % NUMBER_OF_MAC;
//uint16_t index = random(NUMBER_OF_MAC);

Serial.println("\nStart AdvancedWebServer on " + String(BOARD_NAME) + ", using " + String(SHIELD_TYPE));

ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);

ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("MOSI:"), MOSI);
ET_LOGWARN1(F("MISO:"), MISO);
ET_LOGWARN1(F("SCK:"), SCK);
ET_LOGWARN1(F("SS:"), SS);
ET_LOGWARN(F("========================="));

#if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET)
// For other boards, to change if necessary
#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
// Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries
Ethernet.init (USE_THIS_SS_PIN);

#elif USE_ETHERNET3
// Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
#ifndef ETHERNET3_MAX_SOCK_NUM
#define ETHERNET3_MAX_SOCK_NUM 4
#endif

Ethernet.setCsPin (USE_THIS_SS_PIN);
Ethernet.init (ETHERNET3_MAX_SOCK_NUM);

#elif USE_CUSTOM_ETHERNET
// You have to add initialization for your Custom Ethernet here
// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
//Ethernet.init(USE_THIS_SS_PIN);

#endif //( ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
#endif

// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
uint16_t index = millis() % NUMBER_OF_MAC;
// Use Static IP
//Ethernet.begin(mac[index], ip);
// Use DHCP dynamic IP and random mac
Ethernet.begin(mac[index]);

server.on("/", handleRoot);
Expand Down
Loading

0 comments on commit 4cf1f6c

Please sign in to comment.