INFO: Dieses Forum nutzt Cookies...
Cookies sind für den Betrieb des Forums unverzichtbar. Mit der Nutzung des Forums erklärst Du dich damit einverstanden, dass wir Cookies verwenden.

Es wird in jedem Fall ein Cookie gesetzt um diesen Hinweis nicht mehr zu erhalten. Desweiteren setzen wir Google Adsense und Google Analytics ein.

Antwort schreiben 
 
Themabewertung:
  • 2 Bewertungen - 4 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Mit dem Pin 8 und 9 vom Yun werden zwei LED wechselseitig blinken über http
02.12.2015, 12:26 (Dieser Beitrag wurde zuletzt bearbeitet: 02.12.2015 19:32 von arduinofan.)
Beitrag #1
Mit dem Pin 8 und 9 vom Yun werden zwei LED wechselseitig blinken über http
Hallo guten Tag.
Mit diesem FreeBasicprogramm werden vom Notebook aus der Pin 8 und 9 als Blinklicht geschaltet im Wechsel am Yun mit http:
------------------------------
httppost("192.168.240.1","data/put/ledhigh/10","")
Sleep 100,1
httppost("192.168.240.1","data/put/ledhigh/01","")
Sleep 100,1
------------------------------

Freebasicprogramm:
Code:
#Include "win/winsock2.bi"
#Include "windows.bi"
#Include "fbgfx.bi"
#include "vbcompat.bi"
Using FB

Dim Shared As String http_text

#DEFINE RECVBUFFLEN 16384
#Define newline CHR(13,10)

Sub InitWinsock Constructor
    '' init winsock
    DIM wsaData AS WSAData
    IF( WSAStartup( MAKEWORD( 1, 1 ), @wsaData ) <> 0 ) THEN
        PRINT "Error: WSAStartup failed"
        END 1
    END If
End SUB

SUB ExitWinsock Destructor
    WSACleanup
End SUB

FUNCTION httpget(server AS STRING, path AS STRING, hadd AS STRING = "") AS STRING
    DIM IP AS INTEGER
    DIM ia AS in_addr
    DIM s AS SOCKET
    DIM hostentry AS hostent PTR
    DIM sendbuffer AS STRING
    DIM recvbuffer AS ZSTRING * RECVBUFFLEN+1
    DIM bytes AS INTEGER
    DIM sa AS sockaddr_in
    DIM in AS STRING
    ia.S_addr = inet_addr( server )
    IF ( ia.S_addr = INADDR_NONE ) THEN
        hostentry = gethostbyname( server )
        IF ( hostentry = 0 ) THEN
            RETURN "IP couldn't be resolved!"
        END IF
        IP = *CAST( INTEGER PTR, *hostentry->h_addr_list )
    ELSE
        IP = ia.S_addr
    END IF
    s = opensocket( AF_INET, SOCK_STREAM, IPPROTO_TCP )
    IF( s = 0 ) THEN
        RETURN "Socket couldn't be opened."
    END IF
    sa.sin_port         = htons( 80 )
    sa.sin_family       = AF_INET
    sa.sin_addr.S_addr  = ip
    IF ( connect( s, CAST( PSOCKADDR, @sa ), LEN( sa )) = SOCKET_ERROR ) THEN
        closesocket( s )
        RETURN "Couldn't connect to host"
    END IF
    sendBuffer = "GET /" + path + " HTTP/1.0" + NEWLINE + _
    "Host: " + server + NEWLINE + _
    "Connection: close" + NEWLINE + _
    hadd + _
    NEWLINE
    IF( send( s, sendBuffer, LEN( sendBuffer ), 0 ) = SOCKET_ERROR ) THEN
        closesocket( s )
        RETURN "Couldn't send request"
    END IF
    DO
        bytes = recv( s, recvBuffer, RECVBUFFLEN, 0 )
        IF( bytes <= 0 ) THEN
            EXIT DO
        END IF
        recvbuffer[bytes] = 0
        in += recvbuffer
    LOOP
    shutdown( s, 2 )
    closesocket( s )
    RETURN in
