mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-03-09 08:47:55 +01:00
Resolved merge issues
This commit is contained in:
@@ -1256,41 +1256,6 @@ void get_Relay_PWM_Count(int *relayCount, int *pwmCount){
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief Sends HomeAssistant discovery MQTT messages.
|
||||
/// @param request
|
||||
/// @return
|
||||
int http_fn_ha_discovery(http_request_t *request) {
|
||||
int i;
|
||||
char topic[32];
|
||||
int relayCount=0;
|
||||
int pwmCount=0;
|
||||
|
||||
http_setup(request, httpMimeTypeText);
|
||||
get_Relay_PWM_Count(&relayCount, &pwmCount);
|
||||
|
||||
if ((relayCount == 0) && (pwmCount == 0)) {
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// @brief Computes the Relay and PWM count.
|
||||
/// @param relayCount
|
||||
/// @param pwmCount
|
||||
void get_Relay_PWM_Count(int *relayCount, int *pwmCount){
|
||||
(*relayCount) = 0;
|
||||
(*pwmCount) = 0;
|
||||
|
||||
for(int i = 0; i < PLATFORM_GPIO_MAX; i++) {
|
||||
int role = PIN_GetPinRoleForPinIndex(i);
|
||||
if(role == IOR_Relay || role == IOR_Relay_n || role == IOR_LED || role == IOR_LED_n) {
|
||||
(*relayCount)++;
|
||||
}
|
||||
else if(role == IOR_PWM || role == IOR_PWM_n) {
|
||||
(*pwmCount)++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief Sends HomeAssistant discovery MQTT messages.
|
||||
/// @param request
|
||||
/// @return
|
||||
@@ -1327,7 +1292,7 @@ int http_fn_ha_discovery(http_request_t *request) {
|
||||
|
||||
if(pwmCount > 0) {
|
||||
char tmp[64];
|
||||
const char *baseName = CFG_GetShortDeviceName();
|
||||
const char *shortDeviceName = CFG_GetShortDeviceName();
|
||||
|
||||
for(i = 0; i < CHANNEL_MAX; i++) {
|
||||
if(h_isChannelPWM(i)) {
|
||||
@@ -1336,7 +1301,7 @@ int http_fn_ha_discovery(http_request_t *request) {
|
||||
cJSON_AddStringToObject(dev_info->root, "on_cmd_type", "brightness"); //on_command_type
|
||||
cJSON_AddNumberToObject(dev_info->root, "bri_scl", 99); //brightness_scale
|
||||
|
||||
sprintf(tmp,"%s/%i/set",baseName,i);
|
||||
sprintf(tmp,"%s/%i/set",shortDeviceName,i);
|
||||
cJSON_AddStringToObject(dev_info->root, "bri_cmd_t", tmp); //brightness_command_topic
|
||||
|
||||
MQTT_QueuePublish(topic, dev_info->channel, hass_build_discovery_json(dev_info), OBK_PUBLISH_FLAG_RETAIN);
|
||||
@@ -1352,6 +1317,8 @@ int http_fn_ha_discovery(http_request_t *request) {
|
||||
int http_fn_ha_cfg(http_request_t *request) {
|
||||
int relayCount = 0;
|
||||
int pwmCount = 0;
|
||||
const char *shortDeviceName;
|
||||
const char *clientId;
|
||||
int i;
|
||||
char mqttAdded = 0;
|
||||
char *uniq_id;
|
||||
@@ -1437,15 +1404,10 @@ int http_fn_ha_cfg(http_request_t *request) {
|
||||
}
|
||||
|
||||
poststr(request,"</textarea>");
|
||||
|
||||
poststr(request, HomeAssistantDiscoveryScript);
|
||||
poststr(request,"<br/><div><label for=\"ha_disc_topic\">Discovery topic:</label><input id=\"ha_disc_topic\" value=\"homeassistant\"><button onclick=\"send_ha_disc();\">Start Home Assistant Discovery</button> <form action=\"cfg_mqtt\" style=\"display:inline-block;\"><button type=\"submit\">Configure MQTT</button></form></div><br/>");
|
||||
|
||||
poststr(request,htmlReturnToCfg);
|
||||
HTTP_AddBuildFooter(request);
|
||||
poststr(request,htmlEnd);
|
||||
|
||||
poststr(request,htmlFooterReturnToCfgLink);
|
||||
http_html_end(request);
|
||||
poststr(request, HomeAssistantDiscoveryScript);
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
@@ -1584,9 +1546,7 @@ int http_fn_cm(http_request_t *request) {
|
||||
|
||||
int http_fn_cfg(http_request_t *request) {
|
||||
http_setup(request, httpMimeTypeHTML);
|
||||
poststr(request,htmlHeader);
|
||||
HTTP_AddHeader(request);
|
||||
|
||||
http_html_start(request, "Config");
|
||||
postFormAction(request, "cfg_pins", "Configure Module");
|
||||
postFormAction(request, "cfg_generic", "Configure General");
|
||||
postFormAction(request, "cfg_startup", "Configure Startup");
|
||||
|
||||
@@ -397,7 +397,6 @@ static OBK_Publish_Result MQTT_PublishTopicToClient(mqtt_client_t *client, const
|
||||
err_t err;
|
||||
u8_t qos = 2; /* 0 1 or 2, see MQTT specification */
|
||||
u8_t retain = 0; /* No don't retain such crappy payload... */
|
||||
const char *clientId;
|
||||
|
||||
if(client==0)
|
||||
return OBK_PUBLISH_WAS_DISCONNECTED;
|
||||
@@ -430,8 +429,8 @@ static OBK_Publish_Result MQTT_PublishTopicToClient(mqtt_client_t *client, const
|
||||
|
||||
g_timeSinceLastMQTTPublish = 0;
|
||||
|
||||
char *pub_topic = (char *)os_malloc(strlen(sTopic) + 1 + strlen(sChannel) + 5 + 1);
|
||||
sprintf(pub_topic, "%s/%s%s", sTopic, sChannel, (appendGet == true ? "/get" : ""));
|
||||
char *pub_topic = (char *)os_malloc(strlen(sTopic) + 1 + strlen(sChannel) + 5 + 1); //5 for /get
|
||||
sprintf(pub_topic, "%s/%s%s", sTopic, sChannel, (appendGet == true ? "/get" : ""));
|
||||
addLogAdv(LOG_INFO,LOG_FEATURE_MQTT,"Publishing to %s retain=%i",pub_topic, retain);
|
||||
err = mqtt_publish(client, pub_topic, sVal, strlen(sVal), qos, retain, mqtt_pub_request_cb, 0);
|
||||
os_free(pub_topic);
|
||||
@@ -455,7 +454,7 @@ static OBK_Publish_Result MQTT_PublishTopicToClient(mqtt_client_t *client, const
|
||||
// for example, "obk0696FB33/voltage/get" is used to publish voltage from the sensor
|
||||
static OBK_Publish_Result MQTT_PublishMain(mqtt_client_t *client, const char *sChannel, const char *sVal, int flags, bool appendGet)
|
||||
{
|
||||
return MQTT_PublishTopicToClient(mqtt_client, CFG_GetShortDeviceName(), sChannel, sVal, flags, appendGet);
|
||||
return MQTT_PublishTopicToClient(mqtt_client, CFG_GetMQTTClientId(), sChannel, sVal, flags, appendGet);
|
||||
}
|
||||
|
||||
/// @brief Publish a MQTT message immediately.
|
||||
|
||||
Reference in New Issue
Block a user