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
  String / HTTP Request Marc2014 2 76 08.12.2016 09:05
Letzter Beitrag: amithlon
  Servo über Temperatur steuern querkopf71 3 83 07.12.2016 19:21
Letzter Beitrag: hotsystems
  Kommunikation über das WiFi-Shield Flap 3 235 07.11.2016 20:20
Letzter Beitrag: hotsystems
  Menü über Bluetooth Eingabe abwarten anwo 4 505 18.10.2016 08:59
Letzter Beitrag: Lolliball
  Daten über USB verarbeiten Felix91 10 331 12.10.2016 13:00
Letzter Beitrag: Tommy56
  Code mit Verifikation über Keypad & LCD machnetz 5 216 10.10.2016 15:01
Letzter Beitrag: torsten_156
  Arduino Steuern über eigne Homepage b3ta 8 406 16.08.2016 11:07
Letzter Beitrag: Pit
  Zwei ident Feuchtesensoren an Arduino Uno R4 Karli 5 357 24.07.2016 23:36
Letzter Beitrag: SkobyMobil
  Sketch konnte nicht angelegt werden Sarius 2 244 16.07.2016 15:59
Letzter Beitrag: Sarius
  DUE-MEGA über I2C Verbinden HTO 0 223 22.05.2016 10:16
Letzter Beitrag: HTO

Gehe zu:


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