diff --git a/examples/sPSN_Chat/sPSN_Chat.ino b/examples/sPSN_Chat/sPSN_Chat.ino index ee8d7e5e19ae58c5af056a04151f1a7965221f08..3c21bd167a730d5ee68ae06c88cbdc02b9d45d10 100644 --- a/examples/sPSN_Chat/sPSN_Chat.ino +++ b/examples/sPSN_Chat/sPSN_Chat.ino @@ -36,7 +36,7 @@ char topicSub[MAX_LEN_TOPICS] = {""}; //Array für neues Empfangs-Topi char topicPub[MAX_LEN_TOPICS] = {""}; //Array für eigenes Sende-Topic //Callback-Funktion wird bei neuen Daten automatisch aufgerufen -void newData(char* mTopic, int mToLength, char* mData, int mDaLength) { +void newData(char* mTopic, char* mData) { Serial.print(mTopic); Serial.print(":\t"); Serial.println(mData); diff --git a/examples/sPSN_Client1/sPSN_Client1.ino b/examples/sPSN_Client1/sPSN_Client1.ino index 14afad626a9bcce4d48a70de5baf1efd5f748e38..0f4c43aa8d92bf81c78184c062d8df8ba7258c1c 100644 --- a/examples/sPSN_Client1/sPSN_Client1.ino +++ b/examples/sPSN_Client1/sPSN_Client1.ino @@ -34,15 +34,13 @@ char topicPublish[MAX_LEN_TOPICS] = "potiVal"; //Topic unter dem (eigene) Daten veröffentlicht werden char topicSubscribe[MAX_LEN_TOPICS] = "btnState"; //Topic (von anderem TN) das abboniert werden soll -char payload[MAX_LEN_PAYLOAD] = {0}; - 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 newData(char* mTopic, int mToLength, char* mData, int mDaLength) { +void newData(char* mTopic, char* mData) { Serial.print("CB: "); Serial.print(mTopic); Serial.print(" | "); diff --git a/examples/sPSN_Client2/sPSN_Client2.ino b/examples/sPSN_Client2/sPSN_Client2.ino index 5ee164c895c94427f1eb4344face63923e0c4788..4b04bb5684a38d300ec0dc57e9d04e90de7d1c3f 100644 --- a/examples/sPSN_Client2/sPSN_Client2.ino +++ b/examples/sPSN_Client2/sPSN_Client2.ino @@ -30,10 +30,6 @@ char topicPublish[MAX_LEN_TOPICS] = "btnState"; //Topic unter dem (eigene) Daten veröffentlicht werden char topicSubscribe[MAX_LEN_TOPICS] = "potiVal"; //Topic (von anderem TN) das abboniert werden soll -char payload[MAX_LEN_PAYLOAD] = {0}; -boolean newData = false; -boolean ledState = false; - SoftwareSerial sSerial(10, 11); //Erzeuge SoftwareSerial-Instanz mit Rx = Pin10 -> Empfänger | Tx = Pin11 -> Sender DidacticPSNetClient psnClient; //Erzeuge PubSub-Client-Instanz @@ -41,7 +37,7 @@ UnblockingTimer uTimer; //Callback-Funktion - wird beim Empfang neuer Daten aufgerufen -void newData(char* mTopic, int mToLength, char* mData, int mDaLength) { +void newData(char* mTopic, char* mData) { Serial.print("CB: "); Serial.print(mTopic); Serial.print(" | "); diff --git a/examples/sPSN_ClientMinimal/sPSN_ClientMinimal.ino b/examples/sPSN_ClientMinimal/sPSN_ClientMinimal.ino index dabf7d2af8ab617d50a221fc858119476f0fd089..3222fde51f4244bb23296cac218736fc7c4c8a6a 100644 --- a/examples/sPSN_ClientMinimal/sPSN_ClientMinimal.ino +++ b/examples/sPSN_ClientMinimal/sPSN_ClientMinimal.ino @@ -29,7 +29,7 @@ SoftwareSerial sSerial(10, 11); //Erzeuge SoftwareSerial-Instanz mit Rx = Pin10 DidacticPSNetClient psnClient; //Erzeuge PubSub-Client-Instanz //Callback-Funktion - wird beim Empfang neuer Daten aufgerufen -void newData(char* mTopic, int mToLength, char* mPayload, int mPayloadLength) { +void newData(char* mTopic, char* mPayload) { Serial.print("Nachricht von: "); Serial.print(mTopic); Serial.print(" - "); diff --git a/examples/sPSN_PingTest/sPSN_PingTest.ino b/examples/sPSN_PingTest/sPSN_PingTest.ino index f666e9c8553d8171366295c9d5b21c27b0b4d704..14eebdda6a19d72b721d248713154f481535c4c9 100644 --- a/examples/sPSN_PingTest/sPSN_PingTest.ino +++ b/examples/sPSN_PingTest/sPSN_PingTest.ino @@ -50,7 +50,7 @@ char payloadSend[] = "Ping"; bool ledState = true; -void newData(char* mTopic, int mToLength, char* mData, int mDaLength) { +void newData(char* mTopic, char* mData) { Serial.println(mData); digitalWrite(LED_BUILTIN, HIGH); } diff --git a/examples/sPSN_PongTester/sPSN_PongTester.ino b/examples/sPSN_PongTester/sPSN_PongTester.ino index 3f1b2c26f9722397574f0fca5ebcada689637d9d..d96ba58682fa5ea22fb04547af9f5aa576c49ab7 100644 --- a/examples/sPSN_PongTester/sPSN_PongTester.ino +++ b/examples/sPSN_PongTester/sPSN_PongTester.ino @@ -44,7 +44,7 @@ char payloadSend[] = "Pong"; bool ledState = true; -void newData(char* mTopic, int mToLength, char* mData, int mDaLength) { +void newData(char* mTopic, char* mData) { Serial.println(mTopic); //reply pong strcpy(topicPub, mTopic); diff --git a/src/DidacticNet.cpp b/src/DidacticNet.cpp index e3a579113f0ac0cb363cd8a94ecef0e8e3976d50..380c12a0cbbd38ae648f239bb1bd96e48f73de42 100644 --- a/src/DidacticNet.cpp +++ b/src/DidacticNet.cpp @@ -302,7 +302,12 @@ bool DidacticPSNetClient::handleData(){ if( currentTopicNr >= 0){ savePayload( _bufferPayload, currentTopicNr); //callback(_topic[currentTopicNr], topicLength, _payload[currentTopicNr], payloadLength); - callback(_bufferTopic, topicLength, _bufferPayload, payloadLength); + #ifdef CALLBACK_W_LENGTH + callback(_bufferTopic, topicLength, _bufferPayload, payloadLength); + #else + callback(_bufferTopic, _bufferPayload); + #endif + } } return true; diff --git a/src/DidacticNet.h b/src/DidacticNet.h index 31556a30491080e7dacc21227e9f26ee55d0fdd1..cad4bd1df8d4a407d50c53f24c8b8e678df576d4 100644 --- a/src/DidacticNet.h +++ b/src/DidacticNet.h @@ -9,7 +9,11 @@ #include "Arduino.h" //callback(topic, topicLength, data, dataLength) -#define PSNET_CALLBACK_SIGNATURE void (*callback)(char*, int, char*, int) +#ifdef CALLBACK_W_LENGTH + #define PSNET_CALLBACK_SIGNATURE void (*callback)(char*, int, char*, int) +#else + #define PSNET_CALLBACK_SIGNATURE void (*callback)(char*, char*) +#endif #define MSG_PRELIMITER '<' #define MSG_DELIMITER '>' @@ -117,6 +121,7 @@ class DidacticPSNet int _currentPayloadLength = 0; DidacticPSNet& setCallback(PSNET_CALLBACK_SIGNATURE); + void setStream(Stream& _port); int checkData(); @@ -136,6 +141,7 @@ class DidacticPSNet void begin(Stream& _port); void begin(Stream& _port, PSNET_CALLBACK_SIGNATURE); + bool handleNetwork(); bool isDataToSend();