Skip to content
Snippets Groups Projects
Verified Commit f13d0a3e authored by Anian Bühler's avatar Anian Bühler
Browse files

Updated PingPong test-programms

parent abe6a10d
No related branches found
No related tags found
1 merge request!9update master from dev2
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* *
* Arduino3: sPSN_PingTest.ino -> reagiert auf PongTester * Arduino3: sPSN_PingTest.ino -> reagiert auf PongTester
* *
*date: 01.12.2021 *date: 04.07.2022
*/ */
#include "Arduino.h" #include "Arduino.h"
...@@ -51,7 +51,13 @@ char payloadSend[] = "Ping"; ...@@ -51,7 +51,13 @@ char payloadSend[] = "Ping";
bool ledState = true; bool ledState = true;
void newData(char* topic, char* payload) { void newData(char* topic, char* payload) {
Serial.println(payload); if (!strcmp(payload, "Ping")){
Serial.print(payload);
Serial.print(" -> ");
} else{
Serial.print(payload);
Serial.println(" :-D");
}
digitalWrite(LED_BUILTIN, HIGH); digitalWrite(LED_BUILTIN, HIGH);
} }
...@@ -61,6 +67,8 @@ void setup() { ...@@ -61,6 +67,8 @@ void setup() {
Serial.begin(SERIAL_BAUD); Serial.begin(SERIAL_BAUD);
delay(2000); delay(2000);
//Verwende eigene Nummer als Sende- und Empfangstopic
//(2-stellig mit führender 0)
sprintf(topicPub, "%02d", MY_NUMBER); sprintf(topicPub, "%02d", MY_NUMBER);
sprintf(topicSub, "%02d", MY_NUMBER); sprintf(topicSub, "%02d", MY_NUMBER);
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* *
* Arduino3: sPSN_PingTest.ino -> reagiert auf PongTester * Arduino3: sPSN_PingTest.ino -> reagiert auf PongTester
* *
*date: 01.12.2021 *date: 04.07.2022
*/ */
#include "Arduino.h" #include "Arduino.h"
...@@ -36,22 +36,14 @@ SoftwareSerial sSerial(10, 11); ...@@ -36,22 +36,14 @@ SoftwareSerial sSerial(10, 11);
//Erzeuge Client-Instanz //Erzeuge Client-Instanz
DidacticPSNetClient psnClient; DidacticPSNetClient psnClient;
//Arrays für Empfangs- und Sende Topic bool recievedPings[MAX_NR_CLIENTS+1] = {false};
char topicSub[MAX_LEN_TOPICS] = ""; bool newPing = false;
char topicPub[MAX_LEN_TOPICS] = "";
char payloadSend[] = "Pong";
bool ledState = true;
void newData(char* topic, char* payload) { void newData(char* topic, char* payload) {
Serial.println(topic); if (!strcmp(payload, "Ping") && (atoi(topic) <= MAX_NR_CLIENTS)) { //Empfangene Nachricht == Ping
//reply pong recievedPings[atoi(topic)] = true;
strcpy(topicPub, topic); newPing = true;
if (!strcmp(payload, "Ping")) { //Empfangene Nachricht == Ping psnClient.publish(topic, "Pong");
Serial.print(" ");
Serial.print(topic);
psnClient.publish(topicPub, payloadSend);
} }
} }
...@@ -77,9 +69,23 @@ void setup() { ...@@ -77,9 +69,23 @@ void setup() {
Serial.println("\n\nReady for Clients..."); Serial.println("\n\nReady for Clients...");
} }
void loop() { void loop() {
//Verarbeiten der Daten, prüfen ob Netzwerk frei und versenden der Daten //Verarbeiten der Daten, prüfen ob Netzwerk frei und versenden der Daten
psnClient.handleNetwork(); psnClient.handleNetwork();
if(newPing){
newPing = false;
Serial.print("Empfangene Clients: ");
for(int i = 0; i < MAX_NR_CLIENTS+1; i++){
if(recievedPings[i]){
Serial.print(i);
Serial.print(" | ");
}
}
Serial.println();
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment