I've set up my Photon to control a neopixel and want to changed the color based on a parameter sent by the user via SMS.
I know how to send SMS from my particle to my phone using a Twilio POST webhook (hook1Ask() below is working), but I can't find anything online about communication going the other way around (GET webhook for SMS).
I read the particle docs on webhooks and Particle.subscribe, and scoured the inter webs for any answer, but so far, nada.
Here's my code:
//States keep it from sending too many messages
# define STATE_1 1
# define STATE_2 2
int state = 1;
//Variables to keep things tidy
String HOOK_1_ASK = "HOOK_1_ASK";
String HOOK_1_REPLY = "HOOK_1_REPLY";
String data = String(10);
void setup()
{
Serial.begin(9600);
Particle.subscribe("HOOK_1_REPLY", myHandler);
}
void loop()
{
hook1Ask();
delay(100);
}
//***************************************************
// Webhook event trigger
//***************************************************
void hook1Ask(){
if( state == 1 ){
String data = "What's your favorite color? 1=Blue 2=Green 3=Something else";
Particle.publish("HOOK_1_ASK", data, PRIVATE);
state = STATE_2;
}
}
//***************************************************
// myHandler for the subscribe event
//***************************************************
int i = 0;
void myHandler(const char *event, const char *data)
{
i++;
Serial.print(i);
Serial.print(event);
Serial.print(", data: ");
if (data)
Serial.println(data);
else
Serial.println("NULL");
}