<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to connect TMP36 Analog Temperature Sensor with ThingWorx. in ThingWorx Developers</title>
    <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/How-to-connect-TMP36-Analog-Temperature-Sensor-with-ThingWorx/m-p/537052#M26283</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.ptcusercommunity.com/t5/user/viewprofilepage/user-id/283788"&gt;@smishra-31&lt;/a&gt;&amp;nbsp;could you have both EMS and Lua config files enabled with Trace logging&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;EMS logging:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;"logger": {
"level": "TRACE"
},&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;LSR logging setting :&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;scripts.log_level = "INFO"&lt;/PRE&gt;
&lt;P&gt;What's also interesting is that your py scripts are returning float as datatype for the values while the ThingWorx and lua are attempting to work with Number base type. Have you already tried debugging the python script for possible mismatch of datatypes?&lt;/P&gt;</description>
    <pubDate>Mon, 26 Feb 2018 14:35:08 GMT</pubDate>
    <dc:creator>supandey</dc:creator>
    <dc:date>2018-02-26T14:35:08Z</dc:date>
    <item>
      <title>How to connect TMP36 Analog Temperature Sensor with ThingWorx.</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/How-to-connect-TMP36-Analog-Temperature-Sensor-with-ThingWorx/m-p/517765#M13555</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Today I was going through one of the QuickStart Guides: &lt;A title="https://developer.thingworx.com/resources/guides/thingworx-raspberry-pi-quickstart/connect-temperature-sensor" href="https://developer.thingworx.com/resources/guides/thingworx-raspberry-pi-quickstart/connect-temperature-sensor" target="_blank"&gt;https://developer.thingworx.com/resources/guides/thingworx-raspberry-pi-quickstart/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Where ThingWorx team has used &lt;SPAN style="color: #333333; font-family: texgyreadventorregular; font-size: 14px;"&gt;&lt;STRONG&gt;Adafruit DHT11&lt;/STRONG&gt;​ &lt;STRONG&gt;Temperature Sensor&lt;/STRONG&gt; to connect it to Raspberry Pi.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="color: #333333; font-family: texgyreadventorregular; font-size: 14px;"&gt;But in place of that I have &lt;STRONG&gt;​TMP36 Analog Temperature Sensor&lt;/STRONG&gt;​ and &lt;STRONG&gt;Arduino Uno&lt;/STRONG&gt;. As Raspberry Pi cannot read/convert analog values into digital values, I have attached the sensor to Arduino and than connect it to Raspberry Pi.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="color: #333333; font-family: texgyreadventorregular; font-size: 14px;"&gt;In Arduino I have used this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;const int temperaturePin = 0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;void setup()&lt;/P&gt;
