This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
455 additions
and
182 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
This directory is intended for project specific (private) libraries. | ||
PlatformIO will compile them to static libraries and link into executable file. | ||
|
||
The source code of each library should be placed in a an own separate directory | ||
("lib/your_library_name/[here are source files]"). | ||
|
||
For example, see a structure of the following two libraries `Foo` and `Bar`: | ||
|
||
|--lib | ||
| | | ||
| |--Bar | ||
| | |--docs | ||
| | |--examples | ||
| | |--src | ||
| | |- Bar.c | ||
| | |- Bar.h | ||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html | ||
| | | ||
| |--Foo | ||
| | |- Foo.c | ||
| | |- Foo.h | ||
| | | ||
| |- README --> THIS FILE | ||
| | ||
|- platformio.ini | ||
|--src | ||
|- main.c | ||
|
||
and a contents of `src/main.c`: | ||
``` | ||
#include <Foo.h> | ||
#include <Bar.h> | ||
|
||
int main (void) | ||
{ | ||
... | ||
} | ||
|
||
``` | ||
|
||
PlatformIO Library Dependency Finder will find automatically dependent | ||
libraries scanning project source files. | ||
|
||
More information about PlatformIO Library Dependency Finder | ||
- https://docs.platformio.org/page/librarymanager/ldf.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
; SPDX-FileCopyrightText: 2024 Junde Yhi <[email protected]> | ||
; SPDX-License-Identifier: MIT | ||
|
||
[platformio] | ||
name = MyLampThing-0 | ||
|
||
[env:uno] | ||
platform = atmelavr | ||
board = uno | ||
framework = arduino | ||
lib_deps = | ||
quicksander/ArduinoHttpServer@~0.10 | ||
arduino-libraries/Ethernet@^2.0 | ||
symlink://../../ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/*! | ||
SPDX-FileCopyrightText: 2024 Junde Yhi <[email protected]> | ||
SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include <string.h> | ||
|
||
#include <ArduinoHttpServer.h> | ||
#include <Ethernet.h> | ||
#include <tinywot/core.h> | ||
|
||
static char const application_json[] = "application/json"; | ||
|
||
static unsigned char t_scratchpad[32] = {}; | ||
static struct tinywot_request t_request = {}; | ||
static struct tinywot_response t_response = {}; | ||
static struct tinywot_thing t_thing = {}; | ||
|
||
static byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; | ||
static byte ip[] = { 10, 36, 24, 51 }; | ||
static EthernetServer server = EthernetServer(80); | ||
|
||
void setup(void) { | ||
pinMode(13, OUTPUT); | ||
digitalWrite(13, LOW); | ||
|
||
Ethernet.begin(mac, ip); | ||
server.begin(); | ||
} | ||
|
||
void loop(void) { | ||
enum tinywot_status t_status = TINYWOT_STATUS_UNKNOWN; | ||
|
||
Ethernet.maintain(); | ||
|
||
EthernetClient eth_client = server.available(); | ||
if (!eth_client) { | ||
return; | ||
} | ||
|
||
ArduinoHttpServer::StreamHttpRequest<256> httpRequest(eth_client); | ||
|
||
if (httpRequest.readRequest()) { | ||
ArduinoHttpServer::Method method = httpRequest.getMethod(); | ||
|
||
if (method == ArduinoHttpServer::Method::Get) { | ||
t_request.op = TINYWOT_OPERATION_TYPE_READPROPERTY; | ||
} else if (method == ArduinoHttpServer::Method::Post) { | ||
t_request.op = TINYWOT_OPERATION_TYPE_WRITEPROPERTY; | ||
} else { | ||
t_request.op = TINYWOT_OPERATION_TYPE_UNKNOWN; | ||
} | ||
|
||
const String& href = httpRequest.getResource().toString(); | ||
memcpy(t_request.target, href.c_str(), href.length()); | ||
|
||
t_response.payload.content = t_scratchpad; | ||
|
||
t_status = tinywot_thing_process_request(&t_thing, &t_response, &t_request); | ||
if (t_status != TINYWOT_STATUS_SUCCESS) { | ||
client.stop(); | ||
memset(t_scratchpad, 0, sizeof(t_scratchpad)); | ||
memset(&t_request, 0, sizeof(struct tinywot_request)); | ||
memset(&t_response, 0, sizeof(struct tinywot_response)); | ||
return; | ||
} | ||
|
||
// if (method == ArduinoHttpServer::Method::Get) { | ||
// if (httpRequest.getResource().toString() == "/status") { | ||
// ArduinoHttpServer::StreamHttpReply response(client, application_json); | ||
// response.send(digitalRead(13) == HIGH ? "true" : "false"); | ||
// } else { | ||
// ArduinoHttpServer::StreamHttpErrorReply response(client, application_json, "404"); | ||
// } | ||
// } else { | ||
// ArduinoHttpServer::StreamHttpErrorReply response(client, application_json, "405"); | ||
// } | ||
} | ||
|
||
client.stop(); | ||
|
||
memset(t_scratchpad, 0, sizeof(t_scratchpad)); | ||
memset(&t_request, 0, sizeof(struct tinywot_request)); | ||
memset(&t_response, 0, sizeof(struct tinywot_response)); | ||
} |
Oops, something went wrong.