Skip to content

Commit

Permalink
SSDP
Browse files Browse the repository at this point in the history
  • Loading branch information
gskjold committed Nov 18, 2023
1 parent ece5e58 commit 3056210
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/SvelteUi/include/AmsWebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>
#include <ESP8266SSDP.h>
#elif defined(ESP32) // ARDUINO_ARCH_ESP32
#include <WiFi.h>
#include <WebServer.h>
#include <HTTPClient.h>
#include <HTTPUpdate.h>
#include <ESP32SSDP.h>
#else
#warning "Unsupported board type"
#endif
Expand Down Expand Up @@ -120,6 +122,7 @@ class AmsWebServer {
void notFound();
void redirectToMain();
void robotstxt();
void ssdpSchema();
};

#endif
6 changes: 6 additions & 0 deletions lib/SvelteUi/src/AmsWebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ void AmsWebServer::setup(AmsConfiguration* config, GpioConfig* gpioConfig, Meter
server.on(F("/library/test/success.html"), HTTP_GET, std::bind(&AmsWebServer::redirectToMain, this)); // Apple connectivity check: http://www.apple.com/library/test/success.html
*/

server.on("/ssdp/schema.xml", HTTP_GET, std::bind(&AmsWebServer::ssdpSchema, this));

server.onNotFound(std::bind(&AmsWebServer::notFound, this));

server.begin(); // Web server start
Expand Down Expand Up @@ -2329,4 +2331,8 @@ void AmsWebServer::configFileUpload() {
void AmsWebServer::redirectToMain() {
server.sendHeader(HEADER_LOCATION,F("/"));
server.send(302);
}

void AmsWebServer::ssdpSchema() {
SSDP.schema(server.client());
}
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ build_flags =
-fexceptions

[esp32]
lib_deps = WiFi, ESPmDNS, WiFiClientSecure, HTTPClient, FS, Update, HTTPUpdate, WebServer, ${common.lib_deps}
lib_deps = WiFi, ESPmDNS, WiFiClientSecure, HTTPClient, FS, Update, HTTPUpdate, WebServer, ESP32 Async UDP, ESP32SSDP, ${common.lib_deps}

[env:esp8266]
platform = [email protected]
Expand All @@ -27,7 +27,7 @@ board_build.ldscript = eagle.flash.4m2m.ld
build_flags = ${common.build_flags}
lib_ldf_mode = off
lib_compat_mode = off
lib_deps = ESP8266WiFi, ESP8266mDNS, ESP8266WebServer, ESP8266HTTPClient, ESP8266httpUpdate, ${common.lib_deps}
lib_deps = ESP8266WiFi, ESP8266mDNS, ESP8266WebServer, ESP8266HTTPClient, ESP8266httpUpdate, ESP8266SSDP, ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
extra_scripts = ${common.extra_scripts}

Expand Down
2 changes: 2 additions & 0 deletions scripts/mkzip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
find -name firmware.bin | while read firmware;do
dir=`dirname $firmware`
env=`basename $dir`
echo "Found firmware in $dir, using env '$env'"

if [ -f scripts/$env/mkzip.sh ];then
echo "Building zip for env '$env'"
chmod +x scripts/$env/mkzip.sh
Expand Down
29 changes: 29 additions & 0 deletions src/AmsToMqttBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1696,6 +1696,35 @@ void WiFi_post_connect() {
mqttEnabled = strlen(mqttConfig.host) > 0;
ws.setMqttEnabled(mqttEnabled);
}

sprintf_P((char*) commonBuffer, PSTR("AMS reader %s"), wifi.hostname);

SSDP.setSchemaURL("ssdp/schema.xml");
SSDP.setHTTPPort(80);
SSDP.setName((char*) commonBuffer);
//SSDP.setSerialNumber("0");
SSDP.setURL("/");
SSDP.setModelName("AMS reader");
//SSDP.setModelNumber("929000226503");
SSDP.setModelURL("https://amsleser.no");
SSDP.setManufacturer("Utilitech AS");
SSDP.setManufacturerURL("http://amsleser.no");
SSDP.setDeviceType("rootdevice");
sprintf_P((char*) commonBuffer, PSTR("amsreader/%s"), FirmwareVersion::VersionString);
#if defined(ESP32)
SSDP.setModelDescription("Device to read data from electric smart meters");
SSDP.setServerName((char*) commonBuffer);
//SSDP.setUUID("");
SSDP.setIcons( "<icon>"
"<mimetype>image/svg+xml</mimetype>"
"<height>48</height>"
"<width>48</width>"
"<depth>24</depth>"
"<url>favicon.svg</url>"
"</icon>");
#endif
SSDP.setInterval(300);
SSDP.begin();
}

int16_t unwrapData(uint8_t *buf, DataParserContext &context) {
Expand Down
4 changes: 3 additions & 1 deletion src/AmsToMqttBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ESP8266SSDP.h>
#elif defined(ESP32)
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <ESPmDNS.h>
#include "Update.h"
#include <Update.h>
#include <ESP32SSDP.h>
#endif

#include "LittleFS.h"
Expand Down

0 comments on commit 3056210

Please sign in to comment.