Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DidacticNetwork
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Automate
Agent sessions
Code
Merge requests
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
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
letsgoING
Libraries
DidacticNetwork
Commits
783b6c15
Verified
Commit
783b6c15
authored
Feb 23, 2024
by
Anian Bühler
Browse files
Options
Downloads
Patches
Plain Diff
minor changes
parent
13121e38
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/Advanced/sPSN_Client1/sPSN_Client1.ino
+31
-31
31 additions, 31 deletions
examples/Advanced/sPSN_Client1/sPSN_Client1.ino
with
31 additions
and
31 deletions
examples/Advanced/sPSN_Client1/sPSN_Client1.ino
+
31
−
31
View file @
783b6c15
...
...
@@ -31,16 +31,16 @@
#define THRESHOLD 10 // Schwellwert für min. Wertänderung
char
topicPublish
[
MAX_LEN_TOPICS
]
=
"poti
Val
"
;
//Topic unter dem (eigene) Daten veröffentlicht werden
char
topicSubscribe
[
MAX_LEN_TOPICS
]
=
"btn
State
"
;
//Topic (von anderem TN) das abboniert werden soll
char
topicPublish
[
MAX_LEN_TOPICS
]
=
"poti
Nr
"
;
//
Topic unter dem (eigene) Daten veröffentlicht werden
char
topicSubscribe
[
MAX_LEN_TOPICS
]
=
"btn
Nr
"
;
//
Topic (von anderem TN) das abboniert werden soll
SoftwareSerial
sSerial
(
10
,
11
);
// Erzeuge SoftwareSerial-Instanz mit Rx = Pin10 -> Empfänger | Tx = Pin11 -> Sender
DidacticPSNetClient
psnClient
;
// Erzeuge PubSub-Client-Instanz
// Callback-Funktion - wird beim Empfang neuer Daten aufgerufen
void
newData
(
char
*
topic
,
char
*
payload
)
{
void
newData
(
char
*
topic
,
char
*
payload
)
{
Serial
.
print
(
"New data from topic "
);
Serial
.
print
(
topic
);
Serial
.
print
(
": "
);
...
...
@@ -49,14 +49,15 @@ void newData(char* topic, char* payload) {
boolean
static
stateLED
=
false
;
// Wechsle Zustand der Variable "stateLED" wenn Taster beim Sender gedrueckt wurde
if
(
payload
[
0
]
==
'1'
){
if
(
payload
[
0
]
==
'1'
)
{
stateLED
=
!
stateLED
;
digitalWrite
(
LED_PIN
,
stateLED
);
// Setze Ausgang entsprechend dem empfangenen Wert
}
}
void
setup
()
{
void
setup
()
{
Serial
.
begin
(
SERIAL_BAUD
);
// Starte Serielle Schnittstelle (zum PC)
sSerial
.
begin
(
SERIAL_BAUD
);
// Starte SoftwareSerielle Schnittstelle (zu IR-Link-Modulen)
...
...
@@ -68,12 +69,11 @@ void setup() {
psnClient
.
subscribe
(
topicSubscribe
);
// Lege fest zu welchem Topic Daten empfangen werden sollen
}
void
loop
()
{
void
loop
()
{
psnClient
.
handleNetwork
();
// Verarbeiten der Daten, prüfen ob Netzwerk frei und versenden der Daten
int
currentValue
=
analogRead
(
POTI_PIN
);
// lese Poti ein und speichere Wert
psnClient
.
publishOnChange
(
topicPublish
,
currentValue
,
THRESHOLD
);
}
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
sign in
to comment