END FUNCTION


FUNCTION httppost(server AS STRING, path AS STRING, toPost AS STRING, hadd AS STRING = "") AS STRING
    DIM IP AS INTEGER
    DIM ia AS in_addr
    DIM s AS SOCKET
    DIM hostentry AS hostent PTR
    DIM sendbuffer AS STRING
    DIM recvbuffer AS ZSTRING * RECVBUFFLEN+1
    DIM bytes AS INTEGER
    DIM sa AS sockaddr_in
    DIM in AS STRING

    ia.S_addr = inet_addr( server )
    IF ( ia.S_addr = INADDR_NONE ) THEN
        hostentry = gethostbyname( server )
        IF ( hostentry = 0 ) THEN
            RETURN "IP couldn't be resolved!"
        END IF
        IP = *CAST( INTEGER PTR, *hostentry->h_addr_list )
    ELSE
        IP = ia.S_addr
    END IF
    s = opensocket( AF_INET, SOCK_STREAM, IPPROTO_TCP )
    IF( s = 0 ) THEN
        RETURN "Socket couldn't be opened."
    END IF
    sa.sin_port         = htons( 80 )
    sa.sin_family       = AF_INET
    sa.sin_addr.S_addr  = ip
    IF ( connect( s, CAST( PSOCKADDR, @sa ), LEN( sa )) = SOCKET_ERROR ) THEN
        closesocket( s )
        RETURN "Couldn't connect to host"
    END IF
    sendBuffer = "POST /" + path + " HTTP/1.0" + NEWLINE + _
    "Host: " + server + NEWLINE + _
    "Content-Type: application/x-www-form-urlencoded" + NEWLINE + _
    "Content-Length: " + STR(LEN(toPost)) + NEWLINE + _
    "Connection: close" + NEWLINE + _
    hadd + _
    NEWLINE + _
    toPost + NEWLINE
    IF( send( s, sendBuffer, LEN( sendBuffer ), 0 ) = SOCKET_ERROR ) THEN
        closesocket( s )
        RETURN "Couldn't send request"
    END IF
    DO
        bytes = recv( s, recvBuffer, RECVBUFFLEN, 0 )
        IF( bytes <= 0 ) THEN
            EXIT DO
        END IF
        recvbuffer[bytes] = 0
        in += recvbuffer
    LOOP
    shutdown( s, 2 )
    closesocket( s )
    RETURN in
END Function

ScreenRes 400,500,32
ScreenControl SET_WINDOW_POS, 500, 40

Do
   If MULTIKEY(FB.SC_ESCAPE) Then
       End
   EndIf
   httppost("192.168.240.1","data/put/ledhigh/10","")
   Sleep 100,1
   httppost("192.168.240.1","data/put/ledhigh/01","")
   Sleep 100,1
   Cls
Loop

End

Yun-Programm:
Buffer[0] ist für Pin8 und Buffer[1] ist für Pin9.
Code:
#include <Bridge.h>

char buffer[16];

void setup() {
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  Bridge.begin();
}

void loop() {
  Bridge.get("ledhigh", buffer, 2);
  if (buffer[0] == '1') {
    digitalWrite(8, HIGH);
  } else {
    digitalWrite(8, LOW);
  }

  if (buffer[1] == '1') {
    digitalWrite(9, HIGH);
  } else {
    digitalWrite(9, LOW);
  }
}


Angehängte Datei(en) Thumbnail(s)
   
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
08.12.2015, 15:03 (Dieser Beitrag wurde zuletzt bearbeitet: 08.12.2015 16:38 von arduinofan.)
Beitrag #2
RE: Mit dem Pin 8 und 9 vom Yun werden zwei LED wechselseitig blinken über http
Hier wird eine Zahl übertragen vom Yun an das Freebasicprogramm. Die Zahl wird immer 1 erhöht und angezeigt im Screen.
-------------------------------------
http_text=httpget("192.168.240.1","data/get/analog0","")
-------------------------------------

