Hello I continue with the exercises on the commands particle.publish and particle.subscribe.These exercises are for displaying text in the two commands. I was able to view on the console via the particle.publish, but I can’t find the right syntax for using the sscanf with the particle.subscribe command.
Attached is the skecht of the two commands
//Particle.publish
char *testo="Vale"; // se avessi messo const significa che la variabile non verra mai modificata
const char *EVENT_NAME = "Nome";
void setup() {
Serial.begin(9600);
}
void loop() {
char miamem[32];
snprintf(miamem, sizeof(miamem), "%s", testo);
Particle.publish(EVENT_NAME, miamem, PRIVATE);
Serial.print("Nome: ");Serial.println(miamem);
delay(2000);
}
Output on console:
//Particle.subscribe
#include "Particle.h"
void setup(){
Serial.begin(9600);
Particle.subscribe("miamem", dataHandler, MY_DEVICES);
}
void loop() {
//Serial.println("Prova subscribe");
//delay(1000);
}
void dataHandler(const char *event, const char *data) {
char *testo;
if(sscanf(data,"%s",testo)){
Serial.println(testo);
}
}