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
  Display über I2-Bus betreiben mfri 11 147 Heute 14:45
Letzter Beitrag: mfri
  LED langsam über 15 Minuten dimmen Kriskind 9 159 17.01.2017 21:10
Letzter Beitrag: Tommy56
  Messdatenausgabe auf Webserver über NanoESP RivaDynamite 10 290 10.01.2017 15:49
Letzter Beitrag: renid55
  Über drei Taster zwei externe Timer steuern Sidamo 23 324 09.01.2017 20:12
Letzter Beitrag: Tommy56
  LED Dimmen über Bewegungsmelder Jens040774 8 156 05.01.2017 19:07
Letzter Beitrag: renid55
  Variable über EEPROM in ein Script einbinden... Badger1875 5 476 01.01.2017 15:08
Letzter Beitrag: Tommy56
  Ausgang "blinken" lassen NormanIGB 11 379 28.12.2016 17:20
Letzter Beitrag: Tommy56
  String / HTTP Request Marc2014 4 227 23.12.2016 15:42
Letzter Beitrag: Tommy56
  Servo über Temperatur steuern querkopf71 3 216 07.12.2016 19:21
Letzter Beitrag: hotsystems
  Kommunikation über das WiFi-Shield Flap 3 291 07.11.2016 20:20
Letzter Beitrag: hotsystems

Gehe zu:


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