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
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
letsgoING
Libraries
DidacticNetwork
Commits
45719d74
Commit
45719d74
authored
3 years ago
by
Anian Bühler
Browse files
Options
Downloads
Patches
Plain Diff
added clientMinimal example
parent
a2af5f33
No related branches found
Branches containing commit
No related tags found
2 merge requests
!3
Dev to master
,
!2
Dev to Master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/sPSN_ClientMinimal/sPSN_ClientMinimal.ino
+65
-0
65 additions, 0 deletions
examples/sPSN_ClientMinimal/sPSN_ClientMinimal.ino
with
65 additions
and
0 deletions
examples/sPSN_ClientMinimal/sPSN_ClientMinimal.ino
0 → 100644
+
65
−
0
View file @
45719d74
/**
*file: sPSN_Client1
*author: letsgoING -> info@letsgoing.de
*
*description:
* Dieses Programm ist das Minimal-Beispiel für ein einfaches Pub-Sub-Netzwerk.
* Es wird jede Sekunde ein analoger Messwert (AO) übertragen
* und die empfangenen Daten auf dem SerialMonitor ausgegeben
*
* Für das Netwerk werden 3 oder mehr Arduinos mit IR-Link-Modulen benötigt:
*
* Arduino1: sPSN_Broker.ino
*
* Arduino2-n: sPSN_ClientMinimal.ino (dieses Programm)
*
* parameter:
* MAX_LEN_PAYLOAD = 20 Zeichen (didacticNet.h)
* MAX_LEN_TOPICS = 10 Zeichen (didacticNet.h)
*
*date: 06.07.2021
*/
#include
<Arduino.h>
#include
"SoftwareSerial.h"
#include
"didacticNet.h"
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
clientCallback
(
char
*
mTopic
,
int
mToLength
,
char
*
mPayload
,
int
mPayloadLength
)
{
Serial
.
print
(
"Nachricht von: "
);
Serial
.
print
(
mTopic
);
Serial
.
print
(
" - "
);
Serial
.
println
(
mPayload
);
}
void
setup
()
{
Serial
.
begin
(
2400
);
//Starte Serielle Schnittstelle (zum PC)
sSerial
.
begin
(
2400
);
//Starte SoftwareSerielle Schnittstelle (zu IR-Link-Modulen)
psnClient
.
begin
(
sSerial
,
clientCallback
);
//Starte PubSub Client an SoftwareSerial Schnittstelle
//Hier EMPFANGS-TOPIC ANPASSEN -> default "client2"
psnClient
.
subscribe
(
"client2"
);
//Lege fest zu welchem Topic Daten empfangen werden sollen
}
void
loop
()
{
psnClient
.
handleNetwork
();
//Verarbeiten der Daten, prüfen ob Netzwerk frei und versenden der Daten
int
currentValue
=
analogRead
(
A0
);
//lese Poti ein und speichere Wert
char
payload
[
5
];
itoa
(
currentValue
,
payload
,
10
);
if
(
psnClient
.
timeElapsed
(
1000
)){
//Sende neue Daten wenn Mindestwaretzeit 1 Sekunde abgelaufen
//Hier SENDE-TOPIC ANPASSEN -> default "client1"
psnClient
.
publish
(
"client1"
,
payload
);
//bereite Topic und Nutzdaten zum senden vor
}
}
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