Ankündigung

Einklappen
Keine Ankündigung bisher.

EibPC - http//: Kommandos auf Port 80 senden

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    EibPC - http//: Kommandos auf Port 80 senden

    Guten Morgen

    Ich habe neu eine Netzwerkgesteuerte Steckdosenleiste von Gude im Einsatz. Die Ports können über http Kommandos ein bzw. ausgesschaltet werden.

    Folgendes Kommando schaltet den 1. Port ein http://192.168.178.101/?cmd=1&p=1&s=1

    Nun wollte ich dies über den EibPC machen, nur habe ich hier einen Knopf. Ich verbinde über Port 80 auf den Gude, 192.168.178.101. Nun weiss ich nicht wie das Kommando aussehen muss.

    Für Euer Feedback danke ich im Voraus bestens.

    Gruss,
    Martin

    [highlight=epc]
    // GUDE Power

    gudeSendDelay = 200u64
    gudePort = 80u16
    gudeIP = 192.168.178.101
    gudeInit=0b01
    gudeCommandSent=0b01
    gudeToggle=0b01
    gudeTrigger=0b01
    gudeOFF=0b01
    gudeON=0b01

    gudeLED=(gudeToggle or "Standby Sideboard A [s]-10/7/2")

    CR=13
    LF=10


    if pbutton(8,MultiMediaPageID)==1 then {
    gudeToggle=!gudeToggle;
    if gudeToggle then gudeON=1b01; pdisplay(8,$ON$,SWITCH,ACTIVE,GREY, MultiMediaPageID) endif;
    if !gudeToggle then gudeOFF=1b01; pdisplay(8,$OFF$,SWITCH,INACTIVE,GREY, MultiMediaPageID) endif;
    gudeTrigger=1b01
    }endif

    if gudeTrigger and !gudeON then connecttcp(gudePort, gudeIP) endif
    if after(gudeTrigger, gudeSendDelay) then {
    sendtcp(gudePort, gudeIP, $http://192.168.178.101/?cmd=1&p=1&s=1$,13,10);
    gudeCommandSent=1b01;
    gudeON=1b01
    }endif

    if gudeTrigger and gudeON then connecttcp(gudePort, gudeIP) endif
    if after(gudeTrigger, gudeSendDelay) then {
    sendtcp(gudePort, gudeIP, $http://192.168.178.101/?cmd=1&p=1&s=0$,13,10);
    gudeCommandSent=1b01;
    gudeON=0b01
    }endif

    if after(gudeCommandSent, gudeSendDelay) then {

    closetcp(gudePort, gudeIP);
    gudeInit=0b01;
    gudeCommandSent=0b01;
    gudeTrigger=0b01
    }endif

    if gudeLED and presence then write ("AV/Computer An [LED - Eingang]-0/2/10", EIN) \\
    else write("AV/Computer An [LED - Eingang]-0/2/10", AUS) endif


    //0x0D,0x0A,0x0D,0x0A


    // [STANDBY control end]
    [/highlight]

    #2
    Ich hab's mit den folgenden Kommandos versucht:

    GET /?cmd=1&p=1&s=1 HTTP/1.1 (weil dieser über Telnet funktioniert).

    Habe den sendtcp auch mit verschieden LF und CR code oder auch ohne abgeschlossen, jedoch bisweilen ohne Erfolg.

    sendtcp(gudePort, gudeIP, $GET /?cmd=1&p=1&s=0 HTTP/1.1$,13,10);

    sendtcp(gudePort, gudeIP, $GET /?cmd=1&p=1&s=0 HTTP/1.1$,0x0D,0x0A,0x0D,0x0A);

    Kommentar


      #3
      Warum stellst Du die Frage nicht im EibPC Bereich?

      Ich habe schon mehrere unterschiedliche IP Prozesse gebaut und nutze dabei immer diesen grundsätzlichen Ablauf:

      [highlight=epc]
      // Allgemeine Variablen definieren

      Init = after(systemstart() == EIN, 5000u64)
      CRLF = $$
      GET_1 = $$
      GET_2 = $$
      GET_3 = $$
      GET_4 = $$
      GET_5 = $$
      String = $$
      TCP_ConnectionState = 6u08

      // TCP Message für Abfrage

      if Init == EIN then \\
      stringset(CRLF, 0x0A0Du16, 0u16); \\
      GET_1 = $GET /?cmd=1&p=1&s=0 HTTP/1.0$ + CRLF; \\
      GET_2 = $User-Agent: Wget/ 1.0.10$ + CRLF; \\
      GET_3 = $Accept: */*$ + CRLF; \\
      GET_4 = $Host: 192.168.178.101$ + CRLF; \\
      GET_5 = $Connection: Keep-Alive$ + CRLF + CRLF; \\
      String = GET_1 + GET_2 + GET_3 + GET_4 + GET_5 \\
      endif

      // TCP Verbindung zum Host aufbauen

      if after(Init, 1000u64) then \\
      TCP_ConnectionState = connecttcp(Port,IP) \\
      endif

      // TCP Nachricht senden

      if change(TCP_ConnectionState) \\
      and TCP_ConnectionState == 0u08 then \\
      sendtcparray(Port, IP, String, size(String)) \\
      endif

      // jetzt hier noch ggfs. TCP Nachricht empfangen und dann TCP Verbindung schließen
      [/highlight]

      Viele Grüße

      Michael

      Kommentar


        #4
        Guten Abend Michael

        Vielen Dank, da wär ich nie draufgekommen.

        Funktioniert einwandfrei.

        Der EibPC Präfix konnte ich aus irgendwelchen Gründen nicht anwählen, daher landete mein Post nicht im EibPC Teil des Forums.

        Gruss,

        Martin

        Kommentar


          #5
          Hi Martin,

          klasse, freut mich. Mache doch direkt ein kleines Makro draus und poste es mit der Beschreibung der Steckerleiste.

          Ich kannte diese Art Steckerleisten bis dato noch nicht.

          @Admins, schiebt den Beitrag doch bitte in das EibPC Forum.

          Viele Grüße

          Michael

          Kommentar


            #6
            Hallo Michael

            Das dürfte für mich eine rechte Herausforderung sein, aber ich werd mich mal dransetzen.

            Nun ich habe bis vor kurzen die Netio verwendet, aber die laufen einfach nicht robust. Da hab ich mich nach einem neuen Produkt umgeschaut. Der misst sogar Strom, kann Pingen (um einen Rechner zu rebooten) und kann SNMP.

            Wünsche Dir ein schönes Wochenende.

            Gruss,

            Martin

            Kommentar


              #7
              Zitat von kropfm Beitrag anzeigen
              Der EibPC Präfix konnte ich aus irgendwelchen Gründen nicht anwählen, daher landete mein Post nicht im EibPC Teil des Forums.
              Hallo Martin,

              den Prefix EibPC gibt es natürlich nicht im allgemeinen KNX-Forum!

              Für EibPC-Fragen öffne einfach das passende Support-UnterForum EibPC (knx-user-forum.de/eibpc) und stelle dort deine Fragen. So erreichst du direkt die passenden Experten.

              Gruß /Markus

              Kommentar


                #8
                Danke für den Hinweis, Markus. Irgendwie habe ich das Gefühl das Früher in allen Foren alle Präfix gewählt werden konnten.

                Gruss,
                Martin

                Kommentar


                  #9
                  Hi Martin,

                  ja, viel früher als noch weniger unterschiedliche Bereiche vorhanden waren. Mittlerweile sind ja diverse Unterforen vorhanden mit jeweils eigenen und unterforumsspezifischen Prefixes.

                  Gruß /Markus

                  Kommentar


                    #10
                    Hier noch das Makro zum Gude Code:

                    [highlight=epc] begin GUDEcontrol (GudeIP, GudePort, GudeCh, GudeState, GudeTrigger)

                    :info $controls Gude outputs$\\
                    $IP Address$\\
                    $IP Port [u16]$\\
                    $Output 1..4$\\
                    $State [0b01]$\\
                    $Trigger [0b01]$\\

                    :shortinfo $controls GUDE outputs$\\

                    :var CRLF@
                    :var GUDE_GET_1@
                    :var GUDE_GET_2@
                    :var GUDE_GET_3@
                    :var GUDE_GET_4@
                    :var GUDE_GET_5@
                    :var GUDE_http_string@


                    CRLF@ = $$
                    stringset(CRLF@, 0x0A0Du16, 0u16)

                    // http string

                    GUDE_GET_1@ = $GET /?cmd=1&p=$+GudeCh+$&s=$ + convert(GudeState,$$) + $ HTTP/1.1$ + CRLF@
                    GUDE_GET_2@ = $User-Agent: Wget/ 1.0.10$ + CRLF@
                    GUDE_GET_3@ = $Accept: */*$ + CRLF@
                    GUDE_GET_4@ = $Host: $ + convert(GudeIP,$$) + CRLF@
                    GUDE_GET_5@ = $Connection: Keep-Alive$ + CRLF@ + CRLF@
                    GUDE_http_string@ = GUDE_GET_1@ + GUDE_GET_2@ + GUDE_GET_3@ + GUDE_GET_4@ + GUDE_GET_5@


                    //communication variables

                    :var GUDESendDelay@
                    GUDESendDelay@ = 500u64

                    :var GUDEconnectionState@
                    GUDEconnectionState@ = 6u08

                    :var GUDECommandSent@
                    GUDECommandSent@=0b01

                    GudeCh^OutputState=0b01
                    GudeCh^Cascade=0b01

                    // connect to host

                    if after(GudeTrigger, GUDESendDelay@) then \\
                    GUDEconnectionState@ = connecttcp(GudePort,GudeIP) \\
                    endif

                    // send TCP telegram

                    if change(GUDEconnectionState@) and GUDEconnectionState@ == 0u08 then {
                    sendtcparray(GudePort, GudeIP, GUDE_http_string@, size(GUDE_http_string@));
                    GUDECommandSent@=1b01
                    }endif

                    // disconnect

                    if after(GUDECommandSent@, GUDESendDelay@) then {

                    closetcp(GudePort, GudeIP);
                    GudeTrigger=0b01
                    }endif


                    // return output status

                    if GUDECommandSent@ then {
                    GudeCh^OutputState=GudeState;
                    GudeCh^Cascade=1b01;
                    GUDECommandSent@=0b01
                    }endif


                    :end [/highlight]
                    Kritik oder Anmerkungen erwünscht.

                    Kommentar


                      #11
                      Hi Martin,

                      Sorry, but I hope I can ask my question in the English language; in the German language it would take me forever....

                      I am very interested in your project, as I use similar commands to 'talk' to my always-on-low-power pc. It runs Eventghost, a home automation program, which features a webserver plugin. This means I can send commands to the Eventghost automation program by sending commands like:
                      http://192.168.1.40/index.html/?sbwoonkaan (this will send the command "sbwoonkaan" to Eventghost. This is programmed to switch on a squeezebox.

                      Likewise, I have an Irtrans LAN module with an internal database that also uses the same approach for sending commands via infrared. So, for instance, http://192.168.1.28/send.htm?remote=...nd=volup&led=3 will increase the volume of a sony receiver.

                      Similar commands can also be used to directly control a logitech squeezebox (via IP address commands to the squeezebox server IP address of my NAS device).

                      So I see a lot of potential use for your program for my applications, provided I can understand what is going on in your code.
                      I am just setting my first careful steps into the EIBPC programming, so most of the programming language is new to me.

                      To be honest, it looks quite a bit more difficult than I had imagined (hoped) it to be just to send a simple http command out....
                      Maybe this is because of the fact that your code is actually a macro.
                      Would it be possible for you to explain a bit more of the basics of your code?
                      For instance, basically all of the stuff:

                      // http string

                      GUDE_GET_1@ = $GET /?cmd=1&p=$+GudeCh+$&s=$ + convert(GudeState,$$) + $ HTTP/1.1$ + CRLF@
                      GUDE_GET_2@ = $User-Agent: Wget/ 1.0.10$ + CRLF@
                      GUDE_GET_3@ = $Accept: */*$ + CRLF@
                      GUDE_GET_4@ = $Host: $ + convert(GudeIP,$$) + CRLF@
                      GUDE_GET_5@ = $Connection: Keep-Alive$ + CRLF@ + CRLF@
                      GUDE_http_string@ = GUDE_GET_1@ + GUDE_GET_2@ + GUDE_GET_3@ + GUDE_GET_4@ + GUDE_GET_5@
                      I do not understand

                      :var GUDEconnectionState@
                      GUDEconnectionState@ = 6u08
                      Why is the connection state in the form 6u08?

                      What actually is the "GudeTrigger" and when would it activate?

                      Mmmm, a lot of NOOB questions, which I can probably find somewhere in the manual. However, the manual is so huge that I found it difficult to filter out the stuff that is actually needed for a specific problem. Hence my questions here. If you don't feel like answering, that is OK too: I won't feel offended


                      Best regards,
                      Perry

                      Kommentar


                        #12
                        Hi Perry

                        You are probably talking to the least experienced EibPC user. But I see you gotta start somewhere;-) If you look at the earlier posts in this thread, you'll see that I actually thought a simple http command would do.

                        sendtcp(gudePort, gudeIP, $http://192.168.178.101/?cmd=1&p=1&s=1$,13,10);

                        I assumed that to be sufficient, since it worked with Telnet. Of course, it didn't work for the EibPC.


                        Jambala chipped in and provided me with the whole code. All I had to do is grasp the concepts of macro writing and turn it into a macro. Http requests seem to consist of multiple strings, one of which actually contains the actual command. If you look at post #3, you'll find a more readable code. Macros do look a bit funny and add to the confusion.

                        TCP_ConnectionState = 6u08

                        This simply gives the TCP_ConnectionState variable a value that will not be returned by tcpconnect. Since it is used to hold the return result of tcpconnect (0 being the one for a successful connection).

                        The trigger is used to start the macro or code. Like a button that turns on a light. I actually set the trigger here:


                        [highlight=epc]
                        if pbutton(8,MultiMediaPageID)==1 or "Standby Computer System [EIN]-10/7/5" then {
                        GudeState1=!GudeState1;
                        GudeTrigger1=1b01;

                        if GudeState1 then pdisplay(8,$ON$,SWITCH,ACTIVE,GREY, MultiMediaPageID); write ("Standby Computer System [s]-10/7/6",EIN) \\
                        else pdisplay(8,$OFF$,SWITCH,INACTIVE,GREY, MultiMediaPageID); write ("Standby Computer System [s]-10/7/6",AUS) endif;

                        }endif
                        [/highlight]


                        The macro/code resets the trigger at some point so it can be triggered again.

                        This, I found, is one of the core concepts of programming an EibPC, variables that are used in code conditions need to change their values in order to allow subsequent code to run.


                        Hope this helps a bit. Maybe Jambala sheds some more light on the http request subject.


                        Cheers!
                        Martin

                        Kommentar


                          #13
                          Thanks for you explanations, Martin!

                          I see Jambala is working with Init, while you are not:

                          // Allgemeine Variablen definieren

                          Init = after(systemstart() == EIN, 5000u64)
                          CRLF = $$
                          GET_1 = $$
                          GET_2 = $$
                          GET_3 = $$
                          GET_4 = $$
                          GET_5 = $$
                          String = $$
                          TCP_ConnectionState = 6u08

                          // TCP Message für Abfrage

                          if Init == EIN then \\
                          stringset(CRLF, 0x0A0Du16, 0u16); \\
                          1. Does that mean that after each re-start (I am assuming Init is initial start up) of the EibPC, the command is sent (after the defined delay)?
                          2. Why are you not using the 'Init approach' in your macro?
                          3. Suppose I wanted to use 5 different 'http commands' (activated from e.g. EibPC's webserver or via existing GA's assigned to physical rocker switches or motion detectors); would I need to use the entire code 5 times (or use 5 different macros) with each time a different command in the first line of the 5 strings?

                          Kommentar


                            #14
                            that's okay, Perry. I hope I'm not adding to the confusion.

                            No, the idea of using macros is that you re-use the macro code throughout your program by simply calling them. The command strings would very likely be a parameter or an argument.

                            In my case, I could easily have used string constants, except for the one string with the actual command, but they don't really exist in EibStudio's programming language. I don't know why Jambala used the startup routine to initiate the sending of the http request. But before you get too much into macros , write the normal code and then think of a way to write a macro to simplify your code.

                            Attached you'll find my 'normal' code, before it became a marco.

                            Cheers!
                            Martin
                            Angehängte Dateien

                            Kommentar


                              #15
                              irTrans can be easily controlled by CLI. Brick turned it into a nice macro recently. Here's some code:

                              https://knx-user-forum.de/eibpc/1198...ueber-tcp.html

                              Sorry, I haven't paid close attention to what devices you were actually going to control. My mind was all caught up in http requests. There's also a Squeezebox macro. It just crossed my mind now. Sorry!

                              Kommentar

                              Lädt...
                              X