So I’ve got a problem checking the data returned in myhandler().
What I’m trying to do, is have a photon publish a String, and another photon checking if the String is equal to “HI!”.
If the String is indeed equal to HI!, the photon will then publish “working” to another webhook.
If the returned data is “true” it being something has been returned, the photon will then publish said data to another webhook.
With the following code, I do not see the problem, HOWEVER; checking the data sent to the other webhook, reveals that, for some reason, the 2nd photon does NOT equal “HI!” to “HI!”. Why does this happen? What have I done wrong?
Photon 1:
#include “HttpClient/HttpClient.h”
#define sensor A0
#define LED5 D6
int value;
HttpClient http;
http_request_t request;
http_response_t response;
http_header_t headers[] = {
{ "Content-type", "application/x-www-form-urlencoded" },
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
char *slag;
void setup() {
Particle.subscribe("GRAB", myHandler , MY_DEVICES);
pinMode(sensor, INPUT);
pinMode(LED5, OUTPUT);
}
void loop() {
value = analogRead(sensor);
pubStroke("HI!");
}
void myHandler(const char *event, const char *data) {
if (data == "1"){
}
if (data == "0"){
onOff(LED5, 500);
}
}
void pubStroke(char *data){
Particle.publish("STROKE", data, PRIVATE);
delay(60000);
}
void onOff(int led, int pause) {
digitalWrite(led, HIGH);
delay(pause);
digitalWrite(led, LOW);
delay(pause);
}
Photon 2:
// This #include statement was automatically added by the Particle IDE.
#include “HttpClient/HttpClient.h”
#define force1 A0
#define force2 A1
#define force3 A2
#define force4 A3
#define force5 A4
String sensor1;
String sensor2;
String sensor3;
String sensor4;
String sensor5;
String all;
int collection[2];
const char *hej;
void setup() {
Particle.subscribe("STROKE", myHandler , MY_DEVICES);
Particle.variable("hands", all);
}
void loop(){
sensor1 = String(analogRead(force1));
sensor2 = String(analogRead(force2));
sensor3 = String(analogRead(force3));
sensor4 = String(analogRead(force4));
sensor5 = String(analogRead(force5));
all = String(sensor1) + ", " + String(sensor2) + ", " + String(sensor3) + ", " + String(sensor4) + ", "+ String(sensor5);
}
void myHandler(const char *event,const char *data) {
if (data == "HI!") {
pubStroke("working");
}
if (data) {
pubStroke(data);
}
}
void pubStroke(const char *data){
Particle.publish("GRAB", data, PRIVATE);
delay(60000);
}
By checking the particle cloud logs we can conclude, photon 2 does NOT infact equal “HI!” to “HI!” (Seeing as “HI!” is beign returned and NOT “working”):