From 0c11fbf341f781c5e5fd69f8acbc18ae67ee06f4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Anian=20B=C3=BChler?=
 <anian.buehler@reutlingen-university.de>
Date: Mon, 18 Jul 2022 16:55:43 +0200
Subject: [PATCH] changed examples (payload = xy)

---
 examples/sPSN_Client1/sPSN_Client1.ino       | 2 +-
 examples/sPSN_Client2/sPSN_Client2.ino       | 3 ++-
 examples/sPSN_PlotTopics/sPSN_PlotTopics.ino | 3 +--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/examples/sPSN_Client1/sPSN_Client1.ino b/examples/sPSN_Client1/sPSN_Client1.ino
index 2ba99f1..5230231 100644
--- a/examples/sPSN_Client1/sPSN_Client1.ino
+++ b/examples/sPSN_Client1/sPSN_Client1.ino
@@ -49,7 +49,7 @@ void newData(char* topic, char* payload) {
   boolean static stateLED = false;
   
   //Wechsle Zustand der Variable "stateLED" wenn Taster beim Sender gedrueckt wurde
-  if(bool(atoi(payload)) == true){
+  if(payload[0] == '1'){
     stateLED = !stateLED;
     digitalWrite(LED_PIN, stateLED);              //Setze Ausgang entsprechend dem empfangenen Wert
   }        
diff --git a/examples/sPSN_Client2/sPSN_Client2.ino b/examples/sPSN_Client2/sPSN_Client2.ino
index 61581fe..d7cde74 100644
--- a/examples/sPSN_Client2/sPSN_Client2.ino
+++ b/examples/sPSN_Client2/sPSN_Client2.ino
@@ -44,7 +44,8 @@ void newData(char* topic, char* payload) {
   int valuePoti = atoi(payload);  //wandle ASCII-Zeichen in Wert
   //Alternativ: sscanf(mData, "%d", &stateLED); //wandle ASCII-Zeichen in Wert
 
-  int valueLED = constrain(map(valuePoti, 0, 1023, 0, 255), 0, 255); //passe analogRead-Wert (0-1023) für analogWrite (0-255) an und begrenze
+  int mappedValue = map(valuePoti, 0, 1023, 0, 255);
+  int valueLED = constrain(mappedValue, 0, 255); //passe analogRead-Wert (0-1023) für analogWrite (0-255) an und begrenze
   
   analogWrite(LED_PIN, valueLED);        //Setze Ausgang entsprechend dem empfangenen Wert
   analogWrite(LED2_PIN, 255-valueLED);   //Setze Ausgang invertiert zum empfangenen Wert
diff --git a/examples/sPSN_PlotTopics/sPSN_PlotTopics.ino b/examples/sPSN_PlotTopics/sPSN_PlotTopics.ino
index 1a6f395..c39af34 100644
--- a/examples/sPSN_PlotTopics/sPSN_PlotTopics.ino
+++ b/examples/sPSN_PlotTopics/sPSN_PlotTopics.ino
@@ -23,8 +23,7 @@ DidacticPSNetClient psnClient;  //Erzeuge PubSub-Client-Instanz
 
 
 //Callback-Funktion - in diesem Beispiel nicht verwendet
-void newData(char* topic, char* payload) {  
-}
+void newData(char* topic, char* payload) {}
 
 
 void setup() {
-- 
GitLab