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 @@
*
* Arduino3: sPSN_PingTest.ino -> reagiert auf PongTester
*
*date: 01.12.2021
*date: 04.07.2022
*/
#include "Arduino.h"
......@@ -51,7 +51,13 @@ char payloadSend[] = "Ping";
bool ledState = true;
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);
}
......@@ -61,6 +67,8 @@ void setup() {
Serial.begin(SERIAL_BAUD);
delay(2000);
//Verwende eigene Nummer als Sende- und Empfangstopic
//(2-stellig mit führender 0)
sprintf(topicPub, "%02d", MY_NUMBER);
sprintf(topicSub, "%02d", MY_NUMBER);
......
......@@ -13,7 +13,7 @@
*
* Arduino3: sPSN_PingTest.ino -> reagiert auf PongTester
*
*date: 01.12.2021
*date: 04.07.2022
*/
#include "Arduino.h"
......@@ -36,22 +36,14 @@ SoftwareSerial sSerial(10, 11);
//Erzeuge Client-Instanz
DidacticPSNetClient psnClient;
//Arrays für Empfangs- und Sende Topic
char topicSub[MAX_LEN_TOPICS] = "";
char topicPub[MAX_LEN_TOPICS] = "";
char payloadSend[] = "Pong";
bool ledState = true;
bool recievedPings[MAX_NR_CLIENTS+1] = {false};
bool newPing = false;
void newData(char* topic, char* payload) {
Serial.println(topic);
//reply pong
strcpy(topicPub, topic);
if (!strcmp(payload, "Ping")) { //Empfangene Nachricht == Ping
Serial.print(" ");
Serial.print(topic);
psnClient.publish(topicPub, payloadSend);
if (!strcmp(payload, "Ping") && (atoi(topic) <= MAX_NR_CLIENTS)) { //Empfangene Nachricht == Ping
recievedPings[atoi(topic)] = true;
newPing = true;
psnClient.publish(topic, "Pong");
}
}
......@@ -77,9 +69,23 @@ void setup() {
Serial.println("\n\nReady for Clients...");
}
void loop() {
//Verarbeiten der Daten, prüfen ob Netzwerk frei und versenden der Daten
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