Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
November 2021 Blimp Competition
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Shahrul Kamil bin Hassan
November 2021 Blimp Competition
Commits
2a6309ca
There was an error fetching the commit references. Please try again later.
Commit
2a6309ca
authored
4 years ago
by
Zhaoliang Zheng
Browse files
Options
Downloads
Patches
Plain Diff
master is able to send negative value
parent
7eca7876
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Code/ESP32_communication/test_more_variables/ESP32_master/ESP32_master.ino
+91
-0
91 additions, 0 deletions
...ication/test_more_variables/ESP32_master/ESP32_master.ino
with
91 additions
and
0 deletions
Code/ESP32_communication/test_more_variables/ESP32_master/ESP32_master.ino
0 → 100644
+
91
−
0
View file @
2a6309ca
//-----------------------------------------------------------
//ESP-NOW: Transmitter
//Ref: Random Nerd Tutorials https://randomnerdtutorials.com
//-----------------------------------------------------------
#include
<esp_now.h>
#include
<WiFi.h>
//-------------------------------------------------------------------------------------
uint8_t
RxMACaddress
[]
=
{
0xC4
,
0xDD
,
0x57
,
0x9E
,
0x91
,
0x74
};
String
strdata
=
""
;
String
valdata
=
""
;
int
count
=
0
;
//-------------------------------------------------------------------------------------
typedef
struct
TxStruct
{
String
StrD
;
double
ValD
;
}
TxStruct
;
TxStruct
sentData
;
//-------------------------------------------------------------------------------------
void
OnDataSent
(
const
uint8_t
*
mac_addr
,
esp_now_send_status_t
status
)
//callback function
{
Serial
.
print
(
"
\r\n
Last Packet Send Status:
\t
"
);
Serial
.
println
(
status
==
ESP_NOW_SEND_SUCCESS
?
"Delivery Success"
:
"Delivery Fail"
);
}
//======================================================================================
void
setup
()
{
Serial
.
begin
(
9600
);
WiFi
.
mode
(
WIFI_STA
);
//------------------------------------------------------------------------------------
if
(
esp_now_init
()
!=
ESP_OK
)
{
Serial
.
println
(
"Error initializing ESP-NOW"
);
return
;
}
//-------------------------------------------------------------------------------------
esp_now_register_send_cb
(
OnDataSent
);
//-------------------------------------------------------------------------------------
esp_now_peer_info_t
peerInfo
;
memcpy
(
peerInfo
.
peer_addr
,
RxMACaddress
,
6
);
peerInfo
.
channel
=
0
;
peerInfo
.
encrypt
=
false
;
//-------------------------------------------------------------------------------------
if
(
esp_now_add_peer
(
&
peerInfo
)
!=
ESP_OK
)
{
Serial
.
println
(
"Failed to add peer"
);
return
;
}
}
//======================================================================================
void
loop
()
{
while
(
Serial
.
available
()
>
0
){
int
inChar
=
Serial
.
read
();
/*
sentData.potVal = inChar - '0';
delay(10);
esp_now_send(RxMACaddress, (uint8_t *) &sentData, sizeof(sentData));
delay(500);
*/
strdata
+=
char
(
inChar
);
delay
(
10
);
count
+=
1
;
if
(
count
==
3
){
sentData
.
StrD
=
strdata
;
Serial
.
println
(
sentData
.
StrD
);
}
if
(
isDigit
(
inChar
)
||
inChar
==
'.'
||
inChar
==
'-'
){
valdata
+=
char
(
inChar
);
}
if
(
inChar
==
'\n'
){
sentData
.
ValD
=
valdata
.
toDouble
();
Serial
.
println
(
sentData
.
ValD
);
esp_err_t
result
=
esp_now_send
(
RxMACaddress
,
(
uint8_t
*
)
&
sentData
,
sizeof
(
sentData
));
// esp_now_send(RxMACaddress, (uint8_t *) &sentData, sizeof(sentData));
//-------------------------------------------------------------------------------------
if
(
result
==
ESP_OK
)
Serial
.
println
(
"Sent with success"
);
else
Serial
.
println
(
"Error sending the data"
);
//-------------------------------------------------------------------------------------
delay
(
500
);
strdata
=
""
;
valdata
=
""
;
count
=
0
;
}
}
//-------------------------------------------------------------------------------------
}
This diff is collapsed.
Click to expand it.
Preview
0%
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