Hi!,
when running the following code, i expect that when event “hook-response/wit-request-text” is generated, the function extractWITtext is invoked, so the first thing i should view when monitoring the serial port on my PC, is the message “Response from Wit for text input:”, but i just see “Requesting the meaning of a sentence to WIT.AI!”, despite that i checked on the Dashboar that the hook-response “hook-response/wit-request-text” is generated … could anybody help me to find which is the problem???
thaaaaaanks
best regards
#include "application.h"
// name the pins
#define BUTTONPIN D2
String myDeviceID;
// This routine runs only once upon reset
void setup()
{
pinMode(BUTTONPIN, INPUT);
Serial.begin(115200);
myDeviceID = System.deviceID();
Spark.subscribe("hook-response/wit-request-text", extractWITtext, myDeviceID);
}
// This routine loops forever
void loop()
{
if(digitalRead(BUTTONPIN) == 1) {
Serial.println("Requesting the meaning of a sentence to WIT.AI!");
Spark.publish("wit-request-text", "prueba-wit-text-1");
// wait for 1 seg to avoid multiple requests when pushing button
delay(1000);
}
}
void extractWITtext(const char * event, const char * data)
{
Serial.println("Response from Wit for text input:");
String str = String(data);
String msg_id = extractstring(str, "msg_id", ",");
if (msg_id != NULL) {
Serial.println("msg_id: " + msg_id);
}
}
String extractstring(String str, const char* start, const char* end) {
if (str == NULL) {
Serial.println("ERROR: No response received from Wit!");
return NULL;
}
int startidx = str.indexOf(start);
if (startidx < 0) {
return NULL;
}
int endidx = str.indexOf(end);
if (endidx < 0) {
return NULL;
}
return str.substring(startidx + strlen(start), endidx);
}