Im Freebasicprogramm ändert sich immer nur die Do/Loop-Schleife.

Freebasicprogramm:
Code:
#Include "win/winsock2.bi"
#Include "windows.bi"
#Include "fbgfx.bi"
#include "vbcompat.bi"
Using FB

Dim Shared As String http_text

#DEFINE RECVBUFFLEN 16384
#Define newline CHR(13,10)

Sub InitWinsock Constructor
    '' init winsock
    DIM wsaData AS WSAData
    IF( WSAStartup( MAKEWORD( 1, 1 ), @wsaData ) <> 0 ) THEN
        PRINT "Error: WSAStartup failed"
        END 1
    END If
End SUB

SUB ExitWinsock Destructor
    WSACleanup
End SUB

FUNCTION httpget(server AS STRING, path AS STRING, hadd AS STRING = "") AS STRING
    DIM IP AS INTEGER
    DIM ia AS in_addr
    DIM s AS SOCKET
    DIM hostentry AS hostent PTR
    DIM sendbuffer AS STRING
    DIM recvbuffer AS ZSTRING * RECVBUFFLEN+1
    DIM bytes AS INTEGER
    DIM sa AS sockaddr_in
    DIM in AS STRING
    ia.S_addr = inet_addr( server )
    IF ( ia.S_addr = INADDR_NONE ) THEN
        hostentry = gethostbyname( server )
        IF ( hostentry = 0 ) THEN
            RETURN "IP couldn't be resolved!"
        END IF
        IP = *CAST( INTEGER PTR, *hostentry->h_addr_list )
    ELSE
        IP = ia.S_addr
    END IF
    s = opensocket( AF_INET, SOCK_STREAM, IPPROTO_TCP )
    IF( s = 0 ) THEN
        RETURN "Socket couldn't be opened."
    END IF
    sa.sin_port         = htons( 80 )
    sa.sin_family       = AF_INET
    sa.sin_addr.S_addr  = ip
    IF ( connect( s, CAST( PSOCKADDR, @sa ), LEN( sa )) = SOCKET_ERROR ) THEN
        closesocket( s )
        RETURN "Couldn't connect to host"
    END IF
    sendBuffer = "GET /" + path + " HTTP/1.0" + NEWLINE + _
    "Host: " + server + NEWLINE + _
    "Connection: close" + NEWLINE + _
    hadd + _
    NEWLINE
    IF( send( s, sendBuffer, LEN( sendBuffer ), 0 ) = SOCKET_ERROR ) THEN
        closesocket( s )
        RETURN "Couldn't send request"
    END IF
    DO
        bytes = recv( s, recvBuffer, RECVBUFFLEN, 0 )
        IF( bytes <= 0 ) THEN
            EXIT DO
        END IF
        recvbuffer[bytes] = 0
        in += recvbuffer
    LOOP
    shutdown( s, 2 )
    closesocket( s )
    RETURN in
END FUNCTION


