Added built-in HTTP Server
This commit is contained in:
@@ -2,13 +2,11 @@
|
||||
CANbus to http bridge using esp32.
|
||||
It's purpose is to be a bridge between a CAN-Bus and a HTTP-Server.
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
You can visualize CAN-Frame using a visualization library such as Matplotlib.
|
||||
|
||||

|
||||
|
||||
I inspired from [here](https://github.com/c3re/can2mqtt).
|
||||

|
||||
|
||||
# Software requirement
|
||||
esp-idf v4.2-dev-2243 or later.
|
||||
@@ -100,7 +98,13 @@ idf.py flash
|
||||

|
||||
|
||||
## WiFi Setting
|
||||

|
||||

|
||||
|
||||
You can use static IP.
|
||||

|
||||
|
||||
Connect using mDNS.
|
||||

|
||||
|
||||
## HTTP Server Setting
|
||||

|
||||
@@ -111,8 +115,8 @@ The file can2http.csv has three columns.
|
||||
In the first column you need to specify the CAN Frame type.
|
||||
The CAN frame type is either S(Standard frame) or E(Extended frame).
|
||||
In the second column you have to specify the CAN-ID as a __hexdecimal number__.
|
||||
In the last column you have to specify the HTTP-POST-Path.
|
||||
Each CAN-ID and each HTTP-POST-Path is allowed to appear only once in the whole file.
|
||||
In the last column you have to specify the HTTP-POST-Path of external HTTP server.
|
||||
Each CAN-ID is allowed to appear only once in the whole file.
|
||||
|
||||
```
|
||||
S,101,/post
|
||||
@@ -121,20 +125,39 @@ S,103,/post
|
||||
E,103,/post
|
||||
```
|
||||
|
||||
When a Standard CAN frame with ID 0x101 is received, POST with the "/post" PATH.
|
||||
When a Extended CAN frame with ID 0x101 is received, POST with the "/post" PATH.
|
||||
|
||||
# POST Parameter Example
|
||||
```
|
||||
{'canid':257, 'frame': 'standard', 'data': [1,2,3,4,5,6,7,8]}
|
||||
{'canid':257, 'frame': 'extended', 'data': [1,2,3,4,5,6,7,8]}
|
||||
{'canid':259, 'frame': 'standard', 'data': [1,2,3,4,5,6,7,8]}
|
||||
{'canid':259, 'frame': 'extended', 'data': [1,2,3,4,5,6,7,8]}
|
||||
```
|
||||
|
||||
When a CAN frame with ID 0x101 is received, POST with the 'canid':257.
|
||||
When a CAN frame with ID 0x103 is received, POST with the 'canid':259.
|
||||
|
||||
POST Parameter Example:
|
||||
```
|
||||
{"canid":257, "frame": "standard", "data": [16, 17, 18]}
|
||||
{"canid":257, "frame": "extended", "data": [16, 17, 18]}
|
||||
{"canid":259, "frame": "standard", "data": [16, 17, 18]}
|
||||
{"canid":259, "frame": "extended", "data": [16, 17, 18]}
|
||||
```
|
||||
|
||||
# Definition from HTTP to CANbus
|
||||
When HTTP POST is received, it is sent by CANBus according to csv/http2can.csv.
|
||||
Other than this, it is the same as csv/can2http.csv.
|
||||
In the last column you have to specify the HTTP-POST-Path of built-in HTTP server.
|
||||
|
||||
```
|
||||
S,201,/receive
|
||||
E,201,/receive
|
||||
S,203,/receive
|
||||
E,203,/receive
|
||||
```
|
||||
|
||||
When receiving the {"canid": 513, "frame": "standard", "data": [16, 17, 18]}, send the Standard CAN frame with ID 0x201.
|
||||
When receiving the {"canid": 515, "frame": "extended", "data": [16, 17, 18]}, send the Extended CAN frame with ID 0x201.
|
||||
|
||||
|
||||
# Send message using curl
|
||||
```
|
||||
$ curl -X POST -H "Content-Type: application/json" -d '{"canid": 513, "frame": "standard", "data": [16, 17, 18]}' http://esp32-server.local:8000/api/twai/send
|
||||
|
||||
$ curl -X POST -H "Content-Type: application/json" -d '{"canid": 513, "frame": "extended", "data": [16, 17, 18]}' http://esp32-server.local:8000/api/twai/send
|
||||
```
|
||||
|
||||
# HTTP Server Using Tornado
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user