예제 #1
0
/********************************************************************
  parse the websocket json and look for a message type


********************************************************************/
void ArduinoSlackBot::parseResponse(char *payload) {
  DynamicJsonBuffer jsonBuffer;
  JsonObject& root = jsonBuffer.parseObject(payload);

  if (root.success()) {
    
    if (root.containsKey("type")) {
      slackMsg.type = root["type"];

      PRINTLN(slackMsg.type);
      PRINT("free heap size:");
      PRINTLN(ESP.getFreeHeap());


      if (strcasecmp(slackMsg.type, "message") == 0) {
        slackMsg.channel = root["channel"];
        slackMsg.user = root["user"];
        slackMsg.text = root["text"];
        slackMsg.timestamp = root["ts"];
        slackMsg.team = root["team"];
        PRINTLN("parseCommands");
        parseCmds();
      }
    }
    

  } else {
    PRINTLN("parse fail");
  }
}
예제 #2
0
파일: uartctl.c 프로젝트: hellertime/manos
/*
 * Small command language for Uarts
 *
 * - Line based.
 * - Commands are <type><arg>
 * - Multiple commands can be whitespace separated
 *
 * Commands:
 *
 * type: b (baud) arg: int
 * type: l (bits) arg: int
 */
int sysuartctl(Uart* uart, const char *cmd) {
    const char* cmds[2];

    unsigned n = parseCmds(cmd, cmds, COUNT_OF(cmds));
    for (unsigned i = 0; i < n; i++) {
        unsigned arg = atoi(cmds[i] + 1);
        switch (*cmds[i]) {
            case 'B':
            case 'b':
                if (uart->hw->baud(uart, arg) < 0)
                    return -1;
                break;
            case 'L':
            case 'l':
                if (uart->hw->bits(uart, arg) < 0)
                    return -1;
                break;
        }
    }
    return 0;
}