Philips Hue Leuchten mit Enigmalight steuern

    Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

    • Moinsen,

      ich habe soeben auf meiner Vu+ Uno 4k mit Enigmalight und einem HueBridge Emulator und einer selbstgebauten ESP8266 Lösung als LED Lampe das Ambilight zum laufen bekommen.

      Bei mir waren die Punkte des Keys das Problem.
      Ich habe mittels der Anleitung hier und teilen der Anleitung aus dem Dreamboard dann die Funktion herstellen können.

      Effektiv hab ich nur das Useranlegen von dor - denn bei mir kam als ich mit dem API Debugger (http://<IP der Bridge>/debug/clip.html) mal die commandos aus dem Pythonscript ausführte immer nur "unauthorized user".
      Somit mittels:
      Und dem Click auf "Post" einen neuen User angelegt und aus dem Ergebnis den Usernamen genommen und als "key" in dem Python script an den 2 Stellen hinterlegt.

      Schwups schon ging es mit der Anleitung von Seite 1.

      Da ich mit meinem Emulator der Bridge die aktuellste App und auch Hue Sync am PC nutzen kann - sollte das für alle Bridgebesitzer ebenfalls gehen.
      Mit dem Debugger bekommt man auch sehr angenehm die nötigen Lampennummern und Co.

      Irgendwie fehlte oben auch noch der Codeblock zum anlegen des Users (ein Edit scheint nicht machbar zu sein nach X Minuten...)

      Quellcode

      1. {
      2. "devicetype":"myapplication#enigmalight",
      3. "generateclientkey":true
      4. }
      Habe auch noch eine Änderung umgesetzt.

      Das hier:

      Quellcode

      1. os.system("curl -d '{\"on\":false}' -X PUT 192.168.0.15/api/bec6b0821d9d11ea86adb827ebcb496a/groups/0/action")

      Schaltet immer alle Lampen die es global gibt ab... für micht nicht sinnvol, da noch andere Räume existieren.
      Habe dort die Gruppe von genau dieser Lampe angegeben - einfach die "0" zu dem ersetzen was eure Gruppe ist, dann wird da auch nicht einfach anderes abgeschaltet (vor allem wird es das dauerhaft solange der Zweig der Schleife ausgeführt wird - denke das bau ich auch noch um zu einmalig bis der obere Zweig mal wieder genutzt wurde)

      Tja schade das mit dem Edit :D (alternativ bin ich gerade unfähig)

      Also ich hab nun 3 Stellen geändert:
      - Es zielt nicht mehr auf eine Lampe sondern auf eine Entertainmentgruppe (Mittels HUE App erstellt)
      - Es schaltet nicht mehr solange der Loop läuft dauerhaft ab sondern nur einmal
      - Es schaltet nur die Entertainment Gruppe ab

      Somit laufen alle anderen Hue Lampen und gehen nicht ständig aus ;)

      Anleitung:

      1. Enigmalight installieren
      2. Curl vom Feed installieren (opkg install curl) (wenn überhaupt nötig - war bei mir bereits installiert)
      4. Die "enigmalight_hue_LR.py" oder "enigmalight_hue_1x.py" und "rgb_xy.py" in den "\home\elight-addons\wifilight\philips_hue" Ordner kopieren (anderer Ordnerpfad ist auch möglich, muss dann nur in der config angepasst werden!)
      5. enigmalight.conf nach /etc kopieren

      - User in der Bridge anlegen

      Quellcode

      1. {
      2. "devicetype":"myapplication#enigmalight",
      3. "generateclientkey":true
      4. }
      Den da zurück bekommenen usernamen nutzen als "key" für die enigmalight_hue_1x.py (oder wieviele Lampen ihr da auch drin habt oder welche Version ihr da nutzt).

      - Infos einholen -

      Mit dem API Debugger (http://<IP der Bridge>/debug/clip.html) die Entertainmentgruppennummer ausfindig machen:

      Quellcode

      1. "/api/"Usernamen aus der Antowrt der Brdige hier einfügen"/groups"
      Diese wird ebenfalls in der enigmalight_hue_1x.py oder ähnlich lautend benutzt.

      Mit dem API Debugger die "Gamut" Art/den Typ der Lampe herausfinden

      Quellcode

      1. "/api/"Usernamen aus der Antowrt der Brdige hier einfügen"/lights"
      - enigmalight_hue_1x.py anpassen-

      In der unten angehängten Version sind Änderungen in folgenden Zeilen Änderungen zu machen:

      Gamut: 7 & 13
      Entertainmentgruppenummer: 18 & 59
      Username(variable heißt key): 15 & 59

      Meine enigmalight_hue_1x.py:

      Python-Quellcode: enigmalight_hue_1x.py

      1. import sys
      2. import os
      3. import time
      4. import json
      5. import httplib
      6. from rgb_xy import Converter
      7. from rgb_xy import GamutC # or GamutB, GamutC (you must look for the type of your lamps)
      8. counter = 12
      9. off = 0
      10. def popen():
      11. converter = Converter(GamutC)
      12. spidev = file( os.getcwd()+'/aufruf.log', "wb")
      13. key = "Username vom angelegten User HIER einfügen"
      14. ip = "Bridge IP"
      15. url = '/api/' + key + '/groups/'
      16. lurl = url + '5/state' # die 1 ersetzen mit der Nummer deiner Entertainmentgruppe
      17. #Ebenfalls Gruppennummer und key in Zeile 59 angeben!
      18. MINIMAL_VALUE=0.000000000
      19. while True:
      20. eingabe = sys.stdin.readline()
      21. if len(eingabe)>0:
      22. global counter
      23. counter += 1
      24. off = 1
      25. try:
      26. lr,lg,lb,x = eingabe.split(' ')
      27. except ValueError:
      28. spidev.write("Not enough input parameter, do you have the same amount of lights (channels) in your enigmalight config?")
      29. spidev.flush()
      30. raise
      31. lr = (float(lr))*255
      32. lg = (float(lg))*255
      33. lb = (float(lb))*255
      34. lll = calcLuminance(lr,lg,lb)
      35. if (counter>=13):
      36. connection = httplib.HTTPConnection(ip, timeout=10)
      37. lparams = {'xy': converter.rgb_to_xy(lr,lg,lb), 'colormode': 'xy', 'bri': int(lll), 'on': True}
      38. connection.request('PUT', lurl, json.dumps(lparams))
      39. response = connection.getresponse()
      40. connection.close()
      41. counter=0
      42. else:
      43. if off == 1:
      44. off = 0
      45. os.system("curl -d '{\"on\":false}' -X PUT 192.168.0.15/api/bec6b0821d9d11ea86adb827ebcb496a/groups/5/action")
      46. break
      47. def calcLuminance(r,g,b):
      48. LUM_VALUE=5
      49. luminance=1
      50. if (r + g + b > 1):
      51. luminance= r + g + b + LUM_VALUE
      52. if (luminance>=255):
      53. luminance=254
      54. return luminance
      55. import time
      56. time.sleep(1)
      57. popen()
      Alles anzeigen

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von hgdo () aus folgendem Grund: 3 Beiträge zusammengefasst

    • Kann mir vielleicht jemand beim Kompilieren helfen, kann ich das am Mac machen?

      Würde das gerne mit der Steuerung über den Entertainmentbereich probieren, kenn mich aber mit kompilieren nicht aus? Was muss ich da machen oder kann das jemand für mich machen? Ich hänge mal die Datei an, für den Fall das das jemand für mich machen kann. Das wäre total super.

      dtls_client.c.txt
    • Das dürfte unter VTI nicht funktionieren. Die hier entstehende Datei lässt sich nicht auf einer VU ausführen!

      Grundsätzlich sollten die hierfür notwendigen Bibliotheken und dem hier schon bereits beschriebenen Quellcode ausreichen, wenn Python3 unterstützt würde. Dies scheint hier aber derzeit nicht in Planung.

      Abhilfe schafft dann nur die Installation von "pip" und die anschließende Installation der Bibliotheken sslpsk und "Dtls" über "pip" ...

      Aber auch hier sind die Hürden vorhanden: "DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at Release process — pip 20.0.dev0 documentation"
    • Philips Hue Leuchten mit Enigmalight steuern

      Ich stelle mich wahrscheinlich blöd an, aber ich scheitere recht früh bei der Anleitung. Auf der debug/clip.html Seite bekomme ich keine Rückmeldung, wenn ich wie beschrieben /api/newdeveloper eingebe und GET klicke... bin im gleichen Netzwerk, hab es am Laptop und am Handy probiert... in Firefox und Chrome...
      Jemand ne Idee?
    • Master Nick schrieb:

      Mit dem API Debugger die "Gamut" Art/den Typ der Lampe herausfinden
      Und wie sollte die enigmalight_hue_1x.py aussehen wenn ich Lampen von Phillips verwende die unterschiedliche Gamuts haben? Mein Entertainmentbereich besteht aus 3 Hue Lampen, zwei davon haben Gamut C und eine Gamut A ?(

      Und was ist hier mein Entertainmentbereich? 8 oder 5,6,4 ?

      Quellcode

      1. "8": {
      2. "name": "Entertainment-Bereich",
      3. "lights": [
      4. "5",
      5. "6",
      6. "4"

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von bimmler ()

    • Alle Files sind nun da wo sie sein sollen, und Enigmalight sagt "läuft nicht"

      Doch wie ist jetzt generell Enigmalight einzustellen? Auch war unter /home/elight-addons/ nichts weiter, sodas ich die Ordner dann selbst erstellt habe. /home/elight-addons/wifilight/philips_hue.
    • Ich beziehe mich auf die Anleitung aus Post 261.

      Über den Browser kann ich die API ansprechen, die Lampen bzw. die Gruppe reagiert. Das heisst, ich hab den richtigen Key und die richtige Gruppe. Auch stimmt der Pfad für die enigmalight_hue_1x.py in der Enigmalight.conf, diese Ordnerstruktur habe ich erstellt und die Rechte auf 755 geändert.

      Wenn ich jedoch Enigmalight öffne und Grün drücke, passiert nichts.

      Hier ein Log was unter /home/elight-addons/.enigmalight lag, sieht aus als ob nur die Hälfte von dem was passieren soll, passiert:
      Spoiler anzeigen


      Quellcode

      1. 21:03:50.321152 [InitLog] start of log /home/elight-addons/.enigmalight/enigmalight.log
      2. 21:03:50.321512 [CConfig::LoadConfigFromFile] Opening /etc/enigmalight.conf
      3. 21:03:50.322448 [CConfig::CheckConfig] checking config lines
      4. 21:03:50.322888 [CConfig::CheckConfig] config lines valid
      5. 21:03:50.326019 [CConfig::LoadConfigFromFile] Opening /etc/enigmalight.conf
      6. 21:03:50.327055 [CConfig::BuildConfig] building config
      7. 21:03:50.328023 [CConfig::BuildConfig] built config successfully
      8. 21:03:50.328074 [main] Start device 1 from 1
      9. 21:03:50.328582 [CDevice::Process] ambilight: starting with output "python /home/elight-addons/wifilight/philips_hue/enigmalight_hue_1x.py"
      10. 21:03:50.328643 [CDevice::Process] ambilight: setting up
      11. 21:03:50.329157 [CEnigmaLight::SetColorSequence] Set colorsequence to RGB
      12. 21:03:50.329241 [CMainLoop::Process] Start EnigmaLight Server
      13. 21:03:50.329272 [CMainLoop::Process] Opening listening socket on *:19333
      14. 21:03:50.329506 [CGuiServer::Process] Start GuiServer
      15. 21:03:50.329562 [CGuiServer::Process] Opening listening socket for Enigma2 GUI on 127.0.0.1:6767
      16. 21:03:50.329603 [CDevice::Process] ambilight: setup succeeded
      17. 21:03:51.276448 [CGuiServer::Process] GuiClient 127.0.0.1:56447 connected successful.
      18. 21:03:51.330802 [CMainLoop::Cleanup] Removing clients
      19. 21:03:51.330895 [CMainLoop::Cleanup] Closing listening socket
      20. 21:03:51.331144 [CFlagManager::SetVideoGamma] Gamma not set, using 2.2 since this is default for video
      21. 21:03:51.331191 [CMainLoop::Process] Starting grabber..
      22. 21:03:51.331266 [CGrabber::Setup] Lights: 1, Cluster leds: 1 as one led
      23. 21:03:51.331294 [CGrabber::Setup] Channels: 3
      24. 21:03:51.331320 [CGrabber::Setup] Interval: 0.10
      25. 21:03:51.331345 [CGrabber::Run] Mode -> Dynamic
      26. 21:03:51.331371 [CGrabber::Run] Framegrabber initialized
      27. 21:03:51.331428 [CGrabber::Run] Framegrabber Image initialized
      28. 21:03:51.331459 [CGrabber::Run] Blackbar Detection initialized
      29. 21:03:51.331484 [CGrabber::Run] Framegrabber set up
      30. 21:03:51.331508 [CGrabber::Run] entering grabloop
      31. 21:03:51.382291 [CFrameGrabber::CheckRes] Set Scanrange to 120x67 (Source 538976288x538976288)
      32. 00:28:18.583050 [CBitmap::~CBitmap()] [Bitmap] Destroy bitmaps..
      33. 00:28:18.587117 [CMainLoop::Process] Start EnigmaLight Server
      34. 00:28:18.587166 [CMainLoop::Process] Opening listening socket on *:19333
      Alles anzeigen

      Gibt es jemanden der mit nem aktuellen VTI in 2020, der dies hier erfolgreich am laufen hat?

      Meine enigmalight.conf:
      Spoiler anzeigen

      Quellcode

      1. #[global]
      2. [device]
      3. name ambilight
      4. output python /home/elight-addons/wifilight/philips_hue/enigmalight_hue_1x.py
      5. channels 3
      6. type popen
      7. interval 200000
      8. debug off
      9. [color]
      10. name red
      11. rgb FF0000
      12. [color]
      13. name green
      14. rgb 00FF00
      15. [color]
      16. name blue
      17. rgb 0000FF
      18. [light]
      19. position top
      20. name 1HU
      21. color red ambilight 1
      22. color green ambilight 2
      23. color blue ambilight 3
      24. hscan 10 90
      25. vscan 10 90
      Alles anzeigen

      Meine enigmalight_hue_1x.py
      Spoiler anzeigen


      Quellcode

      1. import sys
      2. import os
      3. import time
      4. import json
      5. import httplib
      6. from rgb_xy import Converter
      7. from rgb_xy import GamutC # or GamutB, GamutC (you must look for the type of your lamps)
      8. counter = 12
      9. off = 0
      10. def popen():
      11. converter = Converter(GamutC)
      12. spidev = file( os.getcwd()+'/aufruf.log', "wb")
      13. key = "FaEBatAQW0fF12W-6LKW5cZDYkpsKTQo2v6S68Nz"
      14. ip = "192.168.178.20"
      15. url = '/api/' + key + '/groups/'
      16. lurl = url + '8/state' # die 1 ersetzen mit der Nummer deiner Entertainmentgruppe
      17. #Ebenfalls Gruppennummer und key in Zeile 59 angeben!
      18. MINIMAL_VALUE=0.000000000
      19. while True:
      20. eingabe = sys.stdin.readline()
      21. if len(eingabe)>0:
      22. global counter
      23. counter += 1
      24. off = 1
      25. try:
      26. lr,lg,lb,x = eingabe.split(' ')
      27. except ValueError:
      28. spidev.write("Not enough input parameter, do you have the same amount of lights (channels) in your enigmalight config?")
      29. spidev.flush()
      30. raise
      31. lr = (float(lr))*255
      32. lg = (float(lg))*255
      33. lb = (float(lb))*255
      34. lll = calcLuminance(lr,lg,lb)
      35. if (counter>=13):
      36. connection = httplib.HTTPConnection(ip, timeout=10)
      37. lparams = {'xy': converter.rgb_to_xy(lr,lg,lb), 'colormode': 'xy', 'bri': int(lll), 'on': True}
      38. connection.request('PUT', lurl, json.dumps(lparams))
      39. response = connection.getresponse()
      40. connection.close()
      41. counter=0
      42. else:
      43. if off == 1:
      44. off = 0
      45. os.system("curl -d '{\"on\":false}' -X PUT 192.168.178.20/api/FaEBatAQW0fF12W-6LKW5cZDYkpsKTQo2v6S68Nz/groups/8/action")
      46. break
      47. def calcLuminance(r,g,b):
      48. LUM_VALUE=5
      49. luminance=1
      50. if (r + g + b > 1):
      51. luminance= r + g + b + LUM_VALUE
      52. if (luminance>=255):
      53. luminance=254
      54. return luminance
      55. import time
      56. time.sleep(1)
      57. popen()
      Alles anzeigen


      So sieht die Info aus wenn ich auf Grün drücke:
      1_0_19_EF75_3F9_1_C00000_0_0_0-6.jpg

      Noch ein Log unter /tmp
      Spoiler anzeigen


      Quellcode

      1. 21:02:51 [D] > __common__::rmFile() > Delete old log file /tmp/enigmalight_gui.log
      2. 21:02:51 [D] > __common__::checkSymbolic()
      3. 21:02:54 [D] > __init__::Prepare()
      4. 21:02:54 [D] > __common__::getBoxInformation()
      5. 21:02:54 [D] > __common__::getBoxArch()
      6. 21:02:54 [D] > __common__::getBoxArch() > unknown
      7. 21:02:54 [D] > __common__::getBoxInformation() > ('VuPlus', 'uno4kse', '7252s', 'ARM', 'unknown')
      8. 21:02:54 [D] > __init__::localeInit()
      9. 21:02:54 [D] > __init__::registerSkinParamsInstance()
      10. 21:02:54 [D] > __common__::getXmlContent()
      11. 21:02:54 [D] > __common__::checkXmlFile()
      12. 21:02:54 [D] > __common__::loadEnigmalightSkin() > Load Skin: /usr/lib/enigma2/python/Plugins/Extensions/EnigmaLight/skins/default/skin-fullhd.xml
      13. 21:02:54 [D] > __common__::registerEnigmalightFonts()
      14. 21:02:54 [D] > EL_HttpServer::HttpdStart()
      15. 21:02:54 [D] > EL_HttpServer::buildRootTree()
      16. 21:02:54 [D] RootController::__init__
      17. 21:02:54 [D] WebController::__init__
      18. 21:02:54 [D] AjaxController::__init__
      19. 21:02:54 [D] ApiController::__init__
      20. 21:02:54 [D] > EL_HttpServer::HttpdStart() -> Enigmalight Webremote started on port: 1414
      21. 21:02:54 [D] > EL_HttpServer::BJregisterService()
      22. 21:03:03 [D] Controller::standbyAction > enterStandby..
      23. 21:03:11 [D] Controller::leaveStandby
      24. 21:03:43 [D] > plugin::sessionstart()
      25. 21:03:43 [D] EL_Screen_MainMenu::__init__ > Menu Opened succesfull..
      26. 21:03:43 [D] > __common__::checkSymbolic()
      27. 21:03:43 [D] EL_Screen_MainMenu::finishLayout > Finisch layout....
      28. 21:03:43 [D] EL_Screen_MainMenu::refreshMenu
      29. 21:03:43 [D] Controller::sendAll
      30. 21:03:43 [D] Controller::writeSettings
      31. 21:03:43 [D] Controller::writeAdjust
      32. 21:03:43 [D] EL_Screen_MainMenu::finishLayout > Layout Finisched!
      33. 21:03:50 [D] EL_Screen_MainMenu::keyGreen
      34. 21:03:50 [D] Controller::ToggleDynamic
      35. 21:03:50 [D] Controller::Control > Control: c:start v:dynamic
      36. 21:03:50 [D] Controller::checkIfRunningFinisched
      37. 21:03:50 [D] Controller::checkIfRunningFinisched > control[command] = start
      38. 21:03:50 [D] Controller::checkIfRunningFinisched > control[value] = dynamic
      39. 21:03:50 [D] Controller::checkIfRunningFinisched > control[startcommand] = enigmalight -m 0 -f -c /etc/enigmalight.conf &
      40. 21:03:50 [D] Controller::checkIfRunningFinisched > callback = None
      41. 21:03:50 [D] Controller::checkIfRunningFinisched > pid = None
      42. 21:03:50 [D] Controller::checkIfRunningFinisched > [/usr/bin/enigmalight] not running, Starting..
      43. 21:03:50 [D] Controller::DoControl
      44. 21:03:51 [D] Controller::controlMode
      45. 21:03:51 [D] > __common__::showMessage()
      46. 21:03:51 [D] Controller::sendAll
      47. 21:03:52 [D] Controller::writeSettings
      48. 21:03:52 [D] Controller::writeAdjust
      49. 21:04:18 [D] EL_Screen_MainMenu::cancel
      50. 21:04:18 [D] EL_Screen_MainMenu::exit > Main Exit..
      51. 00:28:18 [D] Controller::ToggleDynamic
      52. 00:28:18 [D] Controller::Control > Control: c:control v:stop
      53. 00:28:18 [D] Controller::checkIfRunningFinisched
      54. 00:28:18 [D] Controller::checkIfRunningFinisched > control[command] = control
      55. 00:28:18 [D] Controller::checkIfRunningFinisched > control[value] = stop
      56. 00:28:18 [D] Controller::checkIfRunningFinisched > control[startcommand] = enigmalight -m 0 -f -c /etc/enigmalight.conf &
      57. 00:28:18 [D] Controller::checkIfRunningFinisched > callback = None
      58. 00:28:18 [D] Controller::checkIfRunningFinisched > pid = 1387
      59. 00:28:18 [D] Controller::checkIfRunningFinisched > [/usr/bin/enigmalight] already running with pid 1387
      60. 00:28:18 [D] Controller::DoControl
      61. 00:28:18 [D] Controller::DoControl > config.plugins.enigmalight.server.value is true, Start server
      62. 00:28:18 [D] > __common__::showMessage()
      63. 00:28:20 [D] Controller::standbyAction > enterStandby..
      64. 10:05:24 [D] Controller::leaveStandby
      65. 14:30:44 [D] > plugin::sessionstart()
      66. 14:30:44 [D] EL_Screen_MainMenu::__init__ > Menu Opened succesfull..
      67. 14:30:44 [D] > __common__::checkSymbolic()
      68. 14:30:44 [D] EL_Screen_MainMenu::finishLayout > Finisch layout....
      69. 14:30:44 [D] EL_Screen_MainMenu::refreshMenu
      70. 14:30:44 [D] Controller::sendAll
      71. 14:30:44 [D] Controller::writeSettings
      72. 14:30:44 [D] Controller::writeAdjust
      73. 14:30:44 [D] EL_Screen_MainMenu::finishLayout > Layout Finisched!
      74. 14:30:48 [D] EL_Screen_MainMenu::keyGreen
      75. 14:30:48 [D] Controller::ToggleDynamic
      76. 14:30:48 [D] Controller::Control > Control: c:start v:dynamic
      77. 14:30:48 [D] Controller::checkIfRunningFinisched
      78. 14:30:48 [D] Controller::checkIfRunningFinisched > control[command] = start
      79. 14:30:48 [D] Controller::checkIfRunningFinisched > control[value] = dynamic
      80. 14:30:48 [D] Controller::checkIfRunningFinisched > control[startcommand] = enigmalight -m 0 -f -c /etc/enigmalight.conf &
      81. 14:30:48 [D] Controller::checkIfRunningFinisched > callback = None
      82. 14:30:48 [D] Controller::checkIfRunningFinisched > pid = 1387
      83. 14:30:48 [D] Controller::checkIfRunningFinisched > [/usr/bin/enigmalight] already running with pid 1387
      84. 14:30:48 [D] Controller::DoControl
      85. 14:30:48 [D] Controller::controlMode
      86. 14:30:48 [D] > __common__::showMessage()
      87. 14:30:48 [D] Controller::sendAll
      88. 14:30:49 [D] Controller::writeSettings
      89. 14:30:49 [D] Controller::writeAdjust
      90. 14:33:46 [D] EL_Screen_MainMenu::keyYellow
      91. 14:33:46 [D] Controller::ToggleMoodLamp
      92. 14:33:46 [D] Controller::Control > Control: c:control v:moodlamp
      93. 14:33:46 [D] Controller::checkIfRunningFinisched
      94. 14:33:46 [D] Controller::checkIfRunningFinisched > control[command] = control
      95. 14:33:46 [D] Controller::checkIfRunningFinisched > control[value] = moodlamp
      96. 14:33:46 [D] Controller::checkIfRunningFinisched > control[startcommand] = enigmalight -m 0 -f -c /etc/enigmalight.conf &
      97. 14:33:46 [D] Controller::checkIfRunningFinisched > callback = None
      98. 14:33:46 [D] Controller::checkIfRunningFinisched > pid = 1387
      99. 14:33:46 [D] Controller::checkIfRunningFinisched > [/usr/bin/enigmalight] already running with pid 1387
      100. 14:33:46 [D] Controller::DoControl
      101. 14:33:46 [D] Controller::writeMoodlamp
      102. 14:33:46 [D] Controller::getColor
      103. 14:33:46 [D] > __common__::rgbToHex()
      104. 14:33:46 [D] > __common__::showMessage()
      105. 14:33:46 [D] Controller::sendAll
      106. 14:33:46 [D] Controller::writeMoodlamp
      107. 14:33:46 [D] Controller::getColor
      108. 14:33:46 [D] > __common__::rgbToHex()
      109. 14:33:46 [D] Controller::writeSettings
      110. 14:33:46 [D] Controller::writeAdjust
      111. 14:33:53 [D] EL_Screen_MainMenu::okbuttonClick
      112. 14:33:53 [D] EL_Screen_MainMenu::okbuttonClick > Selected item EL_Screen_Settings
      113. 14:33:53 [D] EL_Screen_Settings::__init__ > Settings Opened succesfull..
      114. 14:33:53 [D] EL_Screen_Settings::createSetup
      115. 14:33:53 [D] EL_Screen_Settings::__init__ > Finisch layout...
      116. 14:33:53 [D] EL_Screen_Settings::finishLayout > Layout finisched..
      117. 14:34:00 [D] EL_Screen_Settings::keyRight
      118. 14:34:00 [D] Controller::changeValue
      119. 14:34:00 [D] EL_Screen_Settings::createSetup
      120. 14:34:00 [D] EL_Screen_Settings::createSetup
      121. 14:34:05 [D] EL_Screen_Settings::keyRight
      122. 14:34:05 [D] Controller::changeValue
      123. 14:34:05 [D] Controller::writeDynamic
      124. 14:34:05 [D] EL_Screen_Settings::createSetup
      125. 14:34:06 [D] EL_Screen_Settings::createSetup
      126. 14:34:07 [D] EL_Screen_Settings::keyRight
      127. 14:34:07 [D] Controller::changeValue
      128. 14:34:07 [D] Controller::writeMoodlamp
      129. 14:34:07 [D] Controller::getColor
      130. 14:34:07 [D] > __common__::rgbToHex()
      131. 14:34:07 [D] EL_Screen_Settings::createSetup
      132. 14:34:07 [D] EL_Screen_Settings::createSetup
      133. 14:34:07 [D] EL_Screen_Settings::keyRight
      134. 14:34:07 [D] Controller::changeValue
      135. 14:34:07 [D] Controller::writeDynamic
      136. 14:34:07 [D] EL_Screen_Settings::createSetup
      137. 14:34:07 [D] EL_Screen_Settings::createSetup
      138. 14:34:13 [D] EL_Screen_Settings::keyRight
      139. 14:34:13 [D] Controller::changeValue
      140. 14:34:13 [D] EL_Screen_Settings::createSetup
      141. 14:34:13 [D] EL_Screen_Settings::createSetup
      142. 14:34:14 [D] EL_Screen_Settings::keyRight
      143. 14:34:14 [D] Controller::changeValue
      144. 14:34:14 [D] EL_Screen_Settings::createSetup
      145. 14:34:14 [D] EL_Screen_Settings::createSetup
      146. 14:34:15 [D] EL_Screen_Settings::keyRight
      147. 14:34:15 [D] Controller::changeValue
      148. 14:34:15 [D] EL_Screen_Settings::createSetup
      149. 14:34:15 [D] EL_Screen_Settings::createSetup
      150. 14:34:16 [D] EL_Screen_Settings::keyRight
      151. 14:34:16 [D] Controller::changeValue
      152. 14:34:16 [D] EL_Screen_Settings::createSetup
      153. 14:34:16 [D] EL_Screen_Settings::createSetup
      154. 14:34:18 [D] EL_Screen_Settings::keyRight
      155. 14:34:18 [D] Controller::changeValue
      156. 14:34:18 [D] EL_Screen_Settings::createSetup
      157. 14:34:18 [D] EL_Screen_Settings::createSetup
      158. 14:34:20 [D] EL_Screen_Settings::keySave
      159. 14:34:20 [D] EL_Screen_MainMenu::refreshMenu
      160. 14:34:20 [D] Controller::sendAll
      161. 14:34:20 [D] Controller::writeDynamic
      162. 14:34:20 [D] Controller::writeSettings
      163. 14:34:20 [D] Controller::writeAdjust
      164. 14:34:22 [D] EL_Screen_MainMenu::right
      165. 14:34:23 [D] EL_Screen_MainMenu::okbuttonClick
      166. 14:34:23 [D] EL_Screen_MainMenu::okbuttonClick > Selected item EL_Screen_Tuning
      167. 14:34:23 [D] > __init__::getVersion()
      168. 14:34:24 [D] > __common__::getAspect()
      169. 14:34:24 [D] EL_Screen_Tuning::__init__ > Finisch layout..
      170. 14:34:42 [D] EL_Screen_MainMenu::refreshMenu
      171. 14:34:42 [D] Controller::sendAll
      172. 14:34:42 [D] Controller::writeDynamic
      173. 14:34:42 [D] Controller::writeSettings
      174. 14:34:42 [D] Controller::writeAdjust
      175. 14:34:43 [D] EL_Screen_MainMenu::right
      176. 14:34:43 [D] EL_Screen_MainMenu::okbuttonClick
      177. 14:34:43 [D] EL_Screen_MainMenu::okbuttonClick > Selected item EL_Screen_Moodlamp
      178. 14:34:43 [D] EL_Screen_Moodlamp::__init__ > Moodlamp Opened succesfull..
      179. 14:34:43 [D] EL_Screen_Moodlamp::createList
      180. 14:34:43 [D] EL_Screen_Moodlamp::__init__ > Finisch layout..
      181. 14:34:44 [D] EL_Screen_Moodlamp::updateHelp
      182. 14:34:44 [D] EL_Screen_Moodlamp::finishLayout > Layout finsched..
      183. 14:34:44 [D] > __common__::getRGB()
      184. 14:34:47 [D] EL_Screen_MainMenu::refreshMenu
      185. 14:34:47 [D] Controller::sendAll
      186. 14:34:47 [D] Controller::writeDynamic
      187. 14:34:48 [D] Controller::writeSettings
      188. 14:34:48 [D] Controller::writeAdjust
      189. 14:34:49 [D] EL_Screen_MainMenu::right
      190. 14:34:50 [D] EL_Screen_MainMenu::right
      191. 14:34:51 [D] EL_Screen_MainMenu::right
      192. 14:34:52 [D] EL_Screen_MainMenu::left
      193. 14:34:53 [D] EL_Screen_MainMenu::okbuttonClick
      194. 14:34:53 [D] EL_Screen_MainMenu::okbuttonClick > Selected item EL_Screen_About
      195. 14:34:53 [D] > __init__::getVersion()
      196. 14:34:53 [D] > __common__::getBoxInformation()
      197. 14:34:53 [D] > __common__::getBoxArch()
      198. 14:34:53 [D] > __common__::getBoxArch() > unknown
      199. 14:34:53 [D] > __common__::getBoxInformation() > ('VuPlus', 'uno4kse', '7252s', 'ARM', 'unknown')
      200. 14:34:54 [D] EL_Screen_MainMenu::refreshMenu
      201. 14:34:54 [D] Controller::sendAll
      202. 14:34:54 [D] Controller::writeDynamic
      203. 14:34:54 [D] Controller::writeSettings
      204. 14:34:54 [D] Controller::writeAdjust
      205. 14:34:55 [D] EL_Screen_MainMenu::right
      206. 14:34:55 [D] EL_Screen_MainMenu::right
      207. 14:34:56 [D] EL_Screen_MainMenu::okbuttonClick
      208. 14:34:56 [D] EL_Screen_MainMenu::okbuttonClick > Selected item EL_Screen_Settings
      209. 14:34:56 [D] EL_Screen_Settings::__init__ > Settings Opened succesfull..
      210. 14:34:56 [D] EL_Screen_Settings::createSetup
      211. 14:34:56 [D] EL_Screen_Settings::__init__ > Finisch layout...
      212. 14:34:56 [D] EL_Screen_Settings::finishLayout > Layout finisched..
      213. 14:35:04 [D] EL_Screen_MainMenu::refreshMenu
      214. 14:35:04 [D] Controller::sendAll
      215. 14:35:04 [D] Controller::writeDynamic
      216. 14:35:04 [D] Controller::writeSettings
      217. 14:35:04 [D] Controller::writeAdjust
      218. 14:35:05 [D] EL_Screen_MainMenu::cancel
      219. 14:35:05 [D] EL_Screen_MainMenu::exit > Main Exit..
      Alles anzeigen

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von hgdo () aus folgendem Grund: 3 Beiträge zusammengefasst

    • Ich hab ne 4K Box. Aber wie ich es jetzt verstehe, ist selbst diese recht aktuelle Anleitung aus Post 261, veraltet bzw. basiert auf die alte API und man muß mit dem Delay von ca. 1 Sekunde leben. Ich werde jetzt mich mit der Entertainment API auseinandersetzen.

      @chemieka

      Du schreibst Duo. Redest du von einer Duo, Duo2 oder Duo4K ?

      Und hast du ein Delay bei den Farben der Hue‘s ?

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von bimmler ()

    • @discomatratze und/oder @harrykausl Hab jetzt einmal auf dem Mac versucht die dtls_client zu kompilieren. Folgende Fehlermeldung erhalte ich:

      Quellcode

      1. CC aes/aescrypt2.c
      2. ld: warning: ignoring file ../library/libmbedtls.a, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
      3. ld: warning: ignoring file ../library/libmbedcrypto.a, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
      4. ld: warning: ignoring file ../library/libmbedx509.a, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
      5. Undefined symbols for architecture x86_64:
      6. "_mbedtls_aes_crypt_ecb", referenced from:
      7. _main in aescrypt2-31aef0.o
      8. "_mbedtls_aes_free", referenced from:
      9. _main in aescrypt2-31aef0.o
      10. "_mbedtls_aes_init", referenced from:
      11. _main in aescrypt2-31aef0.o
      12. "_mbedtls_aes_setkey_dec", referenced from:
      13. _main in aescrypt2-31aef0.o
      14. "_mbedtls_aes_setkey_enc", referenced from:
      15. _main in aescrypt2-31aef0.o
      16. "_mbedtls_md_finish", referenced from:
      17. _main in aescrypt2-31aef0.o
      18. "_mbedtls_md_free", referenced from:
      19. _main in aescrypt2-31aef0.o
      20. "_mbedtls_md_hmac_finish", referenced from:
      21. _main in aescrypt2-31aef0.o
      22. "_mbedtls_md_hmac_starts", referenced from:
      23. _main in aescrypt2-31aef0.o
      24. "_mbedtls_md_hmac_update", referenced from:
      25. _main in aescrypt2-31aef0.o
      26. "_mbedtls_md_info_from_type", referenced from:
      27. _main in aescrypt2-31aef0.o
      28. "_mbedtls_md_init", referenced from:
      29. _main in aescrypt2-31aef0.o
      30. "_mbedtls_md_setup", referenced from:
      31. _main in aescrypt2-31aef0.o
      32. "_mbedtls_md_starts", referenced from:
      33. _main in aescrypt2-31aef0.o
      34. "_mbedtls_md_update", referenced from:
      35. _main in aescrypt2-31aef0.o
      36. ld: symbol(s) not found for architecture x86_64
      37. clang: error: linker command failed with exit code 1 (use -v to see invocation)
      38. make: *** [aes/aescrypt2] Error 1
      Alles anzeigen

      Wenn ich auf auf einem Linuxlaptop versuche zu kompilieren, bekomme ich folgende Fehlermeldung:
      Spoiler anzeigen

      Quellcode

      1. CC aes/aescrypt2.c
      2. /usr/bin/ld: inkompatibles ../library/libmbedtls.a wird bei der Suche nach -lmbedtls übersprungen
      3. /usr/bin/ld: -lmbedtls kann nicht gefunden werden
      4. /usr/bin/ld: inkompatibles ../library/libmbedx509.a wird bei der Suche nach -lmbedx509 übersprungen
      5. /usr/bin/ld: -lmbedx509 kann nicht gefunden werden
      6. /usr/bin/ld: inkompatibles ../library/libmbedcrypto.a wird bei der Suche nach -lmbedcrypto übersprungen
      7. /usr/bin/ld: -lmbedcrypto kann nicht gefunden werden
      8. collect2: error: ld returned 1 exit status
      9. Makefile:89: recipe for target 'aes/aescrypt2' failed
      10. make: *** [aes/aescrypt2] Error 1


      Kann einer helfen?

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von bimmler ()

    • Woohoo 8o Ein erster Teilerfolg.

      Ich habe die dtls_client nun auf nem Pi kompilieren können. Dabei muss ich sagen, das noch an einer Stelle mehr in der dtls_client.c die IP und der Username eingetragen werden muss, als in der Anleitung aus dem Dreambox Forum angegeben.

      Nun hab ich zwei Lampen erfolgreich über die Entertain-API am laufen. Nur würde ich gerne mehr als zwei Lampen dafür nutzen. Wenn man sich die Enigmalight.conf anschaut, wie müsste dann der Eintrag aussehen?

      Hier meine .conf
      Spoiler anzeigen

      Quellcode

      1. #[global]
      2. [device]
      3. name ambilight
      4. output /home/elight-addons/wifilight/philips_hue/dtls_client
      5. channels 6
      6. type popen
      7. interval 200000
      8. debug off
      9. [color]
      10. name red
      11. rgb FF0000
      12. [color]
      13. name green
      14. rgb 00FF00
      15. [color]
      16. name blue
      17. rgb 0000FF
      18. [light]
      19. position left
      20. name 1HU
      21. color red ambilight 1
      22. color green ambilight 2
      23. color blue ambilight 3
      24. hscan 0 15
      25. vscan 0 100
      26. [light]
      27. position right
      28. name 2HU
      29. color red ambilight 4
      30. color green ambilight 5
      31. color blue ambilight 6
      32. hscan 85 100
      33. vscan 0 100
      Alles anzeigen



      dtls_client.c

      Spoiler anzeigen


      C-Quellcode

      1. /*
      2. * Simple DTLS client demonstration program
      3. *
      4. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
      5. * SPDX-License-Identifier: Apache-2.0
      6. *
      7. * Licensed under the Apache License, Version 2.0 (the "License"); you may
      8. * not use this file except in compliance with the License.
      9. * You may obtain a copy of the License at
      10. *
      11. * http://www.apache.org/licenses/LICENSE-2.0
      12. *
      13. * Unless required by applicable law or agreed to in writing, software
      14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
      15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      16. * See the License for the specific language governing permissions and
      17. * limitations under the License.
      18. *
      19. * This file is part of mbed TLS (https://tls.mbed.org)
      20. */
      21. #if !defined(MBEDTLS_CONFIG_FILE)
      22. #include "mbedtls/config.h"
      23. #else
      24. #include MBEDTLS_CONFIG_FILE
      25. #endif
      26. #if defined(MBEDTLS_PLATFORM_C)
      27. #include "mbedtls/platform.h"
      28. #else
      29. #include <stdio.h>
      30. #define mbedtls_printf printf
      31. #define mbedtls_fprintf fprintf
      32. #endif
      33. #if !defined(MBEDTLS_SSL_CLI_C) || !defined(MBEDTLS_SSL_PROTO_DTLS) || \
      34. !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_TIMING_C) || \
      35. !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_CTR_DRBG_C) || \
      36. !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_RSA_C) || \
      37. !defined(MBEDTLS_CERTS_C) || !defined(MBEDTLS_PEM_PARSE_C)
      38. int main( void )
      39. {
      40. mbedtls_printf( "MBEDTLS_SSL_CLI_C and/or MBEDTLS_SSL_PROTO_DTLS and/or "
      41. "MBEDTLS_NET_C and/or MBEDTLS_TIMING_C and/or "
      42. "MBEDTLS_ENTROPY_C and/or MBEDTLS_CTR_DRBG_C and/or "
      43. "MBEDTLS_X509_CRT_PARSE_C and/or MBEDTLS_RSA_C and/or "
      44. "MBEDTLS_CERTS_C and/or MBEDTLS_PEM_PARSE_C not defined.\n" );
      45. return( 0 );
      46. }
      47. #else
      48. #include <string.h>
      49. #include <unistd.h>
      50. #include "mbedtls/net_sockets.h"
      51. #include "mbedtls/debug.h"
      52. #include "mbedtls/ssl.h"
      53. #include "mbedtls/entropy.h"
      54. #include "mbedtls/ctr_drbg.h"
      55. #include "mbedtls/error.h"
      56. #include "mbedtls/certs.h"
      57. #include "mbedtls/timing.h"
      58. #include "mbedtls/config.h"
      59. #define SERVER_PORT "2100"
      60. #define SERVER_NAME "Hue"
      61. #define SERVER_ADDR "192.168.178.20" /* forces IPv4 */
      62. #define MESSAGE "Echo this"
      63. #define DFL_PSK_IDENTITY "JYY78dfPdO4QC79s5V-T5Orw98WTl1XnjnlcQ-Mk"
      64. #define READ_TIMEOUT_MS 1000
      65. #define MAX_RETRY 5
      66. #define DEBUG_LEVEL 0
      67. static void my_debug( void *ctx, int level,
      68. const char *file, int line,
      69. const char *str )
      70. {
      71. ((void) level);
      72. mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
      73. fflush( (FILE *) ctx );
      74. }
      75. int main( int argc, char *argv[] )
      76. {
      77. int ret, len;
      78. mbedtls_net_context server_fd;
      79. uint32_t flags;
      80. unsigned char buf[1024];
      81. const char *pers = "dtls_client";
      82. int retry_left = MAX_RETRY;
      83. const char *psk_identity;
      84. const unsigned char psk[] = {0x2F, 0x3F, 0x5A, 0xFE, 0x5F, 0xA8, 0x5C, 0x97, 0xDA, 0x92, 0x29, 0x1B, 0xE0, 0xBF, 0x12, 0x98 };
      85. int force_ciphersuite[2];
      86. char message1[] = {'H', 'u', 'e', 'S', 't', 'r', 'e', 'a', 'm', //protocol
      87. 0x01, 0x00, //version 1.0
      88. 0x01, //sequence number 1
      89. 0x00, 0x00, //reserved
      90. 0x00, //color mode RGB
      91. 0x01, //linear filter
      92. 0x00, 0x00, 0x03, //light 1
      93. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      94. 0x00, 0x00, 0x04, //light 2
      95. 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
      96. };
      97. char message2[] = {'H', 'u', 'e', 'S', 't', 'r', 'e', 'a', 'm', //protocol
      98. 0x01, 0x00, //version 1.0
      99. 0x01, //sequence number 1
      100. 0x00, 0x00, //reserved
      101. 0x00, //color mode RGB
      102. 0x01, //linear filter
      103. 0x00, 0x00, 0x03, //light 1
      104. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
      105. 0x00, 0x00, 0x04, //light 2
      106. 0x00, 0x00, 0x00, 0x00, 0xff, 0xff
      107. };
      108. mbedtls_entropy_context entropy;
      109. mbedtls_ctr_drbg_context ctr_drbg;
      110. mbedtls_ssl_context ssl;
      111. mbedtls_ssl_config conf;
      112. mbedtls_x509_crt cacert;
      113. mbedtls_timing_delay_context timer;
      114. ((void) argc);
      115. ((void) argv);
      116. #if defined(MBEDTLS_DEBUG_C)
      117. mbedtls_debug_set_threshold( DEBUG_LEVEL );
      118. #endif
      119. psk_identity = DFL_PSK_IDENTITY;
      120. force_ciphersuite[0]= MBEDTLS_TLS_PSK_WITH_AES_128_GCM_SHA256;
      121. force_ciphersuite[1]= 0;
      122. /*
      123. * set hue in the right mode
      124. */
      125. system("curl -X PUT -H \"Content-Type: application/json\" -d '{\"stream\":{\"active\":true}}' \"http://192.168.178.20/api/JYY78dfPdO4QC79s5V-T5Orw98WTl1XnjnlcQ-Mk/groups/8\"");
      126. /*
      127. * 0. Initialize the RNG and the session data
      128. */
      129. mbedtls_net_init( &server_fd );
      130. mbedtls_ssl_init( &ssl );
      131. mbedtls_ssl_config_init( &conf );
      132. mbedtls_x509_crt_init( &cacert );
      133. mbedtls_ctr_drbg_init( &ctr_drbg );
      134. mbedtls_printf( "\n . Seeding the random number generator..." );
      135. fflush( stdout );
      136. mbedtls_entropy_init( &entropy );
      137. if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy,
      138. (const unsigned char *) pers,
      139. strlen( pers ) ) ) != 0 )
      140. {
      141. mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret );
      142. goto exit;
      143. }
      144. mbedtls_printf( " ok\n" );
      145. /*
      146. * 0. Load certificates
      147. */
      148. mbedtls_printf( " . Loading the CA root certificate ..." );
      149. fflush( stdout );
      150. ret = mbedtls_x509_crt_parse( &cacert, (const unsigned char *) mbedtls_test_cas_pem,
      151. mbedtls_test_cas_pem_len );
      152. if( ret < 0 )
      153. {
      154. mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", -ret );
      155. goto exit;
      156. }
      157. mbedtls_printf( " ok (%d skipped)\n", ret );
      158. /*
      159. * 1. Start the connection
      160. */
      161. mbedtls_printf( " . Connecting to udp/%s/%s...", SERVER_NAME, SERVER_PORT );
      162. fflush( stdout );
      163. if( ( ret = mbedtls_net_connect( &server_fd, SERVER_ADDR,
      164. SERVER_PORT, MBEDTLS_NET_PROTO_UDP ) ) != 0 )
      165. {
      166. mbedtls_printf( " failed\n ! mbedtls_net_connect returned %d\n\n", ret );
      167. goto exit;
      168. }
      169. mbedtls_printf( " ok\n" );
      170. /*
      171. * 2. Setup stuff
      172. */
      173. mbedtls_printf( " . Setting up the DTLS structure..." );
      174. fflush( stdout );
      175. if( ( ret = mbedtls_ssl_config_defaults( &conf,
      176. MBEDTLS_SSL_IS_CLIENT,
      177. MBEDTLS_SSL_TRANSPORT_DATAGRAM,
      178. MBEDTLS_SSL_PRESET_DEFAULT ) ) != 0 )
      179. {
      180. mbedtls_printf( " failed\n ! mbedtls_ssl_config_defaults returned %d\n\n", ret );
      181. goto exit;
      182. }
      183. mbedtls_ssl_conf_transport(&conf, MBEDTLS_SSL_TRANSPORT_DATAGRAM);
      184. /* OPTIONAL is usually a bad choice for security, but makes interop easier
      185. * in this simplified example, in which the ca chain is hardcoded.
      186. * Production code should set a proper ca chain and use REQUIRED. */
      187. mbedtls_ssl_conf_authmode( &conf, MBEDTLS_SSL_VERIFY_OPTIONAL );
      188. mbedtls_ssl_conf_ca_chain( &conf, &cacert, NULL );
      189. mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg );
      190. mbedtls_ssl_conf_dbg( &conf, my_debug, stdout );
      191. if( ( ret = mbedtls_ssl_setup( &ssl, &conf ) ) != 0 )
      192. {
      193. mbedtls_printf( " failed\n ! mbedtls_ssl_setup returned %d\n\n", ret );
      194. goto exit;
      195. }
      196. if( ( ret = mbedtls_ssl_conf_psk( &conf, psk, sizeof(psk),
      197. (const unsigned char *) psk_identity,
      198. strlen( psk_identity ) ) ) != 0 )
      199. {
      200. mbedtls_printf( " failed\n ! mbedtls_ssl_conf_psk returned %d\n\n", ret );
      201. goto exit;
      202. }
      203. mbedtls_ssl_conf_ciphersuites(&conf, force_ciphersuite);
      204. if( ( ret = mbedtls_ssl_set_hostname( &ssl, SERVER_NAME ) ) != 0 )
      205. {
      206. mbedtls_printf( " failed\n ! mbedtls_ssl_set_hostname returned %d\n\n", ret );
      207. goto exit;
      208. }
      209. mbedtls_ssl_set_bio( &ssl, &server_fd,
      210. mbedtls_net_send, mbedtls_net_recv, mbedtls_net_recv_timeout );
      211. mbedtls_ssl_set_timer_cb( &ssl, &timer, mbedtls_timing_set_delay,
      212. mbedtls_timing_get_delay );
      213. mbedtls_ssl_conf_handshake_timeout(&conf, 100, 60000);
      214. mbedtls_printf( " ok\n" );
      215. /*
      216. * 4. Handshake
      217. */
      218. mbedtls_printf( " . Performing the SSL/TLS handshake..." );
      219. fflush( stdout );
      220. do ret = mbedtls_ssl_handshake( &ssl );
      221. while( ret == MBEDTLS_ERR_SSL_WANT_READ ||
      222. ret == MBEDTLS_ERR_SSL_WANT_WRITE );
      223. if( ret != 0 )
      224. {
      225. mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", -ret );
      226. goto exit;
      227. }
      228. mbedtls_printf( " ok\n" );
      229. /*
      230. * 5. Verify the server certificate
      231. */
      232. mbedtls_printf( " . Verifying peer X.509 certificate..." );
      233. /* In real life, we would have used MBEDTLS_SSL_VERIFY_REQUIRED so that the
      234. * handshake would not succeed if the peer's cert is bad. Even if we used
      235. * MBEDTLS_SSL_VERIFY_OPTIONAL, we would bail out here if ret != 0 */
      236. if( ( flags = mbedtls_ssl_get_verify_result( &ssl ) ) != 0 )
      237. {
      238. char vrfy_buf[512];
      239. mbedtls_printf( " failed\n" );
      240. mbedtls_x509_crt_verify_info( vrfy_buf, sizeof( vrfy_buf ), " ! ", flags );
      241. mbedtls_printf( "%s\n", vrfy_buf );
      242. }
      243. else
      244. mbedtls_printf( " ok\n" );
      245. /*
      246. * 6. Write the echo request
      247. */
      248. send_request:
      249. mbedtls_printf( " > sending message" );
      250. fflush( stdout );
      251. char *line = NULL;
      252. while(1) {
      253. size_t size;
      254. if (getline(&line, &size, stdin) == -1) {
      255. mbedtls_printf("No line\n");
      256. } else {
      257. mbedtls_printf( "%s\n", line);
      258. }
      259. char* pEnd;
      260. float f1, f2, f3, f4, f5, f6;
      261. f1 = strtof (line, &pEnd);
      262. f2 = strtof (pEnd, &pEnd);
      263. f3 = strtof (pEnd, &pEnd);
      264. f4 = strtof (pEnd, &pEnd);
      265. f5 = strtof (pEnd, &pEnd);
      266. f6 = strtof (pEnd, NULL);
      267. f1 = f1*65535;
      268. f2 = f2*65535;
      269. f3 = f3*65535;
      270. f4 = f4*65535;
      271. f5 = f5*65535;
      272. f6 = f6*65535;
      273. int i1, i2, i3, i4, i5, i6;
      274. i1 = (int)f1;
      275. i2 = (int)f2;
      276. i3 = (int)f3;
      277. i4 = (int)f4;
      278. i5 = (int)f5;
      279. i6 = (int)f6;
      280. mbedtls_printf( "%x\n", i1);
      281. mbedtls_printf( "%x\n", i2);
      282. mbedtls_printf( "%x\n", i3);
      283. mbedtls_printf( "%x\n", i4);
      284. mbedtls_printf( "%x\n", i5);
      285. mbedtls_printf( "%x\n", i6);
      286. char first[5];
      287. char second[5];
      288. char third[5];
      289. char fourth[5];
      290. char fith[5];
      291. char sixth[5];
      292. sprintf(second, "0x%02x", i1&0xFF);
      293. sprintf(first, "0x%02x", (i1>>8)&0xFF);
      294. sprintf(fourth, "0x%02x", i2&0xFF);
      295. sprintf(third, "0x%02x", (i2>>8)&0xFF);
      296. sprintf(sixth, "0x%02x", i3&0xFF);
      297. sprintf(fith, "0x%02x", (i3>>8)&0xFF);
      298. mbedtls_printf( first );
      299. mbedtls_printf("\n");
      300. mbedtls_printf( second);
      301. mbedtls_printf("\n");
      302. mbedtls_printf( third );
      303. mbedtls_printf("\n");
      304. mbedtls_printf( fourth);
      305. mbedtls_printf("\n");
      306. mbedtls_printf( fith );
      307. mbedtls_printf("\n");
      308. mbedtls_printf( sixth);
      309. mbedtls_printf("\n");
      310. char message[] = {'H', 'u', 'e', 'S', 't', 'r', 'e', 'a', 'm', //protocol
      311. 0x01, 0x00, //version 1.0
      312. 0x01, //sequence number 1
      313. 0x00, 0x00, //reserved
      314. 0x00, //color mode RGB
      315. 0x01, //linear filter
      316. 0x00, 0x00, 0x05, //light 1
      317. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      318. 0x00, 0x00, 0x06, //light 2
      319. 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
      320. };
      321. message[19] = (i1>>8)&0xFF;
      322. message[20] = i1&0xFF;
      323. message[21] = (i2>>8)&0xFF;
      324. message[22] = i2&0xFF;
      325. message[23] = (i3>>8)&0xFF;
      326. message[24] = i3&0xFF;
      327. message[28] = (i4>>8)&0xFF;
      328. message[29] = i4&0xFF;
      329. message[30] = (i5>>8)&0xFF;
      330. message[31] = i5&0xFF;
      331. message[32] = (i6>>8)&0xFF;
      332. message[33] = i6&0xFF;
      333. len = sizeof( message );
      334. fflush( stdout );
      335. do ret = mbedtls_ssl_write( &ssl, (unsigned char *) message, len );
      336. while( ret == MBEDTLS_ERR_SSL_WANT_READ ||
      337. ret == MBEDTLS_ERR_SSL_WANT_WRITE );
      338. if( ret < 0 )
      339. {
      340. mbedtls_printf( " failed\n ! mbedtls_ssl_write returned %d\n\n", ret );
      341. goto exit;
      342. }
      343. }
      344. /*
      345. * 7. Read the echo response
      346. */
      347. mbedtls_printf( " < Read from server:" );
      348. fflush( stdout );
      349. len = sizeof( buf ) - 1;
      350. memset( buf, 0, sizeof( buf ) );
      351. do ret = mbedtls_ssl_read( &ssl, buf, len );
      352. while( ret == MBEDTLS_ERR_SSL_WANT_READ ||
      353. ret == MBEDTLS_ERR_SSL_WANT_WRITE );
      354. if( ret <= 0 )
      355. {
      356. switch( ret )
      357. {
      358. case MBEDTLS_ERR_SSL_TIMEOUT:
      359. mbedtls_printf( " timeout\n\n" );
      360. if( retry_left-- > 0 )
      361. goto send_request;
      362. goto exit;
      363. case MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY:
      364. mbedtls_printf( " connection was closed gracefully\n" );
      365. ret = 0;
      366. goto close_notify;
      367. default:
      368. mbedtls_printf( " mbedtls_ssl_read returned -0x%x\n\n", -ret );
      369. goto exit;
      370. }
      371. }
      372. len = ret;
      373. mbedtls_printf( " %d bytes read\n\n%s\n\n", len, buf );
      374. /*
      375. * 8. Done, cleanly close the connection
      376. */
      377. close_notify:
      378. mbedtls_printf( " . Closing the connection..." );
      379. /* No error checking, the connection might be closed already */
      380. do ret = mbedtls_ssl_close_notify( &ssl );
      381. while( ret == MBEDTLS_ERR_SSL_WANT_WRITE );
      382. ret = 0;
      383. mbedtls_printf( " done\n" );
      384. /*
      385. * 9. Final clean-ups and exit
      386. */
      387. exit:
      388. #ifdef MBEDTLS_ERROR_C
      389. if( ret != 0 )
      390. {
      391. char error_buf[100];
      392. mbedtls_strerror( ret, error_buf, 100 );
      393. mbedtls_printf( "Last error was: %d - %s\n\n", ret, error_buf );
      394. }
      395. #endif
      396. mbedtls_net_free( &server_fd );
      397. mbedtls_x509_crt_free( &cacert );
      398. mbedtls_ssl_free( &ssl );
      399. mbedtls_ssl_config_free( &conf );
      400. mbedtls_ctr_drbg_free( &ctr_drbg );
      401. mbedtls_entropy_free( &entropy );
      402. #if defined(_WIN32)
      403. mbedtls_printf( " + Press Enter to exit this program.\n" );
      404. fflush( stdout ); getchar();
      405. #endif
      406. /* Shell can not handle large exit numbers -> 1 for errors */
      407. if( ret < 0 )
      408. ret = 1;
      409. return( ret );
      410. }
      411. #endif /* MBEDTLS_SSL_CLI_C && MBEDTLS_SSL_PROTO_DTLS && MBEDTLS_NET_C &&
      412. MBEDTLD_TIMING_C && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C &&
      413. MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_RSA_C && MBEDTLS_CERTS_C &&
      414. MBEDTLS_PEM_PARSE_C */
      Alles anzeigen