<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[RemoteXY community — Edit Field Bazaar Consequences]]></title>
	<link rel="self" href="https://forum.remotexy.com/extern.php?action=feed&amp;tid=1088&amp;type=atom" />
	<updated>2020-07-10T10:34:12Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.remotexy.com/viewtopic.php?id=1088</id>
		<entry>
			<title type="html"><![CDATA[Re: Edit Field Bazaar Consequences]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=3178#p3178" />
			<content type="html"><![CDATA[<p>I have made several things using a ds3231, interrupts, buttons and remotexy, without any problem, so I don&#039;t know what you have read but maybe you are just doing something wrong</p><p>You don&#039;t need to use interrupts for buttons but even if you do that, there shouldn&#039;t be any problem if you use interrupts <a target="_blank" href="http://gammon.com.au/interrupts">correctly</a></p><p>Show full code if you want more help</p>]]></content>
			<author>
				<name><![CDATA[Guillaume]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=23</uri>
			</author>
			<updated>2020-07-10T10:34:12Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=3178#p3178</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Edit Field Bazaar Consequences]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=3177#p3177" />
			<content type="html"><![CDATA[<p>Hi,</p><p>I have made the strings the same length in the corresponding arrays, so this should be OK.</p><p>Thanks your reset command, it is far more elegant!</p><p>My project is linked to a clock I have made using Adafruit NeoPixel LED arrays and an RTC DS3221 module.</p><p>I have built into the clock lots of encouragement messages which display depending on which colour button is pressed (for my sister). However, I would like to add the ability of her sending her own messages to the LED arrays from her mobile phone. So in answer to your final question, I just find it easier to take a variable and play with it, as opposed to using the one within the RemoteXY software.</p><p>However, I am very close to abandoning using remoteXY, as I have learnt it doesn&#039;t handle interrupt requests well and the buttons on my clock and the menu system for configuring date/time/colours etc are all triggered by interrupts.</p><p>Regards,</p><p>Christopher</p>]]></content>
			<author>
				<name><![CDATA[c.m.cooper]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=1444</uri>
			</author>
			<updated>2020-07-10T09:23:58Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=3177#p3177</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Edit Field Bazaar Consequences]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=3169#p3169" />
			<content type="html"><![CDATA[<p>So long as receivedMsg is big enough to contain all the characters of RemoteXY.Text_2, there is nothing wrong with this line:<br /></p><div class="codebox"><pre><code>strcpy (receivedMsg, RemoteXY.Text_2);</code></pre></div><p>To reset a c string you can use memset like you did, but it&#039;s far more efficient to do:<br /></p><div class="codebox"><pre><code>receivedMsg[0] = &#039;\0&#039;;</code></pre></div><p>But, why do you need receivedMsg anyway ? Why not simply use RemoteXY.Text_2 ?</p>]]></content>
			<author>
				<name><![CDATA[Guillaume]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=23</uri>
			</author>
			<updated>2020-07-08T20:09:36Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=3169#p3169</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Edit Field Bazaar Consequences]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=3168#p3168" />
			<content type="html"><![CDATA[<p>Hi,</p><p>So, answers in turn to your comments, although the app still giving funny results.</p><br /><p>Your initial comment:</p><div class="quotebox"><blockquote><p>This variable can store a single character:</p></blockquote></div><p>So I updated the char variable to be an array as follows:</p><div class="codebox"><pre><code>char receivedMsg[51];</code></pre></div><p>When you stated:</p><div class="quotebox"><blockquote><p>You are writing to memory that you should not access.</p><p>Even if RemoteXY.Text_2 is apparently a single character &#039;Y&#039;, in fact it&#039;s two characters: &#039;Y&#039; and &#039;\0&#039; which is the null terminator of the C string (it&#039;s used to indicate the end of the string), so it writes &#039;Y&#039; to your char variable, and it writes &#039;\0&#039; to the next memory cell, which is used for something else, introducing a bug in your program so strange things (or crash) will happens.</p></blockquote></div><p>I understand this concept, so I have updated it to copy each array space using a for loop as follows:</p><div class="codebox"><pre><code>  for (int i = 0; i &lt;= 51; i++)
  {
    strcpy (receivedMsg[i], RemoteXY.Text_2[i]);    // Copy received text from RemoteXY app to new variable.
  }
  </code></pre></div><p>Then you stated:</p><div class="quotebox"><blockquote><p>That&#039;s not how you compare c strings</p></blockquote></div><p>So reading a variety of methods, concluded that I need to check if the arrays first position finishes with a null terminator as you stated at the beginning:</p><div class="codebox"><pre><code> if (receivedMsg[0] != &#039;\0&#039;) {                     // Check if variable has data.

    Serial.print(&quot;Message Received: &quot;);             // Print data to serial monitor.
    Serial.println(receivedMsg);</code></pre></div><p>And finally, you commented:</p><div class="quotebox"><blockquote><p>That&#039;s not how you reset c strings</p></blockquote></div><p>Which I have now updated to blank the array as follows:</p><div class="codebox"><pre><code>memset(receivedMsg, 0, sizeof(51));    </code></pre></div><p>Am I on the right course or should I give up and turn into a goat herder in the Himalayas?</p>]]></content>
			<author>
				<name><![CDATA[c.m.cooper]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=1444</uri>
			</author>
			<updated>2020-07-08T15:50:59Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=3168#p3168</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Edit Field Bazaar Consequences]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=3167#p3167" />
			<content type="html"><![CDATA[<p>Hi Guillaume,</p><p>Thanks, your replies have confirmed some thoughts I was having about &quot;char&quot;, &quot;strings&quot; and &quot;Strings&quot; with a capital S!</p><p>I will go away and do some more reading.</p><p>Regards,</p><p>Christopher</p>]]></content>
			<author>
				<name><![CDATA[c.m.cooper]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=1444</uri>
			</author>
			<updated>2020-07-08T14:59:50Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=3167#p3167</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Edit Field Bazaar Consequences]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=3163#p3163" />
			<content type="html"><![CDATA[<p>Hi,</p><p>This variable can store a single character:<br /></p><div class="codebox"><pre><code>char receivedMsg;</code></pre></div><p>So when you do:<br /></p><div class="codebox"><pre><code>strcpy (receivedMsg, RemoteXY.Text_2);</code></pre></div><p>You are writing to memory that you should not access.</p><p>Even if RemoteXY.Text_2 is apparently a single character &#039;Y&#039;, in fact it&#039;s two characters: &#039;Y&#039; and &#039;\0&#039; which is the null terminator of the C string (it&#039;s used to indicate the end of the string), so it writes &#039;Y&#039; to your char variable, and it writes &#039;\0&#039; to the next memory cell, which is used for something else, introducing a bug in your program so strange things (or crash) will happens.</p><br /><div class="codebox"><pre><code>if (receivedMsg &gt; &quot;&quot;)</code></pre></div><p>That&#039;s not how you compare c strings</p><br /><div class="codebox"><pre><code>receivedMsg = &quot;&quot;;</code></pre></div><p>That&#039;s not how you reset c strings</p><br /><p>I suggest you look tutorials how to use c strings</p>]]></content>
			<author>
				<name><![CDATA[Guillaume]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=23</uri>
			</author>
			<updated>2020-07-08T12:04:42Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=3163#p3163</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Edit Field Bazaar Consequences]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=3161#p3161" />
			<content type="html"><![CDATA[<p>Hi all,</p><p>Just trying something really basic, which is sending a char string to the Arduino and then displaying it within serial monitor. My code is at the end of this message.</p><p>As a check, the code includes the basic LED operators, which all work fine when no text is sent.</p><p>When I send the text, nothing appears in the serial monitor and further more, both LEDs illuminate. It cant be down to the string being sent exceeding the field length, as that is set to 51 and this happens if I simply send a &#039;Y&#039; </p><p>--------------------------------------------------------------------</p><p>//////////////////////////////////////////////<br />//&nbsp; &nbsp; &nbsp; &nbsp; RemoteXY include library&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //<br />//////////////////////////////////////////////</p><p>// RemoteXY select connection mode and include library <br />#define REMOTEXY_MODE__ESP8266_SOFTSERIAL_POINT<br />#include &lt;SoftwareSerial.h&gt;</p><p>#include &lt;RemoteXY.h&gt;</p><p>// RemoteXY connection settings <br />#define REMOTEXY_SERIAL_RX 2<br />#define REMOTEXY_SERIAL_TX 3<br />#define REMOTEXY_SERIAL_SPEED 19200<br />#define REMOTEXY_WIFI_SSID &quot;RemoteXY&quot;<br />#define REMOTEXY_WIFI_PASSWORD &quot;123456789&quot;<br />#define REMOTEXY_SERVER_PORT 6377</p><br /><p>// RemoteXY configurate&nbsp; <br />#pragma pack(push, 1)<br />uint8_t RemoteXY_CONF[] =<br />&nbsp; { 255,53,0,52,0,49,0,10,5,1,<br />&nbsp; 2,0,32,15,22,11,2,26,31,31,<br />&nbsp; 79,78,0,79,70,70,0,1,0,37,<br />&nbsp; 35,12,12,2,31,88,0,7,36,34,<br />&nbsp; 56,20,5,2,26,2,51,67,4,33,<br />&nbsp; 66,20,5,2,26,52 };<br />&nbsp; <br />// this structure defines all the variables and events of your control interface <br />struct {</p><p>&nbsp; &nbsp; // input variables<br />&nbsp; uint8_t Blue_LED; // =1 if switch ON and =0 if OFF <br />&nbsp; uint8_t button_1; // =1 if button pressed, else =0 <br />&nbsp; char Text_2[51];&nbsp; // string UTF8 end zero&nbsp; </p><p>&nbsp; &nbsp; // output variables<br />&nbsp; char Text_1[52];&nbsp; // string UTF8 end zero </p><p>&nbsp; &nbsp; // other variable<br />&nbsp; uint8_t connect_flag;&nbsp; // =1 if wire connected, else =0 </p><p>} RemoteXY;<br />#pragma pack(pop)</p><p>/////////////////////////////////////////////<br />//&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;END RemoteXY include&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //<br />/////////////////////////////////////////////</p><p>#define PIN_BLUE_LED 13<br />#define PIN_BUTTON_1 12</p><p>char receivedMsg;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// New variable for received text.<br />&nbsp; <br />void setup() <br />{<br />&nbsp; RemoteXY_Init (); <br />&nbsp; Serial.begin(9600);<br />&nbsp; pinMode (PIN_BLUE_LED, OUTPUT);<br />&nbsp; pinMode (PIN_BUTTON_1, OUTPUT);<br />&nbsp; <br />&nbsp; // TODO you setup code</p><p>} // Close Setup.</p><p>void loop() <br />{ <br />&nbsp; RemoteXY_Handler ();<br />&nbsp; <br />&nbsp; digitalWrite(PIN_BLUE_LED, (RemoteXY.Blue_LED==0)?LOW:HIGH);<br />&nbsp; digitalWrite(PIN_BUTTON_1, (RemoteXY.button_1==0)?LOW:HIGH);<br />&nbsp; <br />&nbsp; // TODO you loop code<br />&nbsp; // use the RemoteXY structure for data transfer<br />&nbsp; // do not call delay() </p><p>&nbsp; strcpy (receivedMsg, RemoteXY.Text_2);&nbsp; &nbsp; // Copy received text from RemoteXY app to new variable.</p><p>&nbsp; if (receivedMsg &gt; &quot;&quot;) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Check if variable has data.</p><p>&nbsp; &nbsp; Serial.print(&quot;Message Received: &quot;);&nbsp; &nbsp; &nbsp;// Print data to serial monitor.<br />&nbsp; &nbsp; Serial.println(receivedMsg);</p><p>&nbsp; &nbsp; receivedMsg = &quot;&quot;;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Reset variable to blank.<br />&nbsp; &nbsp; <br />&nbsp; } // Close if.</p><p>} // Close loop</p>]]></content>
			<author>
				<name><![CDATA[c.m.cooper]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=1444</uri>
			</author>
			<updated>2020-07-08T11:30:29Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=3161#p3161</id>
		</entry>
</feed>
