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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
letsgoING
Libraries
DidacticNetwork
Merge requests
!2
Dev to Master
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Closed
Dev to Master
dev
into
master
Overview
0
Commits
34
Pipelines
0
Changes
1
Closed
Dev to Master
Anian Bühler
requested to merge
dev
into
master
Jul 23, 2021
Overview
0
Commits
34
Pipelines
0
Changes
1
dev to master
1
0
Merge request reports
Viewing commit
45719d74
Prev
Next
Show latest version
1 file
+
65
−
0
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
45719d74
added clientMinimal example
· 45719d74
Anian Bühler
authored
Jul 22, 2021
examples/sPSN_ClientMinimal/sPSN_ClientMinimal.ino
0 → 100644
+
65
−
0
View file @ 45719d74
Edit in single-file editor
Open in Web IDE
/**
*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
}
}
Loading