예제 #1
0
// Command handler for sync command
static void ICACHE_FLASH_ATTR
cmdSync(CmdPacket *cmd) {
  CmdRequest req;
  cmdRequest(&req, cmd);
  if(cmd->argc != 0 || cmd->value == 0) {
    cmdResponseStart(CMD_RESP_V, 0, 0);
    cmdResponseEnd();
    return;
  }

  // clear callbacks table
  os_memset(callbacks, 0, sizeof(callbacks));

  // register our callback with wifi subsystem
  if (!wifiCbAdded) {
    wifiAddStateChangeCb(cmdWifiCb);
    wifiCbAdded = true;
  }

  // send OK response
  cmdResponseStart(CMD_RESP_V, cmd->value, 0);
  cmdResponseEnd();

  // save the MCU's callback and trigger an initial callback
  cmdAddCb("wifiCb", cmd->value);
  lastWifiStatus = 0xff; // set to invalid value so we immediately send status cb in all cases
  cmdWifiCb(wifiState);

  return;
}
예제 #2
0
파일: handlers.c 프로젝트: Ribster/esp-link
// Command handler for Wifi connect command
static uint32_t ICACHE_FLASH_ATTR
CMD_WifiConnect(CmdPacket *cmd) {
  CmdRequest req;
  CMD_Request(&req, cmd);
	if(cmd->argc != 2 || cmd->callback == 0)
		return 0;

  if (!wifiCbAdded) {
    wifiAddStateChangeCb(CMD_WifiCb);    // register our callback with wifi subsystem
    wifiCbAdded = true;
  }
  CMD_AddCb("wifiCb", (uint32_t)cmd->callback); // save the MCU's callback
  lastWifiStatus = 0xff; // set to invalid value so we immediately send status cb in all cases
  CMD_WifiCb(wifiState);

  return 1;
}
예제 #3
0
void ICACHE_FLASH_ATTR
mqtt_client_init()
{
  MQTT_Init(&mqttClient, flashConfig.mqtt_host, flashConfig.mqtt_port, 0, flashConfig.mqtt_timeout,
    flashConfig.mqtt_clientid, flashConfig.mqtt_username, flashConfig.mqtt_password,
    flashConfig.mqtt_keepalive);

  MQTT_OnConnected(&mqttClient, mqttConnectedCb);
  MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb);
  MQTT_OnPublished(&mqttClient, mqttPublishedCb);
  MQTT_OnData(&mqttClient, mqttDataCb);

  // Don't connect now, wait for a wifi status change callback
  //if (flashConfig.mqtt_enable && strlen(flashConfig.mqtt_host) > 0)
  //  MQTT_Connect(&mqttClient);

  wifiAddStateChangeCb(wifiStateChangeCb);
}