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

removed length from callback & updated examples

parent 8b704deb
No related branches found
No related tags found
1 merge request!9update master from dev2
...@@ -36,7 +36,7 @@ char topicSub[MAX_LEN_TOPICS] = {""}; //Array für neues Empfangs-Topi ...@@ -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 char topicPub[MAX_LEN_TOPICS] = {""}; //Array für eigenes Sende-Topic
//Callback-Funktion wird bei neuen Daten automatisch aufgerufen //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(mTopic);
Serial.print(":\t"); Serial.print(":\t");
Serial.println(mData); Serial.println(mData);
... ...
......
...@@ -34,15 +34,13 @@ ...@@ -34,15 +34,13 @@
char topicPublish[MAX_LEN_TOPICS] = "potiVal"; //Topic unter dem (eigene) Daten veröffentlicht werden 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 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 SoftwareSerial sSerial(10, 11); //Erzeuge SoftwareSerial-Instanz mit Rx = Pin10 -> Empfänger | Tx = Pin11 -> Sender
DidacticPSNetClient psnClient; //Erzeuge PubSub-Client-Instanz DidacticPSNetClient psnClient; //Erzeuge PubSub-Client-Instanz
//Callback-Funktion - wird beim Empfang neuer Daten aufgerufen //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("CB: ");
Serial.print(mTopic); Serial.print(mTopic);
Serial.print(" | "); Serial.print(" | ");
... ...
......
...@@ -30,10 +30,6 @@ ...@@ -30,10 +30,6 @@
char topicPublish[MAX_LEN_TOPICS] = "btnState"; //Topic unter dem (eigene) Daten veröffentlicht werden 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 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 SoftwareSerial sSerial(10, 11); //Erzeuge SoftwareSerial-Instanz mit Rx = Pin10 -> Empfänger | Tx = Pin11 -> Sender
DidacticPSNetClient psnClient; //Erzeuge PubSub-Client-Instanz DidacticPSNetClient psnClient; //Erzeuge PubSub-Client-Instanz
...@@ -41,7 +37,7 @@ UnblockingTimer uTimer; ...@@ -41,7 +37,7 @@ UnblockingTimer uTimer;
//Callback-Funktion - wird beim Empfang neuer Daten aufgerufen //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("CB: ");
Serial.print(mTopic); Serial.print(mTopic);
Serial.print(" | "); Serial.print(" | ");
... ...
......
...@@ -29,7 +29,7 @@ SoftwareSerial sSerial(10, 11); //Erzeuge SoftwareSerial-Instanz mit Rx = Pin10 ...@@ -29,7 +29,7 @@ SoftwareSerial sSerial(10, 11); //Erzeuge SoftwareSerial-Instanz mit Rx = Pin10
DidacticPSNetClient psnClient; //Erzeuge PubSub-Client-Instanz DidacticPSNetClient psnClient; //Erzeuge PubSub-Client-Instanz
//Callback-Funktion - wird beim Empfang neuer Daten aufgerufen //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("Nachricht von: ");
Serial.print(mTopic); Serial.print(mTopic);
Serial.print(" - "); Serial.print(" - ");
... ...
......
...@@ -50,7 +50,7 @@ char payloadSend[] = "Ping"; ...@@ -50,7 +50,7 @@ char payloadSend[] = "Ping";
bool ledState = true; bool ledState = true;
void newData(char* mTopic, int mToLength, char* mData, int mDaLength) { void newData(char* mTopic, char* mData) {
Serial.println(mData); Serial.println(mData);
digitalWrite(LED_BUILTIN, HIGH); digitalWrite(LED_BUILTIN, HIGH);
} }
... ...
......
...@@ -44,7 +44,7 @@ char payloadSend[] = "Pong"; ...@@ -44,7 +44,7 @@ char payloadSend[] = "Pong";
bool ledState = true; bool ledState = true;
void newData(char* mTopic, int mToLength, char* mData, int mDaLength) { void newData(char* mTopic, char* mData) {
Serial.println(mTopic); Serial.println(mTopic);
//reply pong //reply pong
strcpy(topicPub, mTopic); strcpy(topicPub, mTopic);
... ...
......
...@@ -302,7 +302,12 @@ bool DidacticPSNetClient::handleData(){ ...@@ -302,7 +302,12 @@ bool DidacticPSNetClient::handleData(){
if( currentTopicNr >= 0){ if( currentTopicNr >= 0){
savePayload( _bufferPayload, currentTopicNr); savePayload( _bufferPayload, currentTopicNr);
//callback(_topic[currentTopicNr], topicLength, _payload[currentTopicNr], payloadLength); //callback(_topic[currentTopicNr], topicLength, _payload[currentTopicNr], payloadLength);
#ifdef CALLBACK_W_LENGTH
callback(_bufferTopic, topicLength, _bufferPayload, payloadLength); callback(_bufferTopic, topicLength, _bufferPayload, payloadLength);
#else
callback(_bufferTopic, _bufferPayload);
#endif
} }
} }
return true; return true;
... ...
......
...@@ -9,7 +9,11 @@ ...@@ -9,7 +9,11 @@
#include "Arduino.h" #include "Arduino.h"
//callback(topic, topicLength, data, dataLength) //callback(topic, topicLength, data, dataLength)
#ifdef CALLBACK_W_LENGTH
#define PSNET_CALLBACK_SIGNATURE void (*callback)(char*, int, char*, int) #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_PRELIMITER '<'
#define MSG_DELIMITER '>' #define MSG_DELIMITER '>'
...@@ -117,6 +121,7 @@ class DidacticPSNet ...@@ -117,6 +121,7 @@ class DidacticPSNet
int _currentPayloadLength = 0; int _currentPayloadLength = 0;
DidacticPSNet& setCallback(PSNET_CALLBACK_SIGNATURE); DidacticPSNet& setCallback(PSNET_CALLBACK_SIGNATURE);
void setStream(Stream& _port); void setStream(Stream& _port);
int checkData(); int checkData();
...@@ -136,6 +141,7 @@ class DidacticPSNet ...@@ -136,6 +141,7 @@ class DidacticPSNet
void begin(Stream& _port); void begin(Stream& _port);
void begin(Stream& _port, PSNET_CALLBACK_SIGNATURE); void begin(Stream& _port, PSNET_CALLBACK_SIGNATURE);
bool handleNetwork(); bool handleNetwork();
bool isDataToSend(); bool isDataToSend();
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment