Merhabalar, Arduino ile .net web servise nasıl bağlantı kurabilirim. Bu konuda çok uzun zamandır uğraşıyorum ama bir arpa boyu kadar yol alamadım. Ne data gönderebiliyorum nede gelen cevabı okuyabiliyorum. Neredeyse internetteki bütün örneklere göz attım.. Hiçbirinde bağlantı sağlayamadım
yardımcı olabilecek ve konuyu pekiştirmemi sağlayabilecek bir arkadaş var mıdır ? Amacım ws.example.com/webservicetest.asmx servisine “12345” göndermek ve gelen cevabı okumak. Bunu birtürlü beceremedim. ![]()
kullandığın ethernet shild de direk tcp/ip socket datasını okuyabilmen kazım direk yazıp okumayı dene.
Web servisinin kullanimi detaylanmaya gidiyorsa uno ile zorlamak yerine dogrudan ethernet baglantili (beaglebone, pcduino vb.) Kartlara bakmakta fayda var. Arduino + ethernet shield temel kullanimda iyi ama is detaylaninca bazi sikintilara gebe ya da daha ugrastirici gibi geliyor bana. Kullananlar anlatsin sikintilarini
Denediğim uygulama aşağıda, nerede hata yapıyorum bir bilen varsa yardımcı olabilir mi ? include <spi.h>
include <ethernet.h>
byte mac = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server = “ws.example.com/webservicetest.asmx”;
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,0,3);
IPAddress gateway(192,168,0,1);
IPAddress subnet(255,255,255,0);
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println(“Failed to configure Ethernet using DHCP”);
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip, gateway, subnet);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println(“connecting…”);
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println(“connected”);
// Make a HTTP request:
client.print("GET /ws.example.com/webservicetest.asmx?Deneme1=12345");
client.println(" HTTP/1.1");
client.println("Host: ws.example.com");
client.println("Connection: close");
client.println("Content-Type: text/xml; charset=UTF-8");
client.println("Content-Length: length");
client.println();
}
else {
// if you didn’t get a connection to the server:
Serial.println(“connection failed”);
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if the server’s disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println(“disconnecting.”);
client.stop();
// do nothing forevermore:
while(true);
}
}
</ethernet.h></spi.h>
program duzgun gorunuyor bilgisayarınızdaki network ayarları nasılsa arduinoda da benzer ayarları yapın. ip ve gateway adreslerine dikkat edin.