Skip to main content
1-Visitor
October 26, 2016
Solved

Thing is not running

  • October 26, 2016
  • 9 replies
  • 5909 views

Hi,

So, I have a service which allow me to create a Thing based on a sshServerTemplate (from the ssh extension of the marketplace). When I call it it creates the thing and configure it (user/pass, url, port, ...) and it works perfectly.

I need to do the same thing with the sftp extension (also available on the marketplace) so I duplicated my service and changed some values in order to manage this. But when I execute the service it throws me an error : "Thing [<thingName>] is not running" ...

I tried to remove all the configuration part to just keep the creatething part and it works, the thing is created. But if i try to set Tags, project or even properties it throws me the error.

Below the code of my service (I know it is quite ugly) (the createThings service is an homemade service and the enableThing is called in this service) :

// Create sftp gateway

var thingName = gatewayName + "Sftp";

var params = {

  Description: undefined /* STRING */,

  ThingName: thingName /* STRING */,

  ThingTemplate: "SftpGatewayTemplate" /* STRING */,

  Tag: undefined /* STRING */

};

me.CreateThings(params);

Things[thingName].RestartThing();

var params = {

  tags: [{

      vocabulary: "Smart Building",

      vocabularyTerm: tagTerm

    }] /* TAGS */

};

Things[thingName].SetTags(params);

Things[thingName].RestartThing();

var params = {

  projectName: tagTerm /* PROJECTNAME */

};

Things[thingName].SetProjectName(params);

Things[thingName].RestartThing();

var params1 = {

  defaultValue: gatewayUrl /* STRING */,

  description: undefined /* STRING */,

  readOnly: undefined /* BOOLEAN */,

  type: "STRING" /* BASETYPENAME */,

  remote: undefined /* BOOLEAN */,

  remotePropertyName: undefined /* STRING */,

  timeout: undefined /* INTEGER */,

  pushType: undefined /* STRING */,

  dataChangeThreshold: undefined /* NUMBER */,

  logged: undefined /* BOOLEAN */,

  name: "URL" /* STRING */,

  pushThreshold: undefined /* NUMBER */,

  dataChangeType: undefined /* STRING */,

  category: undefined /* STRING */,

  persistent: true /* BOOLEAN */,

  dataShape: undefined /* DATASHAPENAME */

};

Things[thingName].AddPropertyDefinition(params1);

Things[thingName].RestartThing();

var params1 = {

  defaultValue: gatewayLoc /* STRING */,

  description: undefined /* STRING */,

  readOnly: undefined /* BOOLEAN */,

  type: "STRING" /* BASETYPENAME */,

  remote: undefined /* BOOLEAN */,

  remotePropertyName: undefined /* STRING */,

  timeout: undefined /* INTEGER */,

  pushType: undefined /* STRING */,

  dataChangeThreshold: undefined /* NUMBER */,

  logged: undefined /* BOOLEAN */,

  name: "Localisation" /* STRING */,

  pushThreshold: undefined /* NUMBER */,

  dataChangeType: undefined /* STRING */,

  category: undefined /* STRING */,

  persistent: true /* BOOLEAN */,

  dataShape: undefined /* DATASHAPENAME */

};

Things[thingName].AddPropertyDefinition(params1);

Things[thingName].RestartThing();

Things[thingName].EnableThing();

Things[thingName].RestartThing();

var params = {

  infoTableName : "InfoTable",

  dataShapeName : "SshConf"

};

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(SshConf)

var infTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

var params = {

  data: password /* STRING */

};

// result: STRING

var pass = Resources["EncryptionServices"].EncryptPropertyValue(params);

// SshConf entry object

var newEntry = new Object();

newEntry.password = pass; // PASSWORD

newEntry.keepAliveTimeout = keepTimeout; // NUMBER

newEntry.port = port; // NUMBER

newEntry.host = gatewayUrl; // STRING - isPrimaryKey = true

newEntry.connectionTimeout = conTimeout; // NUMBER

newEntry.username = user; // STRING

infTable.AddRow(newEntry);

var params = {

    configurationTable: infTable /* INFOTABLE */,

    persistent: true /* BOOLEAN */,

    tableName: "ConnectionInfo" /* STRING */

};

Things[thingName].SetConfigurationTable(params);

Things[thingName].SaveConfigurationTables();

Things[thingName].RestartThing();

Thanks for your help

Best answer by CarlesColl

Some options:

  1. Create a dummy FTP Configuration that always works ( yourdomain, fakeUser, fakePassord --> No rights )
  2. Decompible the extension ( that's not hard if you get to know java ) and tweak it
  3. Open a support case, and nice people from Support they may improve the extension for you, they did for me in the past, who developed SFTP extension it's Europa based

9 replies

1-Visitor
October 26, 2016

Hi,

I think that SFTP Thing tries to connect when it starts, and it may take too much... Then maybe when it's connecting the Thing it's not fully enabled. Just a guess.

Carles.

jdurand1-VisitorAuthor
1-Visitor
October 26, 2016

Hi,

I tried to prove your guess and it looks like it is not the problem.

I will try further in that way but if you have another idea feel free to share it with me !

Thanks

1-Visitor
October 26, 2016

Put a flag to mark if it's configured or not, and then with a timer try to configure it until it's.

22-Sapphire I
October 26, 2016

You can also create an extended template that has a Subscription to ThingStart which kicks off the configuration

1-Visitor
October 26, 2016

Hi Pai,

I think ThingStart will be thrown before the Thing it's correctly initialized, but he can give it a shot i conjunction with Configured Thing flag.

Carles.