Skip to content

Commit fc11945

Browse files
committed
Basic white control via TCP
0 parents  commit fc11945

File tree

9 files changed

+216
-0
lines changed

9 files changed

+216
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.pio
2+
.vscode/.browse.c_cpp.db*
3+
.vscode/c_cpp_properties.json
4+
.vscode/launch.json
5+
.vscode/ipch
6+
src/secret.h

.vscode/extensions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
// See http://go.microsoft.com/fwlink/?LinkId=827846
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
"platformio.platformio-ide"
6+
]
7+
}

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"cSpell.diagnosticLevel": "Hint"
3+
}

.vscode/tasks.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
]
5+
}

include/README

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

lib/README

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
This directory is intended for project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link into executable file.
4+
5+
The source code of each library should be placed in a an own separate directory
6+
("lib/your_library_name/[here are source files]").
7+
8+
For example, see a structure of the following two libraries `Foo` and `Bar`:
9+
10+
|--lib
11+
| |
12+
| |--Bar
13+
| | |--docs
14+
| | |--examples
15+
| | |--src
16+
| | |- Bar.c
17+
| | |- Bar.h
18+
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19+
| |
20+
| |--Foo
21+
| | |- Foo.c
22+
| | |- Foo.h
23+
| |
24+
| |- README --> THIS FILE
25+
|
26+
|- platformio.ini
27+
|--src
28+
|- main.c
29+
30+
and a contents of `src/main.c`:
31+
```
32+
#include <Foo.h>
33+
#include <Bar.h>
34+
35+
int main (void)
36+
{
37+
...
38+
}
39+
40+
```
41+
42+
PlatformIO Library Dependency Finder will find automatically dependent
43+
libraries scanning project source files.
44+
45+
More information about PlatformIO Library Dependency Finder
46+
- https://docs.platformio.org/page/librarymanager/ldf.html

platformio.ini

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; https://docs.platformio.org/page/projectconf.html
10+
11+
[env:nano_33_iot]
12+
platform = atmelsam
13+
board = nano_33_iot
14+
framework = arduino
15+
lib_deps = arduino-libraries/WiFiNINA@^1.8.13

src/main.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#include <Arduino.h>
2+
#include <WiFiNINA.h>
3+
4+
#include "secret.h"
5+
6+
#define WHITE 12
7+
#define RED 3
8+
#define GREEN 2
9+
#define BLUE 10
10+
11+
WiFiServer server(80);
12+
13+
void setup() {
14+
//Initialize serial and wait for port to open:
15+
Serial.begin(9600);
16+
while (!Serial) {
17+
; // wait for serial port to connect. Needed for native USB port only
18+
}
19+
20+
// check for the WiFi module:
21+
if (WiFi.status() == WL_NO_MODULE) {
22+
Serial.println("Communication with WiFi module failed!");
23+
// don't continue
24+
while (true)
25+
;
26+
}
27+
28+
String fv = WiFi.firmwareVersion();
29+
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
30+
Serial.println("Please upgrade the firmware");
31+
}
32+
33+
int status = WL_IDLE_STATUS; // the WiFi radio's status
34+
// attempt to connect to WiFi network:
35+
while (status != WL_CONNECTED) {
36+
Serial.print("Attempting to connect to WPA SSID: ");
37+
Serial.println(SECRET_SSID);
38+
// Connect to WPA/WPA2 network:
39+
status = WiFi.begin(SECRET_SSID, SECRET_PASS);
40+
delay(1000);
41+
}
42+
43+
// you're connected now, so print out the data:
44+
Serial.print("You're connected to the network");
45+
46+
// print your board's IP address:
47+
IPAddress ip = WiFi.localIP();
48+
Serial.print("IP Address: ");
49+
Serial.println(ip);
50+
51+
server.begin();
52+
}
53+
54+
void loop() {
55+
WiFiClient client = server.available();
56+
57+
if (client) {
58+
Serial.println("Client available");
59+
60+
char buffer[256];
61+
int index = 0;
62+
while (client.connected()) {
63+
if (client.available()) {
64+
char c = client.read();
65+
if (c == '\n') {
66+
buffer[index] = '\0';
67+
68+
int val = atoi(buffer);
69+
70+
analogWrite(WHITE, val);
71+
72+
// reset buffer index
73+
index = 0;
74+
} else {
75+
// append char at end of buffer
76+
buffer[index] = c;
77+
index++;
78+
}
79+
}
80+
}
81+
Serial.println("Client disconnected");
82+
client.stop();
83+
}
84+
}

test/README

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
This directory is intended for PlatformIO Unit Testing and project tests.
3+
4+
Unit Testing is a software testing method by which individual units of
5+
source code, sets of one or more MCU program modules together with associated
6+
control data, usage procedures, and operating procedures, are tested to
7+
determine whether they are fit for use. Unit testing finds problems early
8+
in the development cycle.
9+
10+
More information about PlatformIO Unit Testing:
11+
- https://docs.platformio.org/page/plus/unit-testing.html

0 commit comments

Comments
 (0)