cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Unable to connect remote thing (Intel Galileo Gen 2) to thingworx

rshukla-2
7-Bedrock

Unable to connect remote thing (Intel Galileo Gen 2) to thingworx

I'm trying to connect my Intel Galileo Gen 2 board to thingworkx. I'm following the tutorial  Weather Application with Intel Galileo | ThingWorx  . In the example, they have used the HTU21D sensor . As it wasn't available where I live, I'm performing the tutorial  using  a BMP180 sensor. I'm using it to sense temperature and pressure.

I have modified the code given for HTU21D , as follow for BMP180:

  1. include <twApi.h> 
  2. #include <twLogger.h> 
  3. #include <twOSPort.h> 
  4. #include <SFE_BMP180.h> 
  5. #include <Ethernet.h> 
  6. #include <stdio.h> 
  7. #include <string.h> 
  8. #include <Wire.h> 
  9.  
  10. SFE_BMP180 tp; 
  11. /* Mac address of the network adapter */ 
  12. byte mac[] = {0x98, 0x4F, 0xEE, 0x01, 0xCB, 0xE9  }; 
  13.  
  14.  
  15. /* Name of your thing */ 
  16. char * thingName = "myTestTempPress"
  17. /* IP/hostname of your TWX server */ 
  18. char * serverName = "mitpune66.cloud.thingworx.com"
  19. /* port */ 
  20. int port = 443
  21. /* API key */ 
  22. char * apiKey = "d9c81d35-5a28-49b0-9ddf-e9193eda3b66"
  23. /* refresh rate */ 
  24. int timeBetweenRefresh = 1000
  25.  
  26.  
  27. /* Hold all the properties */ 
  28. struct  { 
  29.   double Temperature; 
  30.   double Pressure; 
  31. properties; 
  32.  
  33.  
  34. void sendPropertyUpdate() { 
  35.   /* Create the property list */ 
  36. propertyList * proplist = twApi_CreatePropertyList("Temperature",twPrimitive_CreateFromNumber(properties.Temperature), 0); 
  37.   if (!proplist) { 
  38.   TW_LOG(TW_ERROR,"sendPropertyUpdate: Error allocating property list"); 
  39.   return
  40.   } 
  41.   twApi_AddPropertyToList(proplist,"Pressure",twPrimitive_CreateFromNumber(properties.Pressure), 0); 
  42.   twApi_PushProperties(TW_THING, thingName, proplist, -1, FALSE); 
  43.   twApi_DeletePropertyList(proplist); 
  44.  
  45.  
  46. void dataCollectionTask() 
  47.   char status; 
  48.   status = tp.startTemperature(); 
  49.   status = tp.getTemperature(properties.Temperature); 
  50.   status = tp.startPressure(3); 
  51.   status = tp.getPressure(properties.Pressure, properties.Temperature); 
  52.   Serial.print("Time:"); 
  53.   Serial.print(millis()); 
  54.   Serial.print(" Temperature:"); 
  55.   Serial.print(properties.Temperature, 1); 
  56.   Serial.print("C"); 
  57.   Serial.print(" Pressure:"); 
  58.   Serial.print(properties.Pressure, 1); 
  59.   Serial.print("mb"); 
  60.   Serial.println(); 
  61.   /* Update the properties on the server */ 
  62.   sendPropertyUpdate(); 
  63.    
  64. /*****************
  65. * Property Handler Callbacks
  66. ******************/ 
  67. enum msgCodeEnum propertyHandler(const char * entityName, const char * propertyName,  twInfoTable ** value, char isWrite, void * userdata) { 
  68.   char * asterisk = "*"
  69.   if (!propertyName) propertyName = asterisk; 
  70.   TW_LOG(TW_TRACE,"propertyHandler - Function called for Entity %s, Property %s", entityName, propertyName); 
  71.   if (value) { 
  72.     
  73.       /* Property Reads */ 
  74.       if (strcmp(propertyName, "Temperature") == 0) *value = twInfoTable_CreateFromNumber(propertyName, properties.Temperature); 
  75.       else if (strcmp(propertyName, "Pressure") == 0) *value = twInfoTable_CreateFromNumber(propertyName, properties.Pressure);      
  76.       else return TWX_NOT_FOUND; 
  77.     return TWX_SUCCESS; 
  78.   } 
  79.   else
  80.     TW_LOG(TW_ERROR,"propertyHandler - NULL pointer for value"); 
  81.     return TWX_BAD_REQUEST; 
  82.   } 
  83.  
  84.  
  85. void setup() { 
  86.   int err=0
  87.   /* Open serial connection */ 
  88.   Serial.begin(9600); 
  89.   /* Wait for someone to launch the console */ 
  90.   delay(3000); 
  91.  
  92.  
  93.   /* Setup the ethernet connection */ 
  94.   Serial.println("Attempting to start Ethernet2"); 
  95.   if (Ethernet.begin(mac) == 0) { 
  96.     Serial.println("Failed to configure Ethernet using DHCP"); 
  97.   } 
  98.   else
  99.     Serial.println("Sucess getting dhcp address"); 
  100.   } 
  101.   /* start adapter */ 
  102.   system("ifup eth0"); 
  103.   /* wait for it to start */ 
  104.   delay(1000); 
  105.   Serial.print("Galileo IP address: "); 
  106.   Serial.println(Ethernet.localIP()); 
  107.   system("telnetd -l /bin/sh"); 
  108.   Serial.println("BMP180 Example!"); 
  109.   tp.begin(); 
  110.  
  111.  
  112.   Serial.print("Initialize TWX: "); 
  113.   err = twApi_Initialize(serverName, port, TW_URI, apiKey, NULL, MESSAGE_CHUNK_SIZE, MESSAGE_CHUNK_SIZE, TRUE); 
  114.   if (err) { 
  115.     Serial.println("Error initializing the API"); 
  116.   } 
  117.  
  118.  
  119.   /* Allow self signed certs */ 
  120.   twApi_SetSelfSignedOk(); 
  121.  
  122.  
  123.   /* Regsiter our properties */ 
  124.    twApi_RegisterProperty(TW_THING, thingName, "Temperature", TW_NUMBER, NULL, "ALWAYS", 0, propertyHandler,NULL); 
  125.    twApi_RegisterProperty(TW_THING, thingName, "Pressure", TW_NUMBER, NULL, "ALWAYS", 0, propertyHandler,NULL); 
  126.  
  127.   /* Bind our thing */ 
  128.   twApi_BindThing(thingName); 
  129.  
  130.  
  131.   /* Connect to server */ 
  132.   if (!twApi_Connect(CONNECT_TIMEOUT, CONNECT_RETRIES)) { 
  133.     Serial.println("sucessefully connected to TWX!"); 
  134.   } 
  135.  
  136.  
  137. void loop() { 
  138.   // put your main code here, to run repeatedly: 
  139.   dataCollectionTask(); 
  140.   delay(timeBetweenRefresh); 
  141.   Serial.print("."); 



Every time when I burn the code to my board  the serial monitor waits for a while after printing "Initialize TWX:" and then start printing the temperature and pressure without giving any information regarding the connection, like if it's connected or not .I'm also not able to see temperature and pressure as properties in binding option. I have attached the screenshot of Serial Monitor and the original as well as modified code . Please let me know where I'm going wrong .

2 REPLIES 2

If it helps. Here is the screenshot of ifconfig for my device.

Screenshot (13).png

I realised in code I have written ifup eth0,but there is no adapter as etho0 on my device. As a result, I changed the code to "ifup enp0s20f6". Even after this my device wasn't able to connect and send data to thingworx. I looked further into ifup and I came to know ifup <adapyter_name> gives all the details related to a particular adapter . When I wrote "ifup enp0s20f6" I got error saying "ifup: can't open '/etc/network/interfaces': No such file or directory". My device is connected to the internet as wget is able to download the data . What should I do now ?

vmihai
12-Amethyst
(To:rshukla-2)

Hi Rishi Shukla,

The code for the Weather App with Intel Galileo was made to be used on a http instance. Please check this post to learn how to make the C SDK work on https.

Using the C SDK to Deliver Data to ThingWorx from a Raspberry PI

Thank you,

Veronica

Announcements


Top Tags