Unable to connect remote thing (Intel Galileo Gen 2) to thingworx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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:
- include <twApi.h>
- #include <twLogger.h>
- #include <twOSPort.h>
- #include <SFE_BMP180.h>
- #include <Ethernet.h>
- #include <stdio.h>
- #include <string.h>
- #include <Wire.h>
- SFE_BMP180 tp;
- /* Mac address of the network adapter */
- byte mac[] = {0x98, 0x4F, 0xEE, 0x01, 0xCB, 0xE9 };
- /* Name of your thing */
- char * thingName = "myTestTempPress";
- /* IP/hostname of your TWX server */
- char * serverName = "mitpune66.cloud.thingworx.com";
- /* port */
- int port = 443;
- /* API key */
- char * apiKey = "d9c81d35-5a28-49b0-9ddf-e9193eda3b66";
- /* refresh rate */
- int timeBetweenRefresh = 1000;
- /* Hold all the properties */
- struct {
- double Temperature;
- double Pressure;
- }
- properties;
- void sendPropertyUpdate() {
- /* Create the property list */
- propertyList * proplist = twApi_CreatePropertyList("Temperature",twPrimitive_CreateFromNumber(properties.Temperature), 0);
- if (!proplist) {
- TW_LOG(TW_ERROR,"sendPropertyUpdate: Error allocating property list");
- return;
- }
- twApi_AddPropertyToList(proplist,"Pressure",twPrimitive_CreateFromNumber(properties.Pressure), 0);
- twApi_PushProperties(TW_THING, thingName, proplist, -1, FALSE);
- twApi_DeletePropertyList(proplist);
- }
- void dataCollectionTask()
- {
- char status;
- status = tp.startTemperature();
- status = tp.getTemperature(properties.Temperature);
- status = tp.startPressure(3);
- status = tp.getPressure(properties.Pressure, properties.Temperature);
- Serial.print("Time:");
- Serial.print(millis());
- Serial.print(" Temperature:");
- Serial.print(properties.Temperature, 1);
- Serial.print("C");
- Serial.print(" Pressure:");
- Serial.print(properties.Pressure, 1);
- Serial.print("mb");
- Serial.println();
- /* Update the properties on the server */
- sendPropertyUpdate();
- }
- /*****************
- * Property Handler Callbacks
- ******************/
- enum msgCodeEnum propertyHandler(const char * entityName, const char * propertyName, twInfoTable ** value, char isWrite, void * userdata) {
- char * asterisk = "*";
- if (!propertyName) propertyName = asterisk;
- TW_LOG(TW_TRACE,"propertyHandler - Function called for Entity %s, Property %s", entityName, propertyName);
- if (value) {
- /* Property Reads */
- if (strcmp(propertyName, "Temperature") == 0) *value = twInfoTable_CreateFromNumber(propertyName, properties.Temperature);
- else if (strcmp(propertyName, "Pressure") == 0) *value = twInfoTable_CreateFromNumber(propertyName, properties.Pressure);
- else return TWX_NOT_FOUND;
- return TWX_SUCCESS;
- }
- else {
- TW_LOG(TW_ERROR,"propertyHandler - NULL pointer for value");
- return TWX_BAD_REQUEST;
- }
- }
- void setup() {
- int err=0;
- /* Open serial connection */
- Serial.begin(9600);
- /* Wait for someone to launch the console */
- delay(3000);
- /* Setup the ethernet connection */
- Serial.println("Attempting to start Ethernet2");
- if (Ethernet.begin(mac) == 0) {
- Serial.println("Failed to configure Ethernet using DHCP");
- }
- else {
- Serial.println("Sucess getting dhcp address");
- }
- /* start adapter */
- system("ifup eth0");
- /* wait for it to start */
- delay(1000);
- Serial.print("Galileo IP address: ");
- Serial.println(Ethernet.localIP());
- system("telnetd -l /bin/sh");
- Serial.println("BMP180 Example!");
- tp.begin();
- Serial.print("Initialize TWX: ");
- err = twApi_Initialize(serverName, port, TW_URI, apiKey, NULL, MESSAGE_CHUNK_SIZE, MESSAGE_CHUNK_SIZE, TRUE);
- if (err) {
- Serial.println("Error initializing the API");
- }
- /* Allow self signed certs */
- twApi_SetSelfSignedOk();
- /* Regsiter our properties */
- twApi_RegisterProperty(TW_THING, thingName, "Temperature", TW_NUMBER, NULL, "ALWAYS", 0, propertyHandler,NULL);
- twApi_RegisterProperty(TW_THING, thingName, "Pressure", TW_NUMBER, NULL, "ALWAYS", 0, propertyHandler,NULL);
- /* Bind our thing */
- twApi_BindThing(thingName);
- /* Connect to server */
- if (!twApi_Connect(CONNECT_TIMEOUT, CONNECT_RETRIES)) {
- Serial.println("sucessefully connected to TWX!");
- }
- }
- void loop() {
- // put your main code here, to run repeatedly:
- dataCollectionTask();
- delay(timeBetweenRefresh);
- 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 .
- Labels:
-
Connectivity
-
Install-Upgrade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
If it helps. Here is the screenshot of ifconfig for my device.
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 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
