mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-09 17:15:46 +00:00
some wemo progress based on the input from user - thx
This commit is contained in:
@ -230,7 +230,7 @@ static const char message_template[] =
|
||||
/*"DATE: Sat, 22 Oct 2016 14:44:26 GMT\r\n"*/ \
|
||||
;
|
||||
|
||||
void DRV_WEMO_Send_Advert_To(struct sockaddr_in *addr);
|
||||
void DRV_WEMO_Send_Advert_To(int mode, struct sockaddr_in *addr);
|
||||
|
||||
void DRV_SSDP_SendReply(struct sockaddr_in *addr, const char *message) {
|
||||
|
||||
@ -518,12 +518,19 @@ void DRV_SSDP_RunQuickTick() {
|
||||
if (!strncmp(udp_msgbuf, "M-SEARCH", 8)){
|
||||
// reply with our advert to the sender
|
||||
addLogAdv(LOG_EXTRADEBUG, LOG_FEATURE_HTTP,"Is MSEARCH - responding");
|
||||
if (strstr(udp_msgbuf, "urn:belkin:device:**")) {
|
||||
DRV_WEMO_Send_Advert_To(&addr);
|
||||
}
|
||||
else {
|
||||
DRV_SSDP_Send_Advert_To(&addr);
|
||||
if (DRV_IsRunning("WEMO")) {
|
||||
if (strcasestr(udp_msgbuf, "urn:belkin:device:**")) {
|
||||
DRV_WEMO_Send_Advert_To(1, &addr);
|
||||
return;
|
||||
}
|
||||
else if (strcasestr(udp_msgbuf, "upnp:rootdevice")
|
||||
|| strcasestr(udp_msgbuf, "ssdpsearch:all")
|
||||
|| strcasestr(udp_msgbuf, "ssdp:all")) {
|
||||
DRV_WEMO_Send_Advert_To(2, &addr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
DRV_SSDP_Send_Advert_To(&addr);
|
||||
}
|
||||
|
||||
// our NOTIFTY like:
|
||||
|
||||
@ -67,16 +67,84 @@ const char *g_wemo_msearch =
|
||||
"USN: uuid:%s::%s\r\n" // type1 = urn:Belkin:device:**, type2 = upnp:rootdevice
|
||||
"X-User-Agent: redsonic\r\n"
|
||||
"\r\n";
|
||||
|
||||
|
||||
const char *g_wemo_metaService =
|
||||
"<scpd xmlns=\"urn:Belkin:service-1-0\">"
|
||||
"<specVersion>"
|
||||
"<major>1</major>"
|
||||
"<minor>0</minor>"
|
||||
"</specVersion>"
|
||||
"<actionList>"
|
||||
"<action>"
|
||||
"<name>GetMetaInfo</name>"
|
||||
"<argumentList>"
|
||||
"<retval />"
|
||||
"<name>GetMetaInfo</name>"
|
||||
"<relatedStateVariable>MetaInfo</relatedStateVariable>"
|
||||
"<direction>in</direction>"
|
||||
"</argumentList>"
|
||||
"</action>"
|
||||
"</actionList>"
|
||||
"<serviceStateTable>"
|
||||
"<stateVariable sendEvents=\"yes\">"
|
||||
"<name>MetaInfo</name>"
|
||||
"<dataType>string</dataType>"
|
||||
"<defaultValue>0</defaultValue>"
|
||||
"</stateVariable>"
|
||||
"</serviceStateTable>"
|
||||
"</scpd>\r\n\r\n";
|
||||
|
||||
const char *g_wemo_eventService =
|
||||
"<scpd xmlns=\"urn:Belkin:service-1-0\">"
|
||||
"<actionList>"
|
||||
"<action>"
|
||||
"<name>SetBinaryState</name>"
|
||||
"<argumentList>"
|
||||
"<argument>"
|
||||
"<retval/>"
|
||||
"<name>BinaryState</name>"
|
||||
"<relatedStateVariable>BinaryState</relatedStateVariable>"
|
||||
"<direction>in</direction>"
|
||||
"</argument>"
|
||||
"</argumentList>"
|
||||
"</action>"
|
||||
"<action>"
|
||||
"<name>GetBinaryState</name>"
|
||||
"<argumentList>"
|
||||
"<argument>"
|
||||
"<retval/>"
|
||||
"<name>BinaryState</name>"
|
||||
"<relatedStateVariable>BinaryState</relatedStateVariable>"
|
||||
"<direction>out</direction>"
|
||||
"</argument>"
|
||||
"</argumentList>"
|
||||
"</action>"
|
||||
"</actionList>"
|
||||
"<serviceStateTable>"
|
||||
"<stateVariable sendEvents=\"yes\">"
|
||||
"<name>BinaryState</name>"
|
||||
"<dataType>bool</dataType>"
|
||||
"<defaultValue>0</defaultValue>"
|
||||
"</stateVariable>"
|
||||
"<stateVariable sendEvents=\"yes\">"
|
||||
"<name>level</name>"
|
||||
"<dataType>string</dataType>"
|
||||
"<defaultValue>0</defaultValue>"
|
||||
"</stateVariable>"
|
||||
"</serviceStateTable>"
|
||||
"</scpd>\r\n\r\n";
|
||||
static char *g_serial = 0;
|
||||
static char *g_uid = 0;
|
||||
static int outBufferLen = 0;
|
||||
static char *buffer_out = 0;
|
||||
static int stat_searchesReceived = 0;
|
||||
static int stat_setupXMLVisits = 0;
|
||||
static int stat_metaServiceXMLVisits = 0;
|
||||
static int stat_eventsReceived = 0;
|
||||
static int stat_eventServiceXMLVisits = 0;
|
||||
|
||||
void DRV_WEMO_Send_Advert_To(struct sockaddr_in *addr) {
|
||||
char message[128];
|
||||
void DRV_WEMO_Send_Advert_To(int mode, struct sockaddr_in *addr) {
|
||||
const char *useType;
|
||||
|
||||
if (g_uid == 0) {
|
||||
@ -86,7 +154,14 @@ void DRV_WEMO_Send_Advert_To(struct sockaddr_in *addr) {
|
||||
|
||||
stat_searchesReceived++;
|
||||
|
||||
useType = "urn:Belkin:device:**";
|
||||
if (mode == 1) {
|
||||
useType = "urn:Belkin:device:**";
|
||||
}
|
||||
else {
|
||||
useType = "upnp:rootdevice";
|
||||
}
|
||||
|
||||
addLogAdv(LOG_EXTRADEBUG, LOG_FEATURE_HTTP, "WEMO - sends reply %s",useType);
|
||||
|
||||
if (buffer_out == 0) {
|
||||
outBufferLen = strlen(g_wemo_msearch) + 256;
|
||||
@ -94,12 +169,13 @@ void DRV_WEMO_Send_Advert_To(struct sockaddr_in *addr) {
|
||||
}
|
||||
snprintf(buffer_out, outBufferLen, g_wemo_msearch, HAL_GetMyIPString(), useType, g_uid, useType);
|
||||
|
||||
DRV_SSDP_SendReply(addr, message);
|
||||
addLogAdv(LOG_EXTRADEBUG, LOG_FEATURE_HTTP, "WEMO - Sending %s", buffer_out);
|
||||
DRV_SSDP_SendReply(addr, buffer_out);
|
||||
}
|
||||
|
||||
void WEMO_AppendInformationToHTTPIndexPage(http_request_t* request) {
|
||||
hprintf255(request, "<h4>WEMO: MSEARCH received %i, setup.xml visits %i, events %i </h4>",
|
||||
stat_searchesReceived, stat_setupXMLVisits, stat_eventsReceived);
|
||||
hprintf255(request, "<h4>WEMO: searches %i, setup %i, events %i, mService %i, event %i </h4>",
|
||||
stat_searchesReceived, stat_setupXMLVisits, stat_eventsReceived, stat_metaServiceXMLVisits, stat_eventServiceXMLVisits);
|
||||
|
||||
}
|
||||
static int WEMO_BasicEvent1(http_request_t* request) {
|
||||
@ -114,10 +190,22 @@ static int WEMO_BasicEvent1(http_request_t* request) {
|
||||
}
|
||||
static int WEMO_EventService(http_request_t* request) {
|
||||
|
||||
http_setup(request, httpMimeTypeXML);
|
||||
poststr(request, g_wemo_eventService);
|
||||
poststr(request, NULL);
|
||||
|
||||
stat_eventServiceXMLVisits++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
static int WEMO_MetaInfoService(http_request_t* request) {
|
||||
|
||||
http_setup(request, httpMimeTypeXML);
|
||||
poststr(request, g_wemo_metaService);
|
||||
poststr(request, NULL);
|
||||
|
||||
stat_metaServiceXMLVisits++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
static int WEMO_Setup(http_request_t* request) {
|
||||
|
||||
@ -780,12 +780,26 @@ int http_fn_index(http_request_t* request) {
|
||||
{
|
||||
hprintf255(request, "<h5>Wifi RSSI: %s (%idBm)</h5>", str_rssi[wifi_rssi_scale(HAL_GetWifiStrength())], HAL_GetWifiStrength());
|
||||
}
|
||||
hprintf255(request, "<h5>MQTT State: %s RES: %d(%s)<br>", (Main_HasMQTTConnected() == 1) ? "connected" : "disconnected",
|
||||
MQTT_GetConnectResult(), get_error_name(MQTT_GetConnectResult()));
|
||||
hprintf255(request, "MQTT ErrMsg: %s <br>", (MQTT_GetStatusMessage() != NULL) ? MQTT_GetStatusMessage() : "");
|
||||
hprintf255(request, "MQTT Stats:CONN: %d PUB: %d RECV: %d ERR: %d </h5>", MQTT_GetConnectEvents(),
|
||||
MQTT_GetPublishEventCounter(), MQTT_GetReceivedEventCounter(), MQTT_GetPublishErrorCounter());
|
||||
|
||||
if (CFG_GetMQTTHost()[0] == 0) {
|
||||
hprintf255(request, "<h5>MQTT State: not configured<br>");
|
||||
}
|
||||
else {
|
||||
const char *stateStr;
|
||||
const char *colorStr;
|
||||
if (Main_HasMQTTConnected() == 1) {
|
||||
stateStr = "connected";
|
||||
colorStr = "green";
|
||||
}
|
||||
else {
|
||||
stateStr = "disconnected";
|
||||
colorStr = "yellow";
|
||||
}
|
||||
hprintf255(request, "<h5>MQTT State: <span style=\"color:%s\">%s</span> RES: %d(%s)<br>", colorStr,
|
||||
stateStr,MQTT_GetConnectResult(), get_error_name(MQTT_GetConnectResult()));
|
||||
hprintf255(request, "MQTT ErrMsg: %s <br>", (MQTT_GetStatusMessage() != NULL) ? MQTT_GetStatusMessage() : "");
|
||||
hprintf255(request, "MQTT Stats:CONN: %d PUB: %d RECV: %d ERR: %d </h5>", MQTT_GetConnectEvents(),
|
||||
MQTT_GetPublishEventCounter(), MQTT_GetReceivedEventCounter(), MQTT_GetPublishErrorCounter());
|
||||
}
|
||||
/* Format current PINS input state for all unused pins */
|
||||
if (CFG_HasFlag(OBK_FLAG_HTTP_PINMONITOR))
|
||||
{
|
||||
|
||||
@ -62,7 +62,49 @@ int vsprintf3(char *buffer, const char *fmt, va_list val) {
|
||||
|
||||
#endif
|
||||
|
||||
#if WINDOWS
|
||||
const char* strcasestr(const char* str1, const char* str2)
|
||||
{
|
||||
const char* p1 = str1;
|
||||
const char* p2 = str2;
|
||||
const char* r = *p2 == 0 ? str1 : 0;
|
||||
|
||||
while (*p1 != 0 && *p2 != 0)
|
||||
{
|
||||
if (tolower((unsigned char)*p1) == tolower((unsigned char)*p2))
|
||||
{
|
||||
if (r == 0)
|
||||
{
|
||||
r = p1;
|
||||
}
|
||||
|
||||
p2++;
|
||||
}
|
||||
else
|
||||
{
|
||||
p2 = str2;
|
||||
if (r != 0)
|
||||
{
|
||||
p1 = r + 1;
|
||||
}
|
||||
|
||||
if (tolower((unsigned char)*p1) == tolower((unsigned char)*p2))
|
||||
{
|
||||
r = p1;
|
||||
p2++;
|
||||
}
|
||||
else
|
||||
{
|
||||
r = 0;
|
||||
}
|
||||
}
|
||||
|
||||
p1++;
|
||||
}
|
||||
|
||||
return *p2 == 0 ? (char*)r : 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Why strdup breaks strings?
|
||||
// backlog lcd_clearAndGoto I2C1 0x23 1 1; lcd_print I2C1 0x23 Enabled
|
||||
|
||||
Reference in New Issue
Block a user