<?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=13428&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2015-11-01T22:33:18+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=47&amp;t=13428&amp;mode</id>
<entry>
<author><name><![CDATA[sliver001]]></name></author>
<updated>2015-11-01T22:33:18+01:00</updated>
<published>2015-11-01T22:33:18+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=13428&amp;p=144025#p144025</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=13428&amp;p=144025#p144025"/>
<title type="html"><![CDATA[Ethernet - wznawianie połączenia]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=13428&amp;p=144025#p144025"><![CDATA[
Napisałem prosty kod, który odczytuje ciśnienie i temperaturę z BMP180 i publikuje na serwerze MQTT ale mam problem - w przypadku odłączenia lan'u arduino nie potrafi wznowić połączenia z serwerem MQTT. Czy jest jakaś funkcja typu auto reconnect?<br /><br />[syntax=cpp]#include &lt;Wire.h&gt;<br />#include &lt;Adafruit_BMP085.h&gt;<br />#include &lt;SPI.h&gt;<br />#include &lt;Ethernet.h&gt;<br />#include &lt;PubSubClient.h&gt;<br /><br />float Tc=0;<br />float Pa=0;<br />#define MQTT_SERVER &quot;192.168.1.1&quot;<br />char TcString&#91;6&#93;;<br />char PaString&#91;6&#93;;<br />unsigned long time;<br /><br />byte mac&#91;&#93; = { 0x90, 0xA2, 0xDA, 0x00, 0x23, 0x38 };<br />IPAddress ip(192, 168, 1, 2);<br /><br />Adafruit_BMP085 bmp;<br /><br />char message_buff&#91;100&#93;;<br /><br />EthernetClient ethClient; <br />PubSubClient client( MQTT_SERVER, 1883, callback, ethClient);<br /><br />void setup() {<br />    byte i;<br />  Serial.begin(9600);<br />  delay( 500 );<br /> <br />  if (!bmp.begin()) {<br />Serial.println(&quot;Could not find a valid BMP085 sensor, check wiring!&quot;);<br />while (1) {}<br />  }<br />    while (!Serial) {; <br />  }<br /><br />  Ethernet.begin(mac, ip);<br />  Serial.print(&quot;server is at &quot;);<br />  Serial.println(Ethernet.localIP());<br />    if (client.connect(&quot;arduinoClient&quot;)) {      // connecting to MQTT server<br />    Serial.println(&quot;Connected to MQTT&quot;);      // Milestone for connection debugging<br />  }<br />}<br /><br /><br />void callback(char* topic, byte* payload, unsigned int length) {<br />  int i = 0;<br />  for(i=0; i&lt;length; i++) {<br />    message_buff&#91;i&#93; = payload&#91;i&#93;;<br />  }<br />  message_buff&#91;i&#93; = '\0';<br />  String msgString = String(message_buff);<br />  }<br />}<br />      <br />void loop() {<br /><br />  client.loop();    <br />  if (millis() &gt; (time + 15000)) {<br />    time = millis();<br />  Serial.print(&quot;Temperature = &quot;);<br />    Tc=bmp.readTemperature();<br />    dtostrf(Tc, 2, 2, TcString);<br />    Serial.print(Tc);<br />    Serial.println(&quot; *C&quot;);<br />    client.publish(&quot;/test/dom/temp1/&quot;,TcString);<br />       <br />    Serial.print(&quot;Pressure = &quot;);<br />    Pa=bmp.readPressure()/100;<br />    if(Pa&lt;1000) {<br />    dtostrf(Pa, 2, 2, PaString);<br />    } else {<br />    dtostrf(Pa, 1, 2, PaString);  <br />    }<br />    Serial.print(Pa);<br />    Serial.println(&quot; hPa&quot;);<br />    client.publish(&quot;/test/dom/cisnienie/&quot;,PaString);<br />    Serial.println();<br />  delay(1000);<br />}<br />}[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=11546">sliver001</a> — 1 lis 2015, o 22:33</p><hr />
]]></content>
</entry>
</feed>