Ich möchte von einem Arduino (Webserver) Daten empfangen über : 192.168.2.105 mit Purebasic.
Wenn ich mein Google Chrome starte und 192.168.2.105 eingebe , kommen die Daten vom Arduino an:
analog input 1 is 309
analog input 2 is 281
analog input 3 is 275
analog input 4 is 288
analog input 5 is 271
Wer kann mir das einmal Zeigen. Ich bekomme das nicht hin.
Das Programm vom Arduino, welches die Daten sendet , da sind drin Port und IP :
Code: Alles auswählen
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 2, 105);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("<br />");
}
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
} else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
Ethernet.maintain();
}
}
Code: Alles auswählen
Global Quit.l, Port.l, conID.l, status.l, cEvent.l, Result.l
Global text_e.s,
*DataBuffer = AllocateMemory(128)
If OpenWindow(0, 10, 10, 410, 500, "Client ", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
ButtonGadget(1,5, 10,100, 20, "Ende")
ButtonGadget(2,120, 10, 100, 20, "Connect")
ButtonGadget(3,235, 10, 140, 20, "Disconnect")
EditorGadget(4, 10, 60, 300, 400)
ButtonGadget(5,320,60, 80, 25, "Cls Edit")
Quit = 0
Port = 80
status = 0
InitNetwork()
Repeat
EventID.l = WaitWindowEvent(10)
Select EventID
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Quit = 1
Case 2
If Not status
conID = OpenNetworkConnection("192.168.2.105", Port)
If conID
status = 1
SetGadgetText(4, GetGadgetText(4) + #CR$ + "- Connected -" + #CR$)
EndIf
EndIf
Case 3
;Disconnect
If status <> 0
CloseNetworkConnection(conID)
status = 0
SetGadgetText(4, GetGadgetText(4) + #CR$ + "- Connection closed -" + #CR$)
EndIf
Case 5
text_e=""
SetGadgetText(4, text_e)
EndSelect
EndSelect
If status
cEvent = NetworkClientEvent(conID)
Select cEvent
Case #PB_NetworkEvent_Data
Repeat
Result = ReceiveNetworkData(ConID, *DataBuffer, 128)
SetGadgetText(4, GetGadgetText(4) + PeekS(*DataBuffer, Result,#PB_Ascii))
Until Result < 128
EndSelect
EndIf
Until Quit = 1 Or EventID = #PB_Event_CloseWindow
EndIf
FreeMemory(*DataBuffer)
End
Gruss