@@ -114,7 +114,11 @@ void createDiscovery(char* sensor_type,
114114 if (child_device) {
115115 StaticJsonBuffer<JSON_MSG_BUFFER> jsonDeviceBuffer;
116116 JsonObject& device = jsonDeviceBuffer.createObject ();
117+ char JSONmessageBuffer[JSON_MSG_BUFFER];
118+ modules.printTo (JSONmessageBuffer, sizeof (JSONmessageBuffer));
119+ Log.notice (F (" Received json : %s" CR), JSONmessageBuffer);
117120 device.set (" name" , gateway_name);
121+ device.set (" model" , JSONmessageBuffer);
118122 device.set (" manufacturer" , DEVICEMANUFACTURER);
119123 device.set (" sw_version" , OMG_VERSION);
120124 JsonArray& identifiers = device.createNestedArray (" identifiers" );
@@ -128,21 +132,63 @@ void createDiscovery(char* sensor_type,
128132void pubMqttDiscovery () {
129133 Log.trace (F (" omgStatusDiscovery" CR));
130134 createDiscovery (" binary_sensor" , // set Type
131- will_Topic, Gateway_Name , (char *)getUniqueId (" " , " " ).c_str (), // set state_topic,name,uniqueId
135+ will_Topic, " SYS: Connectivity " , (char *)getUniqueId (" connectivity " , " " ).c_str (), // set state_topic,name,uniqueId
132136 will_Topic, " connectivity" , " " , // set availability_topic,device_class,value_template,
133137 Gateway_AnnouncementMsg, will_Message, " " , // set,payload_on,payload_off,unit_of_meas,
134138 0 , // set off_delay
135- Gateway_AnnouncementMsg, will_Message, false , " " // set,payload_avalaible,payload_not avalaible ,is a child device, command topic
139+ Gateway_AnnouncementMsg, will_Message, true , " " // set,payload_avalaible,payload_not avalaible ,is a child device, command topic
136140 );
141+ createDiscovery (" sensor" , // set Type
142+ subjectSYStoMQTT, " SYS: Uptime" , (char *)getUniqueId (" uptime" , " " ).c_str (), // set state_topic,name,uniqueId
143+ " " , " " , " {{ value_json.uptime }}" , // set availability_topic,device_class,value_template,
144+ " " , " " , " s" , // set,payload_on,payload_off,unit_of_meas,
145+ 0 , // set off_delay
146+ " " , " " , true , " " // set,payload_avalaible,payload_not avalaible ,is a child device, command topic
147+ );
148+
149+ # if defined(ESP8266) || defined(ESP32)
150+ createDiscovery (" sensor" , // set Type
151+ subjectSYStoMQTT, " SYS: Free memory" , (char *)getUniqueId (" freemem" , " " ).c_str (), // set state_topic,name,uniqueId
152+ " " , " " , " {{ value_json.freemem }}" , // set availability_topic,device_class,value_template,
153+ " " , " " , " B" , // set,payload_on,payload_off,unit_of_meas,
154+ 0 , // set off_delay
155+ " " , " " , true , " " // set,payload_avalaible,payload_not avalaible ,is a child device, command topic
156+ );
157+ createDiscovery (" sensor" , // set Type
158+ subjectSYStoMQTT, " SYS: IP" , (char *)getUniqueId (" ip" , " " ).c_str (), // set state_topic,name,uniqueId
159+ " " , " " , " {{ value_json.ip }}" , // set availability_topic,device_class,value_template,
160+ " " , " " , " " , // set,payload_on,payload_off,unit_of_meas,
161+ 0 , // set off_delay
162+ " " , " " , true , " " // set,payload_avalaible,payload_not avalaible ,is a child device, command topic
163+ );
164+ # ifndef ESP32_ETHERNET
165+ createDiscovery (" sensor" , // set Type
166+ subjectSYStoMQTT, " SYS: Rssi" , (char *)getUniqueId (" rssi" , " " ).c_str (), // set state_topic,name,uniqueId
167+ " " , " " , " {{ value_json.rssi }}" , // set availability_topic,device_class,value_template,
168+ " " , " " , " dB" , // set,payload_on,payload_off,unit_of_meas,
169+ 0 , // set off_delay
170+ " " , " " , true , " " // set,payload_avalaible,payload_not avalaible ,is a child device, command topic
171+ );
172+ # endif
173+ # endif
174+ # ifdef ESP32
175+ createDiscovery (" sensor" , // set Type
176+ subjectSYStoMQTT, " SYS: Low Power Mode" , (char *)getUniqueId (" lowpowermode" , " " ).c_str (), // set state_topic,name,uniqueId
177+ " " , " " , " {{ value_json.lowpowermode }}" , // set availability_topic,device_class,value_template,
178+ " " , " " , " " , // set,payload_on,payload_off,unit_of_meas,
179+ 0 , // set off_delay
180+ " " , " " , true , " " // set,payload_avalaible,payload_not avalaible ,is a child device, command topic
181+ );
182+ # endif
137183 createDiscovery (" switch" , // set Type
138- will_Topic, " restart OMG " , (char *)getUniqueId (" restart" , " " ).c_str (), // set state_topic,name,uniqueId
184+ will_Topic, " SYS: Restart gateway " , (char *)getUniqueId (" restart" , " " ).c_str (), // set state_topic,name,uniqueId
139185 will_Topic, " " , " " , // set availability_topic,device_class,value_template,
140186 " {\" cmd\" :\" restart\" }" , " " , " " , // set,payload_on,payload_off,unit_of_meas,
141187 0 , // set off_delay
142188 Gateway_AnnouncementMsg, will_Message, true , subjectMQTTtoSYSset // set,payload_avalaible,payload_not avalaible ,is a child device, command topic
143189 );
144190 createDiscovery (" switch" , // set Type
145- will_Topic, " erase OMG " , (char *)getUniqueId (" erase" , " " ).c_str (), // set state_topic,name,uniqueId
191+ will_Topic, " SYS: Erase credentials " , (char *)getUniqueId (" erase" , " " ).c_str (), // set state_topic,name,uniqueId
146192 will_Topic, " " , " " , // set availability_topic,device_class,value_template,
147193 " {\" cmd\" :\" erase\" }" , " " , " " , // set,payload_on,payload_off,unit_of_meas,
148194 0 , // set off_delay
@@ -476,18 +522,34 @@ void pubMqttDiscovery() {
476522# endif
477523
478524# ifdef ZgatewayBT
479- // Sensor to display BT received value
480- Log.trace (F (" gatewayBTDiscovery" CR));
481- char * gatewayBT[8 ] = {" sensor" , " gatewayBT" , " " , " " , jsonId, " " , " " , " " };
482- // component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
483-
484- Log.trace (F (" CreateDiscoverySensor" CR));
485- // trc(gatewayBT[1]);
486- createDiscovery (gatewayBT[0 ],
487- subjectBTtoMQTT, gatewayBT[1 ], (char *)getUniqueId (gatewayBT[1 ], gatewayBT[2 ]).c_str (),
488- will_Topic, gatewayBT[3 ], gatewayBT[4 ],
489- gatewayBT[5 ], gatewayBT[6 ], gatewayBT[7 ],
490- 0 , " " , " " , true , " " );
525+ createDiscovery (" sensor" , // set Type
526+ subjectSYStoMQTT, " BT: Interval between scans" , (char *)getUniqueId (" interval" , " " ).c_str (), // set state_topic,name,uniqueId
527+ " " , " " , " {{ value_json.interval }}" , // set availability_topic,device_class,value_template,
528+ " " , " " , " ms" , // set,payload_on,payload_off,unit_of_meas,
529+ 0 , // set off_delay
530+ " " , " " , true , " " // set,payload_avalaible,payload_not avalaible ,is a child device, command topic
531+ );
532+ createDiscovery (" sensor" , // set Type
533+ subjectSYStoMQTT, " BT: Connnect every X scan(s)" , (char *)getUniqueId (" scanbcnct" , " " ).c_str (), // set state_topic,name,uniqueId
534+ " " , " " , " {{ value_json.scanbcnct }}" , // set availability_topic,device_class,value_template,
535+ " " , " " , " " , // set,payload_on,payload_off,unit_of_meas,
536+ 0 , // set off_delay
537+ " " , " " , true , " " // set,payload_avalaible,payload_not avalaible ,is a child device, command topic
538+ );
539+ createDiscovery (" switch" , // set Type
540+ will_Topic, " BT: Force scan" , (char *)getUniqueId (" force_scan" , " " ).c_str (), // set state_topic,name,uniqueId
541+ will_Topic, " " , " " , // set availability_topic,device_class,value_template,
542+ " {\" interval\" :0}" , " " , " " , // set,payload_on,payload_off,unit_of_meas,
543+ 0 , // set off_delay
544+ Gateway_AnnouncementMsg, will_Message, true , subjectMQTTtoBTset // set,payload_avalaible,payload_not avalaible ,is a child device, command topic
545+ );
546+ createDiscovery (" switch" , // set Type
547+ " " , " BT: Publish only sensors" , (char *)getUniqueId (" only_sensors" , " " ).c_str (), // set state_topic,name,uniqueId
548+ " " , " " , " " , // set availability_topic,device_class,value_template,
549+ " {\" onlysensors\" :true}" , " {\" onlysensors\" :false}" , " " , // set,payload_on,payload_off,unit_of_meas,
550+ 0 , // set off_delay
551+ Gateway_AnnouncementMsg, will_Message, true , subjectMQTTtoBTset // set,payload_avalaible,payload_not avalaible ,is a child device, command topic
552+ );
491553# endif
492554}
493555
0 commit comments