<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Mysensors PH]]></title><description><![CDATA[<p dir="auto">/*<br />
Original code created by DFRobot for their probes,<br />
adapted by <a href="mailto:tony.dijksterhuis@gmail.com" rel="nofollow ugc">tony.dijksterhuis@gmail.com</a> Mysensors for the project.<br />
*/</p>
<p dir="auto">#include &lt;SPI.h&gt;<br />
#include &lt;MySensors.h&gt;<br />
#include &lt;DallasTemperature.h&gt;<br />
#include &lt;OneWire.h&gt;<br />
#include "Vcc.h"        // <a href="https://github.com/Yveaux/Arduino_Vcc" rel="nofollow ugc">https://github.com/Yveaux/Arduino_Vcc</a></p>
<p dir="auto">static const float VccMin = 0.0;        // Minimum expected Vcc level, in Volts. (0.6V for 1 AA Alkaline)<br />
static const float VccMax = 3.3;        // Maximum expected Vcc level, in Volts. (1.5V for 1 AA Alkaline)<br />
static const float VccCorrection = 3.29 / 3.31;  // Measured Vcc by multimeter divided by reported Vcc<br />
Vcc vcc(VccCorrection);</p>
<p dir="auto">#define CHILD_ID_PH 0<br />
#define ArrayLenth 10               // times of collection<br />
#define PH_SENSOR_ANALOG_PIN A0         // pH meter Analog output to Arduino Analog Input 0<br />
#define LED_DIGITAL_PIN 13<br />
#define Offset 0.00           //deviation compensate</p>
<p dir="auto">#define CHILD_ID_TEMP 1<br />
#define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No<br />
#define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected<br />
#define MAX_ATTACHED_DS18B20 16</p>
<p dir="auto">unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)<br />
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)<br />
DallasTemperature sensors(&amp;oneWire); // Pass the oneWire reference to Dallas Temperature.</p>
<p dir="auto">unsigned long lastSend = 0;<br />
static const unsigned long SEND_FREQUENCY = 30000;  // Minimum time between send (in milliseconds)</p>
<p dir="auto">MySensor gw;</p>
<p dir="auto">float lastPhHValue;<br />
static const float deltaPhValue = 0.5;</p>
<p dir="auto">float lastTemperature[MAX_ATTACHED_DS18B20];<br />
int numSensors=0;<br />
boolean receivedConfig = false;<br />
boolean metric = true;</p>
<p dir="auto">MyMessage msgPH(CHILD_ID_PH, V_VAR1);<br />
MyMessage msg(CHILD_ID_TEMP,V_TEMP);</p>
<p dir="auto">void setup()<br />
{<br />
// Startup up the OneWire library<br />
sensors.begin();<br />
// requestTemperatures() will not block current thread<br />
sensors.setWaitForConversion(false);</p>
<pre><code>//gw.begin(NULL, 100, false); //deze gebruiken, 100 is de node_id, die weer gebruiken in pimatic
gw.begin();
//Serial.print("0;0;3;0;2;");Serial.print(LIBRARY_VERSION);

pinMode(LED_DIGITAL_PIN, OUTPUT);
numSensors = sensors.getDeviceCount();

// Send the Sketch Version Information to the Gateway
gw.sendSketchInfo("pHmeter", "1.0");

// Register all sensors to gw (they will be created as child devices)
gw.present(CHILD_ID_PH, S_WATER_QUALITY);

// Present all sensors to controller
for (int i=0; i&lt;numSensors &amp;&amp; i&lt;MAX_ATTACHED_DS18B20; i++) {   
gw.present(i, S_TEMP);
}
</code></pre>
<p dir="auto">}</p>
<p dir="auto">void loop()<br />
{<br />
// By calling process() you route messages in the background<br />
gw.process();<br />
read_PH();<br />
read_TEMP();</p>
<pre><code>gw.sleep(SLEEP_TIME);
</code></pre>
<p dir="auto">}</p>
<p dir="auto">void read_PH(){<br />
unsigned long now = millis();<br />
bool sendTime = now - lastSend &gt; SEND_FREQUENCY;<br />
if (sendTime)<br />
{<br />
lastSend = now;</p>
<pre><code>    //    float v = vcc.Read_Volts();
    //    Serial.print("VCC = " );
    //    Serial.print(v);
    //    Serial.println(" Volts" );
    
    int batteryPcnt = (int)vcc.Read_Perc(VccMin, VccMax);
    //    Serial.print("VCC = " );
    //    Serial.print(batteryPcnt);
    //    Serial.println(" %" );
    
    gw.sendBatteryLevel(batteryPcnt);
}

// Read PH_SENSOR_ANALOG_PIN in phValue
float voltage = analogReadAverage(PH_SENSOR_ANALOG_PIN, 10) * 5.0 / 1024;

// convert the millivolt into pH value
float PhValue = 3.5 * voltage+Offset;




if (sendTime || abs(PhValue - lastPhHValue) &gt; deltaPhValue)
{
    Serial.print("    pH:");
    Serial.print(PhValue, 2);
    Serial.println(" ");
    
    gw.send(msgPH.set(PhValue, 2)); // envoi au reseau avec deux decimales
    
    digitalWrite(LED_DIGITAL_PIN, digitalRead(LED_DIGITAL_PIN) ^ 1);
    
    lastPhHValue = PhValue;
}
</code></pre>
<p dir="auto">}</p>
<p dir="auto">void read_TEMP(){<br />
sensors.requestTemperatures();</p>
<p dir="auto">// query conversion time and sleep until conversion completed<br />
int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());<br />
// sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)<br />
gw.sleep(conversionTime);</p>
<p dir="auto">// Read temperatures and send them to controller<br />
for (int i=0; i&lt;numSensors &amp;&amp; i&lt;MAX_ATTACHED_DS18B20; i++) {</p>
<pre><code>// Fetch and round temperature to one decimal
float temperature = static_cast&lt;float&gt;(static_cast&lt;int&gt;((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;

// Only send data if temperature has changed and no error
#if COMPARE_TEMP == 1
if (lastTemperature[i] != temperature &amp;&amp; temperature != -127.00 &amp;&amp; temperature != 85.00) {
#else
if (temperature != -127.00 &amp;&amp; temperature != 85.00) {
#endif

  // Send in the new temperature
  gw.send(msg.setSensor(i).set(temperature,1));
  // Save new temperatures for next compare
  lastTemperature[i]=temperature;
}
</code></pre>
<p dir="auto">}<br />
}</p>
<p dir="auto">double analogReadAverage(uint8_t pin, unsigned long ms)<br />
{<br />
double average = 0;<br />
int buffer[ArrayLenth];</p>
<pre><code>for (int i = 0; i &lt; ArrayLenth; i++)
{
    buffer[i] = analogRead(PH_SENSOR_ANALOG_PIN);
    delay(ms);
}

if (ArrayLenth &lt; 5)
{
    // less than 5, calculated directly statistics
    for (int i = 0; i &lt; ArrayLenth; i++)
    {
        average += buffer[i];
    }
    average = average / ArrayLenth;
}
else
{
    // Sort the values from small to large
    for (int i = 0; i &lt; ArrayLenth; i++)
    {
        for (int j = i + 1; j &lt; 10; j++)
        {
            if (buffer[i] &gt; buffer[j])
            {
                int temp = buffer[i];
                buffer[i] = buffer[j];
                buffer[j] = temp;
            }
        }
    }
    
    // take the average value of center sample
    for (int i = 2; i &lt; ArrayLenth - 2; i++)
    {
        average += buffer[i];
    }
    
    average = average / (ArrayLenth - 4);
}

return average;
</code></pre>
<p dir="auto">}</p>
<p dir="auto">In file included from C:\Users\Przemek\AppData\Local\Temp\arduino_modified_sketch_990915\sketch_apr20a.ino:8:0:</p>
<p dir="auto">C:\Users\Przemek\Documents\Arduino\libraries\MySensors/MySensors.h:389:2: error: #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.</p>
<p dir="auto">#error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.</p>
<p dir="auto">^</p>
<p dir="auto">exit status 1</p>
]]></description><link>https://forum.mysensors.org/topic/9281/mysensors-ph</link><generator>RSS for Node</generator><lastBuildDate>Wed, 11 Nov 2026 10:37:25 GMT</lastBuildDate><atom:link href="https://forum.mysensors.org/topic/9281.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 20 Apr 2018 17:06:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Mysensors PH on Sun, 29 Apr 2018 14:07:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/szybki946" aria-label="Profile: szybki946">@<bdi>szybki946</bdi></a> said in <a href="/post/88979">Mysensors PH</a>:</p>
<blockquote>
<p dir="auto">how to fix this error</p>
</blockquote>
<p dir="auto">Effectively you are asking somebody to complete this project for you - this is not just one simple correction. There were a few PH prob projects in the past (just use search), but you have to be careful and maybe need to convert the code from 1.5 to 2.xx. This is not difficult and there is a sticky post how to do that.</p>
<p dir="auto"><a href="https://forum.mysensors.org/topic/3101/ph-probe-code">https://forum.mysensors.org/topic/3101/ph-probe-code</a></p>
]]></description><link>https://forum.mysensors.org/post/89297</link><guid isPermaLink="true">https://forum.mysensors.org/post/89297</guid><dc:creator><![CDATA[alexsh1]]></dc:creator><pubDate>Sun, 29 Apr 2018 14:07:14 GMT</pubDate></item><item><title><![CDATA[Reply to Mysensors PH on Fri, 20 Apr 2018 19:35:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/szybki946" aria-label="Profile: szybki946">@<bdi>szybki946</bdi></a> start by reading the <a href="https://www.mysensors.org/about" rel="nofollow ugc">getting started guide</a>. By doing that you'll get an introduction to MySensors and how everything fits together. It will save you a lot of time.</p>
]]></description><link>https://forum.mysensors.org/post/88987</link><guid isPermaLink="true">https://forum.mysensors.org/post/88987</guid><dc:creator><![CDATA[mfalkvidd]]></dc:creator><pubDate>Fri, 20 Apr 2018 19:35:05 GMT</pubDate></item><item><title><![CDATA[Reply to Mysensors PH on Fri, 20 Apr 2018 18:00:43 GMT]]></title><description><![CDATA[<p dir="auto">how to fix this error</p>
]]></description><link>https://forum.mysensors.org/post/88979</link><guid isPermaLink="true">https://forum.mysensors.org/post/88979</guid><dc:creator><![CDATA[szybki946]]></dc:creator><pubDate>Fri, 20 Apr 2018 18:00:43 GMT</pubDate></item><item><title><![CDATA[Reply to Mysensors PH on Fri, 20 Apr 2018 17:39:53 GMT]]></title><description><![CDATA[<p dir="auto">You didn't define any radio interface, of course it fails the compile. That is also an old code for old mysensors library.</p>
]]></description><link>https://forum.mysensors.org/post/88978</link><guid isPermaLink="true">https://forum.mysensors.org/post/88978</guid><dc:creator><![CDATA[gohan]]></dc:creator><pubDate>Fri, 20 Apr 2018 17:39:53 GMT</pubDate></item></channel></rss>