Faulty import statements in Golang

Hi,

when you insert a “Run script” node in a Thingsplex flow, it contains an example code. The header of this code contains several import commands that links to the Futurehome code repo on Github. 2 of these import commands lead to 404 pages:

import “github.com/thingsplex/tpflow/model
import “github.com/thingsplex/tpflow/node/action/exec

Does anybody know the correct links?
THANKS!

1 Like

Hi again,

here comes another potential hint for educated readers. When I try to save the flow containing the Golang script node, I get the following error message in the log:

Node type exec can’t be loaded: 4:8: import “github.com/thingsplex/tpflow/model” error: unable to find source related to: “github.com/thingsplex/tpflow/model”. Either the GOPATH environment variable, or the Interpreter.Options.GoPath needs to be set

Does that help anyone to detect the root of the problem?

Thanks!

Hi again,

I’m growing more and more certain that this issue is caused by the environment variable not being set correctly in the Futurehome system. This means no GO scripts would work at all in Thingsplex, which I would consider a major issue. @futurehome, could you please have a look and verify?

I’m asking because I actually want to solve this issue:

and I do need this GO script node to get it done.

THANKS!

Golang node might not be supported by flow engine that is supplied with Futurehome smarthub. It’s supported in open source version of tpflow engine but it has to be run outside of the hub .

That would mean that more sophisticated automations than simple flows are impossible! This would be a showstopper for any advanced use of the hub. Any chance of fixing this? Any other option for using script language on Futurehome?

That is correct , unless FH agrees to accept 3rd party apps to Playground app store . In theory the process is in place but in practice nothing gets through. The open tpflow engine supports golang scripting , python and lua .

@alivinco ,

thanks for the update!

As an alternative to my approach, would you know how to read and set the elements of an array, which is a global variable in the Futurehome hub, from a Thingsplex flow?

Thanks!

1 Like

It might be possible for in-memory variables , I’ll test and report here

Yes,

Just change the thingsplex to futurehomeno in the import paths.

And I wouldn’t go back to open source version even if it’s possible, as it’s really buggy.

1 Like

@Rafal I just updated tpflow to the latest version from futurehome and it can’t reliably load flows in ThingsplexUI . Log inspection shows that the engine reloads all flow periodically due to some crash or something else. Now I’m reverting back to open source version. Maybe there are some bugs but at least it was quite stable and working fine.

1 Like

@Rafal ,

thanks for the input! I tried as you suggested, but I still get this error message:

Node type exec can’t be loaded: 5:8: import “github.com/futurehomeno/tpflow/node/action/exec” error: unable to find source related to: “github.com/futurehomeno/tpflow/node/action/exec”. Either the GOPATH environment variable, or the Interpreter.Options.GoPath needs to be set

Any idea?

Thanks!

@Spielkind Hey, we’re still waiting for the UI to be updated. But in your case, change the exec node import path to:
github.com/futurehomeno/tpflow/internal/node/action

@alivinco Can you share the error you found so we could improve on that too? Maybe there’re some edge cases that we didn’t cover.

@Rafal ,

thanks for your continued input. Probably I have thick thumbs. For the exec node, I tried:

Node type exec can’t be loaded: 5:8: import “github.com/futurehomeno/tpflow/internal/node/action” error: unable to find source related to: “github.com/futurehomeno/tpflow/internal/node/action”. Either the GOPATH environment variable, or the Interpreter.Options.GoPath needs to be set

and

Node type exec can’t be loaded: 5:8: import “github.com/futurehomeno/tpflow/internal/node/action/exec” error: unable to find source related to: “github.com/futurehomeno/tpflow/internal/node/action/exec”. Either the GOPATH environment variable, or the Interpreter.Options.GoPath needs to be set

but still error messages. Help!

Also getting the same error messages. Would really like to see a working example of go code. That would be really helpful.

Because the path of tpflow changed, also import paths needs to be fixes as follows:

package ext

import (
	"fmt"

	"github.com/futurehomeno/fimpgo"

	"github.com/futurehomeno/tpflow/context"
	"github.com/futurehomeno/tpflow/model"
)

var counter int = 1

type AppLogic struct {
	mqtt *fimpgo.MqttTransport
	ctx  context.Storage
}

func (al *AppLogic) sendMessage(msg string) {
	fimpMsg := fimpgo.NewMessage("evt.script.test", "test", "string", msg, nil, nil, nil)
	al.mqtt.PublishToTopic("pt:j1/mt:evt/rt:app/rn:testapp/ad:1", fimpMsg)

}
func (al *AppLogic) CheckHomeMode() {
	hModeVal, err := al.ctx.GetVariable("fh.home.mode", "global")
	if err != nil {
		return
	}
	hMode, ok := hModeVal.Value.(string)
	if !ok {
		return
	}

	if hMode == "home" {
		al.sendMessage("home is set to home mode")
	}
}

func Run(msg *model.Message, ctx context.Storage, params model.ScriptParams) string {
	appL := AppLogic{mqtt: params.Mqtt, ctx: ctx}
	appL.CheckHomeMode()

	counter++
	r := fmt.Sprintf("Hello %d", counter)
	ctx.SetVariable("hello_var", "string", r, "", params.FlowId, true)

	return "ok"
}

2 Likes

This seems to work, so that is a huge step forward. But it is very difficult to find documentation of how to use the go implementation in Futurehome. For example I am not able to use SetVariable as in your example. Nothing happens in the Context part of the Flows page.

Could you please include some info of how to find documentation and possibly update the SetVariable? For info, GetVariable is able to get the home mode in the example, so something is definitely working.

Unfortunately there is not yet any documentation that touches exec node and how to use go code. This is something that will come up later on. But regarding your issue - I just copy&pasted the code to my flow, and it did saved the variable (as flow variable). But to see it, switch from local to global variables and back. As the refresh button does not work every time.

Thanks - I see it now. So now the question is how to save a global variable… ?

For global just use "global" as the flow name (which is 5th parameter). So just change the params.FlowId to "global"