Base.ino 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Home Dynamic System v2
  3. * Designed by tobychui
  4. *
  5. * This is the base module for implementing the Home Dynamic v2 Protocol with ArozOS 1.0
  6. * For more examples, see other project folders.
  7. *
  8. */
  9. #include <ESP8266WiFi.h> // Include the Wi-Fi library
  10. #include <ESP8266WiFiMulti.h> // Include the Wi-Fi-Multi library
  11. #include <ESP8266mDNS.h> // Include the mDNS library
  12. ESP8266WiFiMulti wifiMulti; // Create an instance of the ESP8266WiFiMulti class, called 'wifiMulti'
  13. //Change the properties of the IoT device
  14. const String DeviceName = "HDSv2-Demo"; //The name of this IoT device
  15. //Change the WiFi Settings
  16. void WiFiConfig(){
  17. wifiMulti.addAP("Toby Room Automation", "homedynamicsystem");
  18. //Add more WiFi AP here if nessary
  19. //wifiMulti.addAP("ssid_from_AP_2", "your_password_for_AP_2");
  20. //wifiMulti.addAP("ssid_from_AP_3", "your_password_for_AP_3");
  21. }
  22. //Inject zeroconf attr into the MDNS respond (For scanning by ArozOS)
  23. void MDNSDynamicServiceTxtCallback(const MDNSResponder::hMDNSService p_hService) {
  24. //Define the domain of the HDSv2 devices
  25. MDNS.addDynamicServiceTxt(p_hService, "domain","hds.arozos.com");
  26. MDNS.addDynamicServiceTxt(p_hService, "protocol","hdsv2");
  27. //Define the OEM written values
  28. MDNS.addDynamicServiceTxt(p_hService, "uuid","00000000-0000-0000-0000-000000000000");
  29. MDNS.addDynamicServiceTxt(p_hService, "model","Generic");
  30. MDNS.addDynamicServiceTxt(p_hService, "vendor","HomeDynamic Project");
  31. MDNS.addDynamicServiceTxt(p_hService, "version_minor","0.00");
  32. MDNS.addDynamicServiceTxt(p_hService, "version_build","0");
  33. }
  34. void hostProbeResult(String p_pcDomainName, bool p_bProbeResult) {
  35. MDNS.setDynamicServiceTxtCallback(MDNSDynamicServiceTxtCallback);
  36. }
  37. void setup() {
  38. //Use 115200 baudrate on serial monitor if you want to see what is happening to the device
  39. Serial.begin(115200);
  40. delay(10);
  41. Serial.println('\n');
  42. WiFiConfig();
  43. Serial.println("Connecting ...");
  44. while (wifiMulti.run() != WL_CONNECTED) {
  45. delay(500);
  46. Serial.print('.');
  47. }
  48. Serial.println('\n');
  49. Serial.print("Connected to ");
  50. Serial.println(WiFi.SSID());
  51. Serial.print("IP address:\t");
  52. Serial.println(WiFi.localIP());
  53. MDNS.setHostProbeResultCallback(hostProbeResult);
  54. if (!MDNS.begin(DeviceName)) { // Start the mDNS responder for esp8266.local
  55. Serial.println("Error setting up MDNS responder!");
  56. }
  57. //Advertise the port that you are using
  58. MDNS.addService("http", "tcp", 12110);
  59. Serial.println("mDNS responder started");
  60. }
  61. void loop() {
  62. MDNS.update();
  63. }