Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Arduino Codes
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Medics
Arduino Codes
Commits
c35b24ad
"git@git.soton.ac.uk:soclabs/cortex-m0-baseline.git" did not exist on "7e61ba6703d6928b7b5002837f79dd6b14d1f18e"
Commit
c35b24ad
authored
2 months ago
by
mhby1g21
Browse files
Options
Downloads
Patches
Plain Diff
wifi command test codes
parent
323fc9e8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wifi-test/wifi-test.ino
+129
-0
129 additions, 0 deletions
wifi-test/wifi-test.ino
with
129 additions
and
0 deletions
wifi-test/wifi-test.ino
0 → 100644
+
129
−
0
View file @
c35b24ad
#include
<WiFiNINA.h>
#include
<Servo.h>
// WiFi credentials
const
char
ssid
[]
=
"YourNetwork"
;
// Your network SSID
const
char
pass
[]
=
"YourPassword"
;
// Your network password
int
status
=
WL_IDLE_STATUS
;
// Server settings
WiFiServer
server
(
80
);
// Create servo objects
Servo
thumb
;
Servo
index
;
Servo
middle
;
Servo
ring
;
Servo
pinky
;
// Servo pins
const
int
thumbPin
=
2
;
const
int
indexPin
=
3
;
const
int
middlePin
=
4
;
const
int
ringPin
=
5
;
const
int
pinkyPin
=
6
;
void
setup
()
{
Serial
.
begin
(
9600
);
// Initialize servos
thumb
.
attach
(
thumbPin
);
index
.
attach
(
indexPin
);
middle
.
attach
(
middlePin
);
ring
.
attach
(
ringPin
);
pinky
.
attach
(
pinkyPin
);
// Set initial positions
thumb
.
write
(
90
);
index
.
write
(
90
);
middle
.
write
(
90
);
ring
.
write
(
90
);
pinky
.
write
(
90
);
// Check for WiFi module
if
(
WiFi
.
status
()
==
WL_NO_MODULE
)
{
Serial
.
println
(
"Communication with WiFi module failed!"
);
while
(
true
);
}
// Attempt to connect to WiFi network
while
(
status
!=
WL_CONNECTED
)
{
Serial
.
print
(
"Attempting to connect to Network: "
);
Serial
.
println
(
ssid
);
status
=
WiFi
.
begin
(
ssid
,
pass
);
delay
(
10000
);
}
Serial
.
println
(
"Connected to wifi"
);
printWiFiStatus
();
server
.
begin
();
}
void
loop
()
{
WiFiClient
client
=
server
.
available
();
if
(
client
)
{
String
currentLine
=
""
;
while
(
client
.
connected
())
{
if
(
client
.
available
())
{
char
c
=
client
.
read
();
if
(
c
==
'\n'
)
{
if
(
currentLine
.
length
()
==
0
)
{
client
.
println
(
"HTTP/1.1 200 OK"
);
client
.
println
(
"Content-type:text/html"
);
client
.
println
();
client
.
println
();
break
;
}
else
{
currentLine
=
""
;
}
}
else
if
(
c
!=
'\r'
)
{
currentLine
+=
c
;
}
// Process commands
// Format: /finger/angle (e.g., /thumb/180)
if
(
currentLine
.
startsWith
(
"GET /"
))
{
processCommand
(
currentLine
);
}
}
}
client
.
stop
();
}
}
void
processCommand
(
String
command
)
{
// Extract finger and angle from command
int
firstSlash
=
command
.
indexOf
(
'/'
);
int
secondSlash
=
command
.
indexOf
(
'/'
,
firstSlash
+
1
);
int
space
=
command
.
indexOf
(
' '
,
secondSlash
);
if
(
firstSlash
!=
-
1
&&
secondSlash
!=
-
1
&&
space
!=
-
1
)
{
String
finger
=
command
.
substring
(
firstSlash
+
1
,
secondSlash
);
int
angle
=
command
.
substring
(
secondSlash
+
1
,
space
).
toInt
();
// Constrain angle between 0 and 180
angle
=
constrain
(
angle
,
0
,
180
);
// Move appropriate servo
if
(
finger
==
"thumb"
)
thumb
.
write
(
angle
);
else
if
(
finger
==
"index"
)
index
.
write
(
angle
);
else
if
(
finger
==
"middle"
)
middle
.
write
(
angle
);
else
if
(
finger
==
"ring"
)
ring
.
write
(
angle
);
else
if
(
finger
==
"pinky"
)
pinky
.
write
(
angle
);
}
}
void
printWiFiStatus
()
{
Serial
.
print
(
"SSID: "
);
Serial
.
println
(
WiFi
.
SSID
());
IPAddress
ip
=
WiFi
.
localIP
();
Serial
.
print
(
"IP Address: "
);
Serial
.
println
(
ip
);
long
rssi
=
WiFi
.
RSSI
();
Serial
.
print
(
"Signal strength (RSSI):"
);
Serial
.
print
(
rssi
);
Serial
.
println
(
" dBm"
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment