Any Documentation on "physicalgraph device HubAction"?

your path in your hubaction isn’t defined, its just sending “GET path HTTP/1.1”

1 Like

Updated:

def headers = [:] 
headers.put("HOST", "$ip:$port")
log.debug "The Header is $headers"

def method = "GET"

try {
    def hubAction = new physicalgraph.device.HubAction(
        method: method,
        path: "/",
        headers: headers,
        device.deviceNetworkId
        )
    log.debug hubAction
	hubAction
}
catch(Exception ex) {
	log.debug "Hit Exception $e on $hubAction"
}

I also tried replacing hubAction at the end of the try block with sendHubCommand(hubAction) but it made no difference. Would the issue have anything to do with UPNP?

UPNP is something completely different. What are you trying to do?

Just get the body of the html and parse through it. I have read the method used depends on if you are building a device handler or a smartapp. In my case I am trying to build a device handler, I also read that in some case you use mac address and some ip and in some ip:port in hex. I have been playing with all of these but with no luck so I was looking at UPNP but this was just me grasping at straws to figure out why the parse function never fires.

def parse(String description) {
log.debug "Parsing '${description}'"

def msg = parseLanMessage(description)
    log.debug msg
}

Also not sure if it matters but I have only tried this in the simulator.

Thanks

I tried running the hub action which was printed out in the logs in putty

so I ran
"GET / HTTP/1.1
Accept: /
User-Agent: Linux UPnP/1.0 SmartThings
HOST: 192.168.1.7:80"

and got the following so I know the GET is working. Pasting html in here doesn’t work so just pasting the non html

HTTP/1.1 200 OK
Content-Type: text/html

ESP8266 Temperature Sensor

Temp F: 80.82
Temp C: 27.12

any other ideas?

so you are getting a response? What’s the issue?

No response the parse function is never triggered. I am only getting the response in putty or the browser.

I just cane across this so I will try it and see what happens.

Just an update to let you know I got it to work with the fork of the SmartThing library I linked above

Hi can you share the code, and how you got it to work ? please

Hi sorry my code isn’t very clean but hear it is. I must say I ended up scrapping the project and haven’t had time to go back to it due to the fact that it was draining an entire 9v battery overnight.

The device Handler:

metadata {
definition (name: "ESP8266 Thermometer2", namespace: "uali8020", author: "Umar Ali") {
	capability "Actuator"
capability "Temperature Measurement"
    capability "Sensor"
    
    command "getTemp"
    command "configure"
}


simulator {
	// TODO: define status and reply messages here
}

// Preferences
preferences {
	input("ip", "string", title: "IP Address", description: "ip", required: true, displayDuringSetup: true)
	input("port", "text", title: "Arduino Port", description: "port", required: true, displayDuringSetup: true)
	input("mac", "text", title: "Arduino MAC Addr", description: "mac", required: true, displayDuringSetup: true)
}

tiles {
	// TODO: define your main and details tiles here
        valueTile("temperature", "device.temperature", width: 3, height: 3) {
    state("temperature", label:'${currentValue}°',
			backgroundColors:[
				[value: 31, color: "#153591"],
				[value: 44, color: "#1e9cbb"],
				[value: 59, color: "#90d2a7"],
				[value: 74, color: "#44b621"],
				[value: 84, color: "#f1d801"],
				[value: 95, color: "#d04e00"],
				[value: 96, color: "#bc2323"]
			]
		)
	}
    standardTile("getTemp", "device.getTemp", inactiveLabel: false, decoration: "flat", width: 3, height: 1) {
		state "default", label:'Get Temp', action:"getTemp", icon: "st.Office.office10"
	}
    standardTile("configure", "device.configure", inactiveLabel: false, decoration: "flat", width: 3, height: 1) {
		state "configure", label:'', action:"configuration.configure", icon:"st.secondary.configure"
	}
    
    main(["temperature"])
	details(["temperature", 
            "getTemp",
            "configure"])
    }
}

