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

Commit

Permalink
v1.6.2 for ESP32 + ENC28J60
Browse files Browse the repository at this point in the history
#### Releases v1.6.2

1. Initial coding to port [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer) to ESP32 boards using ENC28J60 Ethernet.
2. Bump up to `v1.6.2` to sync with [AsyncWebServer_ESP32_ENC v1.6.2](https://github.com/khoih-prog/AsyncWebServer_ESP32_ENC).
3. Use `allman astyle`
  • Loading branch information
khoih-prog authored Nov 28, 2022
1 parent 3e00bad commit e11b91e
Show file tree
Hide file tree
Showing 65 changed files with 22,009 additions and 4 deletions.
76 changes: 76 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
## Contributing to AsyncWebServer_ESP32_ENC

### Reporting Bugs

Please report bugs in AsyncWebServer_ESP32_ENC if you find them.

However, before reporting a bug please check through the following:

* [Existing Open Issues](https://github.com/khoih-prog/AsyncWebServer_ESP32_ENC/issues) - someone might have already encountered this.

If you don't find anything, please [open a new issue](https://github.com/khoih-prog/AsyncWebServer_ESP32_ENC/issues/new).

### How to submit a bug report

Please ensure to specify the following:

* Arduino IDE version (e.g. 1.8.19) or Platform.io version
* Board Core Version (e.g. ESP32 core v2.0.5)
* Contextual information (e.g. what you were trying to achieve)
* Simplest possible steps to reproduce
* Anything that might be relevant in your opinion, such as:
* Operating system (Windows, Ubuntu, etc.) and the output of `uname -a`
* Network configuration


### Example

```
Arduino IDE version: 1.8.19
ESP32_DEV board
ESP32 core v2.0.5
OS: Ubuntu 20.04 LTS
Linux xy-Inspiron-3593 5.15.0-53-generic #59~20.04.1-Ubuntu SMP Thu Oct 20 15:10:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Context:
I encountered a crash while using this library
Steps to reproduce:
1. ...
2. ...
3. ...
4. ...
```

### Additional context

Add any other context about the problem here.

---

### Sending Feature Requests

Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.

There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/AsyncWebServer_ESP32_ENC/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.

---

### Sending Pull Requests

Pull Requests with changes and fixes are also welcome!

Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)

1. Change directory to the library GitHub

```
xy@xy-Inspiron-3593:~$ cd Arduino/xy/AsyncWebServer_ESP32_ENC_GitHub/
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncWebServer_ESP32_ENC_GitHub$
```

2. Issue astyle command

```
xy@xy-Inspiron-3593:~/Arduino/xy/AsyncWebServer_ESP32_ENC_GitHub$ bash utils/restyle.sh
```

8 changes: 4 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

Expand Down Expand Up @@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found.
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
along with this program. If not, see <http://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

Expand All @@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
<http://www.gnu.org/licenses/>.

The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
1,840 changes: 1,840 additions & 0 deletions README.md

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# AsyncWebServer_ESP32_ENC

[![arduino-library-badge](https://www.ardu-badge.com/badge/AsyncWebServer_ESP32_ENC.svg?)](https://www.ardu-badge.com/AsyncWebServer_ESP32_ENC)
[![GitHub release](https://img.shields.io/github/release/khoih-prog/AsyncWebServer_ESP32_ENC.svg)](https://github.com/khoih-prog/AsyncWebServer_ESP32_ENC/releases)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/AsyncWebServer_ESP32_ENC.svg)](http://github.com/khoih-prog/AsyncWebServer_ESP32_ENC/issues)

<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Donate to my libraries using BuyMeACoffee" style="height: 50px !important;width: 181px !important;" ></a>
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-orange.svg?logo=buy-me-a-coffee&logoColor=FFDD00" style="height: 20px !important;width: 200px !important;" ></a>
<a href="https://profile-counter.glitch.me/khoih-prog/count.svg" title="Total khoih-prog Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog/count.svg" style="height: 30px;width: 200px;"></a>
<a href="https://profile-counter.glitch.me/khoih-prog-AsyncWebServer_ESP32_ENC/count.svg" title="Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-AsyncWebServer_ESP32_ENC/count.svg" style="height: 30px;width: 200px;"></a>

---
---

## Table of contents

* [Changelog](#changelog)
* [Releases v1.6.2](#releases-v162)



---
---

## Changelog

#### Releases v1.6.2

1. Initial coding to port [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer) to ESP32 boards using ENC28J60 Ethernet.
2. Bump up to `v1.6.2` to sync with [AsyncWebServer_ESP32_ENC v1.6.2](https://github.com/khoih-prog/AsyncWebServer_ESP32_ENC).
3. Use `allman astyle`

Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
/****************************************************************************************************************************
AsyncMultiWebServer_ESP32_ENC.ino
For ENC28J60 Ethernet in ESP32 (ESP32 + ENC28J60)
AsyncWebServer_ESP32_ENC is a library for the Ethernet ENC28J60 in ESSP32 to run AsyncWebServer
Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_ENC
Licensed under GPLv3 license
*****************************************************************************************************************************/

#if !( defined(ESP32) )
#error This code is designed for (ESP32 + ENC28J60) to run on ESP32 platform! Please check your Tools->Board setting.
#endif

#include <Arduino.h>

#define _ASYNC_WEBSERVER_LOGLEVEL_ 2

// 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, 0xFE, 0x01 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 },
{ 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 },
};

// Select the IP address according to your local network
IPAddress myIP(192, 168, 2, 232);
IPAddress myGW(192, 168, 2, 1);
IPAddress mySN(255, 255, 255, 0);

// Google DNS Server IP
IPAddress myDNS(8, 8, 8, 8);

#include <AsyncTCP.h>

#include <AsyncWebServer_ESP32_ENC.h>

// Optional values to override default settings
//#define SPI_HOST 1
//#define SPI_CLOCK_MHZ 8

// Must connect INT to GPIOxx or not working
//#define INT_GPIO 4

//#define MISO_GPIO 19
//#define MOSI_GPIO 23
//#define SCK_GPIO 18
//#define CS_GPIO 5
// Optional values to override default settings

unsigned int analogReadPin [] = { 12, 13, 14 };

#define BUFFER_SIZE 500

#define HTTP_PORT1 8080
#define HTTP_PORT2 8081
#define HTTP_PORT3 8082

AsyncWebServer* server1;
AsyncWebServer* server2;
AsyncWebServer* server3;

AsyncWebServer* multiServer [] = { server1, server2, server3 };
uint16_t http_port [] = { HTTP_PORT1, HTTP_PORT2, HTTP_PORT3 };

#define NUM_SERVERS ( sizeof(multiServer) / sizeof(AsyncWebServer*) )

unsigned int serverIndex;

String createBuffer()
{
char temp[BUFFER_SIZE];

memset(temp, 0, sizeof(temp));

int sec = millis() / 1000;
int min = sec / 60;
int hr = min / 60;
int day = hr / 24;

snprintf(temp, BUFFER_SIZE - 1,
"<html>\
<head>\
<meta http-equiv='refresh' content='5'/>\
<title>%s</title>\
<style>\
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
</style>\
</head>\
<body>\
<h1>Hello from %s</h1>\
<h2>running AsyncMultiWebServer_ESP32_ENC</h2>\
<h3>on %s</h3>\
<h3>Uptime: %d d %02d:%02d:%02d</h3>\
</body>\
</html>", BOARD_NAME, BOARD_NAME, SHIELD_TYPE, day, hr, min % 60, sec % 60);

return temp;
}


void handleRoot(AsyncWebServerRequest * request)
{
String message = createBuffer();
request->send(200, F("text/html"), message);
}

String createNotFoundBuffer(AsyncWebServerRequest * request)
{
String message;

message.reserve(500);

message = F("File Not Found\n\n");

message += F("URI: ");
message += request->url();
message += F("\nMethod: ");
message += (request->method() == HTTP_GET) ? F("GET") : F("POST");
message += F("\nArguments: ");
message += request->args();
message += F("\n");

for (uint8_t i = 0; i < request->args(); i++)
{
message += " " + request->argName(i) + ": " + request->arg(i) + "\n";
}

return message;
}

void handleNotFound(AsyncWebServerRequest * request)
{
String message = createNotFoundBuffer(request);
request->send(404, F("text/plain"), message);
}

void setup()
{
Serial.begin(115200);

while (!Serial && millis() < 5000);

delay(200);

Serial.print(F("\nStart AsyncMultiWebServer_ESP32_ENC on "));
Serial.print(BOARD_NAME);
Serial.print(F(" with "));
Serial.println(SHIELD_TYPE);
Serial.println(ASYNC_WEBSERVER_ESP32_ENC_VERSION);

AWS_LOGWARN(F("Default SPI pinout:"));
AWS_LOGWARN1(F("MOSI:"), MOSI_GPIO);
AWS_LOGWARN1(F("MISO:"), MISO_GPIO);
AWS_LOGWARN1(F("SCK:"), SCK_GPIO);
AWS_LOGWARN1(F("CS:"), CS_GPIO);
AWS_LOGWARN1(F("INT:"), INT_GPIO);
AWS_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ);
AWS_LOGWARN(F("========================="));

///////////////////////////////////

// To be called before ETH.begin()
ESP32_ENC_onEvent();

// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
uint16_t index = millis() % NUMBER_OF_MAC;

//bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ,
// int SPI_HOST, uint8_t *ENC28J60_Mac = ENC28J60_Default_Mac);
//ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, SPI_HOST );
ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, SPI_HOST, mac[index] );

// Static IP, leave without this line to get IP via DHCP
//bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0);
ETH.config(myIP, myGW, mySN, myDNS);

ESP32_ENC_waitForConnect();

///////////////////////////////////


Serial.print("\nConnected to network. IP = ");
Serial.println(ETH.localIP());

for (serverIndex = 0; serverIndex < NUM_SERVERS; serverIndex++)
{
multiServer[serverIndex] = new AsyncWebServer(http_port[serverIndex]);

if (multiServer[serverIndex])
{
Serial.printf("Initialize multiServer OK, serverIndex = %d, port = %d\n", serverIndex, http_port[serverIndex]);
}
else
{
Serial.printf("Error initialize multiServer, serverIndex = %d\n", serverIndex);

while (1);
}

multiServer[serverIndex]->on("/", HTTP_GET, [](AsyncWebServerRequest * request)
{
handleRoot(request);
});

multiServer[serverIndex]->on("/hello", HTTP_GET, [](AsyncWebServerRequest * request)
{
String message = F("Hello from AsyncMultiWebServer_ESP32_ENC using ENC28J60 Ethernet, running on ");
message += BOARD_NAME;

request->send(200, "text/plain", message);
});

multiServer[serverIndex]->onNotFound([](AsyncWebServerRequest * request)
{
handleNotFound(request);
});

multiServer[serverIndex]->begin();

Serial.printf("HTTP server started at ports %d\n", http_port[serverIndex]);
}
}

void loop()
{
}
Loading

0 comments on commit e11b91e

Please sign in to comment.