&lt;P&gt;{&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Serial.begin(9600);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;void loop()&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; float voltage, degreesC;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; voltage = getVoltage(temperaturePin);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; degreesC = (voltage - 0.5) * 100.0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Serial.print("Temp=");&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Serial.println(degreesC);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; delay(1000);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;float getVoltage(int pin)&lt;/P&gt;
&lt;P&gt;{&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; return (analogRead(pin) * 0.004882814);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Python Script that I have place in &lt;STRONG&gt;/microserver/ArduinoTempSensor/ArduinoTempSensor.py&lt;/STRONG&gt; is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#!/usr/bin/python&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;import serial&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;import time&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;ser = serial.Serial('/dev/ttyACM0', 9600, 8, 'N', 1, timeout=5)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;while True:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ser.inWaiting &amp;gt; 0:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(ser.readline())&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and in &lt;STRONG&gt;PiTemplate.lua file&lt;/STRONG&gt;, I have added these lines as mentioned:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: inherit; color: inherit;"&gt;1) properties.temp = { baseType="NUMBER", pushType="ALWAYS", value=0 }&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: inherit; color: inherit;"&gt;2) local sensorCmd = io.popen("./ArduinoTempSensor/ArduinoTempSensor.py")&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: inherit; color: inherit;"&gt;&lt;CODE style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: inherit; color: inherit;"&gt;3)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -- set property temp&lt;BR /&gt;local sensor = sensorCmd:read("*a")&lt;BR /&gt;log.debug("[PiTemplate]",string.format("raw sensor %s", sensor))&lt;BR /&gt;s = string.match(sensor,"Temp=(%d+\.%d+)");&lt;BR /&gt;log.debug("[PiTemplate]",string.format("scaled temp %.1f", s))&lt;BR /&gt;properties.temp.value = s&lt;/CODE&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This far I have gone but results are not so good. The values got&amp;nbsp; updated but only once, after that it is not getting refreshed or new values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: inherit; color: inherit;"&gt;&lt;CODE style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: inherit; color: inherit;"&gt;&lt;/CODE&gt;&lt;/CODE&gt;&lt;IMG style="height: 374px; width: 1074.28px;" class="image-1 jive-image" src="https://www.ptcusercommunity.com/legacyfs/online/thingworx/8856_PiThing.PNG" alt="PiThing.PNG" width="1074" height="374" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Errors that I am getting while running EMS is:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;IMG style="height: 267px; width: 1081.96px;" class="image-2 jive-image" src="/legacyfs/online/thingworx/8858_EMS Error.PNG" alt="EMS Error.PNG" width="1082" height="267" border="0" /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;While running Lua Script:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;IMG style="height: 569px; width: 1040.65px;" class="image-3 jive-image" src="/legacyfs/online/thingworx/8859_Lua Script.PNG" alt="Lua Script.PNG" width="1041" height="569" border="0" /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Regards,&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Shashank&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 19:24:25 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/How-to-connect-TMP36-Analog-Temperature-Sensor-with-ThingWorx/m-p/517765#M13555</guid>
      <dc:creator>smishra-31</dc:creator>
      <dc:date>2018-11-27T19:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to connect TMP36 Analog Temperature Sensor with ThingWorx.</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/How-to-connect-TMP36-Analog-Temperature-Sensor-with-ThingWorx/m-p/537052#M26283</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.ptcusercommunity.com/t5/user/viewprofilepage/user-id/283788"&gt;@smishra-31&lt;/a&gt;&amp;nbsp;could you have both EMS and Lua config files enabled with Trace logging&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;EMS logging:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;"logger": {
"level": "TRACE"
},&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;LSR logging setting :&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;scripts.log_level = "INFO"&lt;/PRE&gt;
&lt;P&gt;What's also interesting is that your py scripts are returning float as datatype for the values while the ThingWorx and lua are attempting to work with Number base type. Have you already tried debugging the python script for possible mismatch of datatypes?&lt;/P&gt;</description>
      <pubDate>Mon, 26 Feb 2018 14:35:08 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/How-to-connect-TMP36-Analog-Temperature-Sensor-with-ThingWorx/m-p/537052#M26283</guid>
      <dc:creator>supandey</dc:creator>
      <dc:date>2018-02-26T14:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to connect TMP36 Analog Temperature Sensor with ThingWorx.</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/How-to-connect-TMP36-Analog-Temperature-Sensor-with-ThingWorx/m-p/537053#M26284</link>
      <description>BTW, which python version are you working with?</description>
      <pubDate>Mon, 26 Feb 2018 14:38:38 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/How-to-connect-TMP36-Analog-Temperature-Sensor-with-ThingWorx/m-p/537053#M26284</guid>
      <dc:creator>supandey</dc:creator>
      <dc:date>2018-02-26T14:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to connect TMP36 Analog Temperature Sensor with ThingWorx.</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/How-to-connect-TMP36-Analog-Temperature-Sensor-with-ThingWorx/m-p/539584#M26649</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.ptcusercommunity.com/t5/user/viewprofilepage/user-id/133161"&gt;@supandey&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apologies for late reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using Python 2.4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have completely changed my old python script. Instead of initiating a infinite loop in script ( while True: ), I am returning only the 5th Value ( retries=5 ). I have used regular expression also to check the correct format.&lt;/P&gt;
&lt;P&gt;So it is working fine now.&lt;/P&gt;
&lt;PRE&gt;#!/usr/bin/python

import sys
import serial
import time
import re

ser = serial.Serial('/dev/ttyACM0', 9600, 8, 'N', 1, timeout=5)
r = re.compile("\d{2}.\d{2}")

def read_retry(retries=5):
    temperature = None
    for i in range(retries):
        temp = ser.readline()
        if i == retries-1:
            if r.match(temp) is not None:
                temperature = float(temp)
            else:
                temperature = None
    return temperature

SensorTemp = read_retry()

if SensorTemp is not None:
    print('Temp={0:0.2f}'.format(SensorTemp))
else:
    print('Failed to get reading. Try again!')
    sys.exit(1)
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; Regards,&lt;/P&gt;
&lt;P&gt;Shashank&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2018 09:17:00 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/How-to-connect-TMP36-Analog-Temperature-Sensor-with-ThingWorx/m-p/539584#M26649</guid>
      <dc:creator>smishra-31</dc:creator>
      <dc:date>2018-03-12T09:17:00Z</dc:date>
    </item>
  </channel>
</rss>