// parse events into attributes
def parse(String description) {
log.debug "Parsing '${description}'"
// TODO: handle 'temperature' attribute

    def msg = parseLanMessage(description)

    def headerString = msg.header

if (!headerString) {
	//log.debug "headerstring was null for some reason :("
}

def bodyString = msg.body

if (bodyString) {
    //log.debug "BodyString: $bodyString"
    def value = bodyString
	def result = createEvent(name: "temperature", value: value, unit: "F")
    log.debug "Parse returned ${result?.descriptionText}"
    return result
}


}

private getHostAddress() {
    def ip = settings.ip
    def port = settings.port

log.debug "Using ip: ${ip} and port: ${port} for device: ${device.id}"
    return ip + ":" + port
}

def sendEthernet(message) {
log.debug "Executing 'sendEthernet' ${message}"
new physicalgraph.device.HubAction(
	       method: "POST",
	       path: "/${message}?",
	       headers: [ HOST: "${getHostAddress()}" ]
     )
}

def configure() {
log.debug "Executing 'configure'"
    if(device.deviceNetworkId!=settings.mac) {
	     log.debug "setting device network id"
	    device.deviceNetworkId = settings.mac
    }
}

def getTemp() {
    sendEthernet("tempF")
}

ESP 8266 Code:

#include <SmartThingsESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>

SmartThingsCallout_t messageCallout;    // call out function forward decalaration

String ssid = "RouterSSIDHere";//type your ssid
String password = "xxxxxxxxx";//type your router passkey
IPAddress ip(192, 168, xxx, xxx);       // Device IP Address      //  <---You must edit this line!
IPAddress gateway(192, 168, xxx, xxx);    //router gateway          //  <---You must edit this line!
IPAddress subnet(255, 255, 255, 0);   //LAN subnet mask         //  <---You must edit this line!
IPAddress dnsserver(192, 168, xxx, xxx);  //DNS server              //  <---You must edit this line!
const unsigned int serverPort = 8090; // port to run the http server on

// Smartthings Hub Information
IPAddress hubIp(192, 168, xxx, xxx);    // smartthings hub ip     //  <---You must edit this line!
const unsigned int hubPort = 39500;   // smartthings hub port


// ************** ONE WIRE Ds1820
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

float temp;
float tempC;
float tempF;

//Create a SmartThings Ethernet ESP8266WiFi object
st::SmartThingsESP8266WiFi smartthing(ssid, password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, messageCallout);

bool isDebugEnabled;    // enable or disable debug in this example



void setupDS18B20() {
	sensors.begin();
}

void readDS18B20() {
	Serial.println("********** DS18B20 **********");
	sensors.requestTemperatures(); // Send the command to get temperatures
	tempC = sensors.getTempCByIndex(0);
	Serial.print("Temp C: ");
	Serial.println(tempC);
	tempF = ((tempC * 9.0) / 5.0) + 32;
	Serial.print("Temp F: ");
	Serial.println(tempF);
}


void setup() {
	// setup default state of global variables
	isDebugEnabled = true;

	if (isDebugEnabled)
	{ // setup debug serial port
		Serial.begin(9600);         // setup serial with a baud rate of 9600
		Serial.println("");
		Serial.println("setup..");  // print out 'setup..' on start
	}

	//Run the SmartThings init() routine to make sure the ThingShield is connected to the ST Hub
	smartthing.init();

	//init DS1820
	setupDS18B20();

	//synch up the ST cloud
	smartthing.send("no temp");       // send message to cloud

}

void loop() {
	smartthing.run();
}

void messageCallout(String message)
{
	// if debug is enabled print out the received message
	if (isDebugEnabled)
	{
		Serial.print("Received message: '");
		Serial.print(message);
		Serial.println("' ");
	}

	readDS18B20();

	if (message.equals("tempF"))
	{
		smartthing.send((String)tempF);
	}
	else if (message.equals("tempC"))
	{
		smartthing.send((String)tempC);
	}
}

Hopefully this helps. For the ESP8266 be sure to include the right libraries found here https://github.com/DanielOgorchock/ST_Anything/tree/master/Arduino/libraries/SmartThings