Strings Showing null in HTMLtile


Hi everyone. Im new to programing, after installing several Smartapps and Device Handlers I became curious about the whole process and began reading about JAVA, HTML, Groovy, etc. I’ve learned a lot in the last 5 months but am still no where near the skill level that most of you have here.

I’m attempting to make a Smartapp and Device Handler to connect my 3D printer to Smartthings. The main purpose for this project is to allow me an avenue to get my hands dirty with coding. I’ve been able to create the smartapp and device handler already, which allow me to send commands and monitor the temperatures and status of the printers extruder and heated bed. The final ability I would like for my device handler to do is to be able to display the content of the microSD card in the printer and to request to have a print started when clicking the name of the file. To accomplish this I am using the Smartthings HTMLtile.

So far I’ve been able to query my printer for the content of the microSD card. I then convert that information to a string that I pass from the 3Dprinter to the Smartapp and then to the Device Handler. I then use the ‘log.debug’ tool to verify the value of the string is being received in the Device handler. So far everything is working just fine. However, when I create the HTMLtile content to display the string the string is always showing as “null.”

The interesting thing is, I can locally give the same string a value, like “test value” and refresh the tile and everything works out fine. It’s only when I try to give the string the value that is being passed by the Smartapp that the string losses its content. I have noticed in the Live logs that when a HTMLtile represhes the string values go null for 2 seconds. This I believe is where I’m getting my problem. I need to find a way to store the string value somewhere else and then call on it when the HTMLtile is loading, or I’m guessing that would be the fix I need. But like I said I am only 5 months into learing this stuff and have a long way to go. If anyone can help point me in the right direction I would appreciate it. A big THANK YOU in advance for all you guys do. I’m sure I have studied many of your codes the last couple of months to help with my learning :).


code to fill HTMLtile (jpeg file, since I cant figure out how to post HTML code on the forum :smile:)

code to fill HTMLtile:

def getSDCardHTML(String List) {

 //List = "test string"
log.debug List  
try {
   def SDfiles = List != null ? List : "nope text"
   log.debug SDfiles
   def html = """
   <!DOCTYPE html>
           <meta http-equiv="refresh" content="8">
  		<meta http-equiv="cache-control" content="max-age=0"/>
  		<meta http-equiv="cache-control" content="no-cache"/>
  		<meta http-equiv="expires" content="0"/>
  		<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT"/>
  		<meta http-equiv="pragma" content="no-cache"/>
  		<meta name="viewport" content="width = device-width, user-scalable=no, initial-scale=1.0">      
  		  <col width="100%">
  			<th>SD Card Files</th>
                 <div id="div1">${List}</div>
                 <br><a href=""></a>
  render contentType: "text/html", data: html, status: 200

} catch (ex) {
log.error “SDCardHTML Exception:”, ex
exceptionDataHandler(ex.message, “SDCardHTML”)


I ended up solving my problem by storing the value by using the “state” data storage feature and then inserting it into the htmlTile.