<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pl-pl">
<link rel="self" type="application/atom+xml" href="https://forum.atnel.pl/feed.php?f=47&amp;t=5564&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2014-01-17T17:20:42+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=47&amp;t=5564&amp;mode</id>
<entry>
<author><name><![CDATA[adi19887]]></name></author>
<updated>2014-01-17T17:20:42+01:00</updated>
<published>2014-01-17T17:20:42+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=5564&amp;p=65350#p65350</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=5564&amp;p=65350#p65350"/>
<title type="html"><![CDATA[Re: [java][arduino]TCP serwer Arduino]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=5564&amp;p=65350#p65350"><![CDATA[
Dobrze sam sobie odpowiem <img src="https://forum.atnel.pl/images/smilies/icon_razz.gif" alt=":P" title="Pokazuje język" /><br /><br />Trzeba było jedynie wyzerować (czyli usunąc) zawartość stringa wiadomosc_od_klienta po każdym odbiorze. Teraz chodzi jak malina <img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":)" title="Szczęśliwy" />. [Informacja dla mnie podobnych]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=2079">adi19887</a> — 17 sty 2014, o 17:20</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[adi19887]]></name></author>
<updated>2014-01-16T13:58:35+01:00</updated>
<published>2014-01-16T13:58:35+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=5564&amp;p=65222#p65222</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=5564&amp;p=65222#p65222"/>
<title type="html"><![CDATA[[java][arduino]TCP serwer Arduino]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=5564&amp;p=65222#p65222"><![CDATA[
Witam serdecznie,<br /><br />Kombinuję jakby tutaj zrobić komunikację po ethernet między moim arduino mega i ethernet shield. Komunikuje mnie się dobrze, (załącza wyjście na moje żądanie) jednak każde kolejne polecenie jest ignorowane (nieodbierane ?). Nie znam TCP na tyle dobrze aby rozwiązać ten problem samemu więc piszę tutaj. Wklejam kod:<br />[syntax=cpp]#define zaw1 22<br />#define zaw2 23<br />#define zaw3 24<br />#define zaw4 25<br />#define zaw5 26<br />#define zaw6 27<br /><br />#define nad1 28<br />#define nad2 29<br />#define nad3 30<br />#define nad4 31<br />#define nad5 32<br />#define nad6 33<br /><br />#define spus 34<br />#define pomp 35<br /><br /><br />#include &lt;SPI.h&gt;<br />#include &lt;Ethernet.h&gt;<br /><br />// Enter a MAC address for your controller below.<br />// Newer Ethernet shields have a MAC address printed on a sticker on the shield<br />byte mac&#91;&#93; = {  <br />  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };<br />byte serverIP&#91;&#93; = {192,168,0,215};<br />int serverPort=8888;<br />String wiadomosc_od_klienta= &quot;&quot;;<br />String tryb1= &quot;&quot;;<br />String data1= &quot;&quot;;<br />int wyjscie;<br />long previousMillis = 0;<br />long interval = 1000; <br />// Initialize the Ethernet client library<br />// with the IP address and port of the server <br />// that you want to connect to (port 80 is default for HTTP):<br />EthernetServer server(serverPort);<br /><br />void setup() {<br />  // start the serial library:<br />  Serial.begin(9600);<br />  // start the Ethernet connection:<br />  Ethernet.begin(mac, serverIP);<br />  server.begin();<br />  <br />  Serial.println(&quot;Server started&quot;);<br />  //Inicjalizuje wyjscia<br />  inicjalizujwyjscia_zawory();<br />  inicjalizacjaethernet_nadmuch();<br />  inicjalizacjaethernet_spust();<br />  inicjalizacjaethernet_pompa();<br />  }<br />  <br /><br /><br />void inicjalizujwyjscia_zawory()<br />{<br /><br />  <br />  pinMode(zaw1,OUTPUT);<br />  pinMode(zaw2,OUTPUT);<br />  pinMode(zaw3,OUTPUT);<br />  pinMode(zaw4,OUTPUT);<br />  pinMode(zaw5,OUTPUT);<br />  pinMode(zaw6,OUTPUT);<br />  <br />  digitalWrite(zaw1,LOW);<br />  digitalWrite(zaw2,LOW);<br />  digitalWrite(zaw3,LOW);<br />  digitalWrite(zaw4,LOW);<br />  digitalWrite(zaw5,LOW);<br />  digitalWrite(zaw6,LOW);<br />  <br />}<br /><br />void inicjalizacjaethernet_nadmuch()<br />{<br /><br />  <br />  pinMode(nad1,OUTPUT);<br />  pinMode(nad2,OUTPUT);<br />  pinMode(nad3,OUTPUT);<br />  pinMode(nad4,OUTPUT);<br />  pinMode(nad5,OUTPUT);<br />  pinMode(nad6,OUTPUT);<br />  <br />  digitalWrite(nad1,LOW);<br />  digitalWrite(nad2,LOW);<br />  digitalWrite(nad3,LOW);<br />  digitalWrite(nad4,LOW);<br />  digitalWrite(nad5,LOW);<br />  digitalWrite(nad6,LOW);<br />  <br />}<br /><br />void inicjalizacjaethernet_spust()<br />{<br /><br />  <br />  pinMode(spus,OUTPUT);<br />  <br />  digitalWrite(spus,HIGH); //Załączam w inicjalizacji zeby spust był załączony.<br /> }<br /><br />void inicjalizacjaethernet_pompa()<br />{<br /> <br />  <br />  pinMode(pomp,OUTPUT);<br />  <br />  digitalWrite(pomp, LOW);<br />}<br /><br />int wybor_wyjscia(String data)<br />{<br />  if(data == &quot;zaw1&quot;)<br />  return zaw1;<br />  if(data == &quot;zaw2&quot;)<br />  return zaw2;<br />  if(data == &quot;zaw3&quot;)<br />  return zaw3;<br />  if(data == &quot;zaw4&quot;)<br />  return zaw4;<br />  if(data == &quot;zaw5&quot;)<br />  return zaw5;<br />  if(data == &quot;zaw6&quot;)<br />  return zaw6;<br />  <br />  if(data == &quot;nad1&quot;)<br />  return nad1;<br />  if(data == &quot;nad2&quot;)<br />  return nad2;<br />  if(data == &quot;nad3&quot;)<br />  return nad3;<br />  if(data == &quot;nad4&quot;)<br />  return nad4;<br />  if(data == &quot;nad5&quot;)<br />  return nad5;<br />  if(data == &quot;nad6&quot;)<br />  return nad6;<br />  <br />  if(data == &quot;spus&quot;)<br />  return spus;<br />  if(data == &quot;pomp&quot;)<br />  return pomp;<br />  <br />  <br />}<br />void EthernetNadaj(String tryb, String data)<br />{<br />  <br />  Serial.print(data);<br />  Serial.println(tryb);<br />  //Serial.print(data2);<br />}<br />void EthernetConnection()<br />{<br />  EthernetClient client = server.available(); //Nasłuchuje klientów<br />  if(client)<br />  {<br />    <br />      while(client.connected())<br />      {<br />        if(client.available())<br />        {  <br />            char c;<br />            c= client.read();<br />            wiadomosc_od_klienta += c; //łączy dane do stringa<br />            <br />            <br />         }<br />      }<br />      data1 = wiadomosc_od_klienta.substring(0,4);<br />      tryb1 = wiadomosc_od_klienta.substring(4,6);<br />  }<br />  client.stop();<br />}<br />void EthernetZalacz(String tryb, String odbior)<br />{<br />  int typ;<br />  int data;<br />  if(tryb == &quot;on&quot;)<br />  {<br />       typ = HIGH;<br />  }<br />  if(tryb == &quot;of&quot;)<br />  {<br />       typ = LOW;<br />  }<br />  data = wybor_wyjscia(odbior);<br />  digitalWrite(data,typ);<br />}<br /><br /><br /><br />void loop() {<br />  <br />  EthernetConnection();<br />   <br />  unsigned long currentMillis = millis();<br /> <br />  if(currentMillis - previousMillis &gt; interval) {<br />    // save the last time you blinked the LED<br />    previousMillis = currentMillis;<br />    EthernetNadaj(tryb1,data1);<br />  }<br />  EthernetZalacz(tryb1,data1);<br />  <br />}[/syntax]<br /><br />Oraz :<br />[syntax=java]import java.io.BufferedReader;<br />import java.io.DataOutputStream;<br />import java.io.InputStreamReader;<br />import java.net.Socket;<br />import java.util.Scanner;<br /> <br />class Client<br />{<br />    //Ip Adress and Port, where the Arduino Server is running on<br />    private static final String serverIP=&quot;192.168.0.215&quot;;<br />    private static final int serverPort=8888;<br /> <br />     public static void main(String argv&#91;&#93;) throws Exception<br />     {<br />          String msgToServer;//Message that will be sent to Arduino<br />          String msgFromServer;//recieved message will be stored here<br /> <br />          Socket clientSocket = new Socket(serverIP, serverPort);//making the socket connection<br />          System.out.println(&quot;Connected to:&quot;+serverIP+&quot; on port:&quot;+serverPort);//debug<br />          //OutputStream to Arduino-Server<br />          DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());<br />          //BufferedReader from Arduino-Server<br />          BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));//<br />          <br />          <br />          String imie;<br />          Scanner odczyt = new Scanner(System.in); //obiekt do odebrania danych od użytkownika<br />          imie = odczyt.nextLine();<br />          msgToServer = imie;//Message tha will be sent<br />          <br />          //msgToServer = &quot;Hello Arduino Server&quot;;//Message tha will be sent<br />          outToServer.writeBytes(msgToServer+'\n');//sending the message<br />          System.out.println(&quot;sending to Arduino-Server: &quot;+msgToServer);//debug<br />          //msgFromServer = inFromServer.readLine();//recieving the answer<br />          //System.out.println(&quot;recieved from Arduino-Server: &quot; + msgFromServer);//print the answer<br /> <br />          clientSocket.close();//close the socket<br />          //don't do this if you want to keep the connection<br />     }<br />}[/syntax]<br /><br />Polecenia wydaje za zasadzie:<br />zaw1on - załącza wyjscie 1<br />zaw1of - mialoby wyłączać wyjscie nr 1 jednak tego nie robi.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=2079">adi19887</a> — 16 sty 2014, o 13:58</p><hr />
]]></content>
</entry>
</feed>