FUNCTION httppost(server AS STRING, path AS STRING, toPost AS STRING, hadd AS STRING = "") AS STRING
    DIM IP AS INTEGER
    DIM ia AS in_addr
    DIM s AS SOCKET
    DIM hostentry AS hostent PTR
    DIM sendbuffer AS STRING
    DIM recvbuffer AS ZSTRING * RECVBUFFLEN+1
    DIM bytes AS INTEGER
    DIM sa AS sockaddr_in
    DIM in AS STRING

    ia.S_addr = inet_addr( server )
    IF ( ia.S_addr = INADDR_NONE ) THEN
        hostentry = gethostbyname( server )
        IF ( hostentry = 0 ) THEN
            RETURN "IP couldn't be resolved!"
        END IF
        IP = *CAST( INTEGER PTR, *hostentry->h_addr_list )
    ELSE
        IP = ia.S_addr
    END IF
    s = opensocket( AF_INET, SOCK_STREAM, IPPROTO_TCP )
    IF( s = 0 ) THEN
        RETURN "Socket couldn't be opened."
    END IF
    sa.sin_port         = htons( 80 )
    sa.sin_family       = AF_INET
    sa.sin_addr.S_addr  = ip
    IF ( connect( s, CAST( PSOCKADDR, @sa ), LEN( sa )) = SOCKET_ERROR ) THEN
        closesocket( s )
        RETURN "Couldn't connect to host"
    END IF
    sendBuffer = "POST /" + path + " HTTP/1.0" + NEWLINE + _
    "Host: " + server + NEWLINE + _
    "Content-Type: application/x-www-form-urlencoded" + NEWLINE + _
    "Content-Length: " + STR(LEN(toPost)) + NEWLINE + _
    "Connection: close" + NEWLINE + _
    hadd + _
    NEWLINE + _
    toPost + NEWLINE
    IF( send( s, sendBuffer, LEN( sendBuffer ), 0 ) = SOCKET_ERROR ) THEN
        closesocket( s )
        RETURN "Couldn't send request"
    END IF
    DO
        bytes = recv( s, recvBuffer, RECVBUFFLEN, 0 )
        IF( bytes <= 0 ) THEN
            EXIT DO
        END IF
        recvbuffer[bytes] = 0
        in += recvbuffer
    LOOP
    shutdown( s, 2 )
    closesocket( s )
    RETURN in
END Function

ScreenRes 400,500,32
ScreenControl SET_WINDOW_POS, 500, 40

Do
   If MULTIKEY(FB.SC_ESCAPE) Then
       End
   EndIf
   http_text=httpget("192.168.240.1","data/get/analog0","")
   PRINT http_text
   Sleep 100
Loop

End

Yun-Programm :
Code:
#include <Bridge.h>

int zahl;

void setup() {
  pinMode(A0, INPUT);
  Bridge.begin();
}

void loop() {
  zahladd();
  Bridge.put("analog0", String(zahl,DEC));
  delay(100);
}

void zahladd() {
  zahl=zahl+1;
}
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
Antwort schreiben 


Möglicherweise verwandte Themen...
Thema: Verfasser Antworten: Ansichten: Letzter Beitrag
  Taster 1 mal drücken = LED 2 mal blinken oder aufblitzen gordolino 19 1.149 03.11.2017 15:14
Letzter Beitrag: ardu_arne
  Richtungsblinker und Warnblinker über jeweils einen Schalter Crazydiver 25 1.203 04.10.2017 12:47
Letzter Beitrag: hotsystems
  Werden ungenutzte Funktionen weg optimiert? BennIY 1 290 03.10.2017 09:06
Letzter Beitrag: Tommy56
  2 LEDs unabhängig blinken lassen cappy0815 1 280 26.09.2017 07:42
Letzter Beitrag: hotsystems
  Kommunikation über das WiFi-Shield Flap 13 1.551 12.09.2017 22:12
Letzter Beitrag: Flap
  blinken mit millis Gonmaus 13 809 08.09.2017 21:12
Letzter Beitrag: Bitklopfer
  Zwei Arduinos mit ISP verbinden Binary1 17 1.675 01.08.2017 16:40
Letzter Beitrag: Binary1
  LED blinken zeitversetzt starten Sky-Shadow 6 593 17.06.2017 15:12
Letzter Beitrag: Sky-Shadow
  RGB Animation über Serial Steuern Medolino 5 769 20.02.2017 16:14
Letzter Beitrag: Medolino
  Arduino-UNO LED über Taster digital zum leuchten zu bringen IvKriz 9 827 18.02.2017 08:33
Letzter Beitrag: renid55

Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste