mirror of https://github.com/jeelabs/esp-link.git
parent
47b33f837f
commit
bc3856334d
@ -1,9 +1,11 @@ |
|||||||
#ifndef CGI_H |
#ifndef CGI_H |
||||||
#define CGI_H |
#define CGI_H |
||||||
|
|
||||||
|
#include <esp8266.h> |
||||||
#include "httpd.h" |
#include "httpd.h" |
||||||
|
|
||||||
void jsonHeader(HttpdConnData *connData, int code); |
void jsonHeader(HttpdConnData *connData, int code); |
||||||
int cgiMenu(HttpdConnData *connData); |
int cgiMenu(HttpdConnData *connData); |
||||||
|
uint8_t UTILS_StrToIP(const char* str, void *ip); |
||||||
|
|
||||||
#endif |
#endif |
||||||
|
@ -1,70 +1,70 @@ |
|||||||
#include <esp8266.h> |
#include <esp8266.h> |
||||||
#include <mqtt.h> |
//#include <mqtt.h>
|
||||||
#include <cgiwifi.h> |
//#include <cgiwifi.h>
|
||||||
|
|
||||||
MQTT_Client mqttClient; |
//MQTT_Client mqttClient;
|
||||||
|
//
|
||||||
void ICACHE_FLASH_ATTR
|
//void ICACHE_FLASH_ATTR
|
||||||
mqttConnectedCb(uint32_t *args) { |
//mqttConnectedCb(uint32_t *args) {
|
||||||
MQTT_Client* client = (MQTT_Client*)args; |
|
||||||
MQTT_Publish(client, "announce/all", "Hello World!", 0, 0); |
|
||||||
} |
|
||||||
|
|
||||||
void ICACHE_FLASH_ATTR
|
|
||||||
mqttDisconnectedCb(uint32_t *args) { |
|
||||||
// MQTT_Client* client = (MQTT_Client*)args;
|
|
||||||
os_printf("MQTT Disconnected\n"); |
|
||||||
} |
|
||||||
|
|
||||||
void ICACHE_FLASH_ATTR
|
|
||||||
mqttTcpDisconnectedCb(uint32_t *args) { |
|
||||||
// MQTT_Client* client = (MQTT_Client*)args;
|
// MQTT_Client* client = (MQTT_Client*)args;
|
||||||
os_printf("MQTT TCP Disconnected\n"); |
// MQTT_Publish(client, "announce/all", "Hello World!", 0, 0);
|
||||||
} |
//}
|
||||||
|
//
|
||||||
void ICACHE_FLASH_ATTR
|
//void ICACHE_FLASH_ATTR
|
||||||
mqttPublishedCb(uint32_t *args) { |
//mqttDisconnectedCb(uint32_t *args) {
|
||||||
// MQTT_Client* client = (MQTT_Client*)args;
|
//// MQTT_Client* client = (MQTT_Client*)args;
|
||||||
os_printf("MQTT Published\n"); |
// os_printf("MQTT Disconnected\n");
|
||||||
} |
//}
|
||||||
|
//
|
||||||
void ICACHE_FLASH_ATTR
|
//void ICACHE_FLASH_ATTR
|
||||||
mqttDataCb(uint32_t *args, const char* topic, uint32_t topic_len, const char *data, uint32_t data_len) { |
//mqttTcpDisconnectedCb(uint32_t *args) {
|
||||||
char *topicBuf = (char*)os_zalloc(topic_len + 1); |
//// MQTT_Client* client = (MQTT_Client*)args;
|
||||||
char *dataBuf = (char*)os_zalloc(data_len + 1); |
// os_printf("MQTT TCP Disconnected\n");
|
||||||
|
//}
|
||||||
// MQTT_Client* client = (MQTT_Client*)args;
|
//
|
||||||
|
//void ICACHE_FLASH_ATTR
|
||||||
os_memcpy(topicBuf, topic, topic_len); |
//mqttPublishedCb(uint32_t *args) {
|
||||||
topicBuf[topic_len] = 0; |
//// MQTT_Client* client = (MQTT_Client*)args;
|
||||||
|
// os_printf("MQTT Published\n");
|
||||||
os_memcpy(dataBuf, data, data_len); |
//}
|
||||||
dataBuf[data_len] = 0; |
//
|
||||||
|
//void ICACHE_FLASH_ATTR
|
||||||
os_printf("Receive topic: %s, data: %s\n", topicBuf, dataBuf); |
//mqttDataCb(uint32_t *args, const char* topic, uint32_t topic_len, const char *data, uint32_t data_len) {
|
||||||
os_free(topicBuf); |
// char *topicBuf = (char*)os_zalloc(topic_len + 1);
|
||||||
os_free(dataBuf); |
// char *dataBuf = (char*)os_zalloc(data_len + 1);
|
||||||
} |
//
|
||||||
|
//// MQTT_Client* client = (MQTT_Client*)args;
|
||||||
void ICACHE_FLASH_ATTR
|
//
|
||||||
wifiStateChangeCb(uint8_t status) |
// os_memcpy(topicBuf, topic, topic_len);
|
||||||
{ |
// topicBuf[topic_len] = 0;
|
||||||
if (status == wifiGotIP && mqttClient.connState != TCP_CONNECTING){ |
//
|
||||||
MQTT_Connect(&mqttClient); |
// os_memcpy(dataBuf, data, data_len);
|
||||||
} |
// dataBuf[data_len] = 0;
|
||||||
else if (status == wifiIsDisconnected && mqttClient.connState == TCP_CONNECTING){
|
//
|
||||||
MQTT_Disconnect(&mqttClient); |
// os_printf("Receive topic: %s, data: %s\n", topicBuf, dataBuf);
|
||||||
} |
// os_free(topicBuf);
|
||||||
} |
// os_free(dataBuf);
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//void ICACHE_FLASH_ATTR
|
||||||
|
//wifiStateChangeCb(uint8_t status)
|
||||||
|
//{
|
||||||
|
// if (status == wifiGotIP && mqttClient.connState != TCP_CONNECTING){
|
||||||
|
// MQTT_Connect(&mqttClient);
|
||||||
|
// }
|
||||||
|
// else if (status == wifiIsDisconnected && mqttClient.connState == TCP_CONNECTING){
|
||||||
|
// MQTT_Disconnect(&mqttClient);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
void init() { |
void init() { |
||||||
wifiAddStateChangeCb(wifiStateChangeCb); |
// wifiAddStateChangeCb(wifiStateChangeCb);
|
||||||
MQTT_InitConnection(&mqttClient, MQTT_HOST, MQTT_PORT, MQTT_SECURITY); |
// MQTT_InitConnection(&mqttClient, MQTT_HOST, MQTT_PORT, MQTT_SECURITY);
|
||||||
MQTT_InitClient(&mqttClient, MQTT_CLIENT_ID, MQTT_USER, MQTT_PASS, MQTT_KEEPALIVE, MQTT_CLSESSION); |
// MQTT_InitClient(&mqttClient, MQTT_CLIENT_ID, MQTT_USER, MQTT_PASS, MQTT_KEEPALIVE, MQTT_CLSESSION);
|
||||||
MQTT_InitLWT(&mqttClient, "/lwt", "offline", 0, 0); |
// MQTT_InitLWT(&mqttClient, "/lwt", "offline", 0, 0);
|
||||||
MQTT_OnConnected(&mqttClient, mqttConnectedCb); |
// MQTT_OnConnected(&mqttClient, mqttConnectedCb);
|
||||||
MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); |
// MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb);
|
||||||
MQTT_OnDisconnected(&mqttClient, mqttTcpDisconnectedCb); |
// MQTT_OnDisconnected(&mqttClient, mqttTcpDisconnectedCb);
|
||||||
MQTT_OnPublished(&mqttClient, mqttPublishedCb); |
// MQTT_OnPublished(&mqttClient, mqttPublishedCb);
|
||||||
MQTT_OnData(&mqttClient, mqttDataCb); |
// MQTT_OnData(&mqttClient, mqttDataCb);
|
||||||
} |
} |
Loading…
Reference in new issue