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;
-
- byte mac[] = {0x98, 0x4F, 0xEE, 0x01, 0xCB, 0xE9 };
-
-
-
- char * thingName = "myTestTempPress";
-
- char * serverName = "mitpune66.cloud.thingworx.com";
-
- int port = 443;
-
- char * apiKey = "d9c81d35-5a28-49b0-9ddf-e9193eda3b66";
-
- int timeBetweenRefresh = 1000;
-
-
-
- struct {
- double Temperature;
- double Pressure;
- }
- properties;
-
-
- void sendPropertyUpdate() {
-
- 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();
-
- sendPropertyUpdate();
- }
-
-
-
-
- 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) {
-
-
- 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;
-
- Serial.begin(9600);
-
- delay(3000);
-
-
-
- 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");
- }
-
- system("ifup eth0");
-
- 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");
- }
-
-
-
- twApi_SetSelfSignedOk();
-
-
-
- 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);
-
-
- twApi_BindThing(thingName);
-
-
-
- if (!twApi_Connect(CONNECT_TIMEOUT, CONNECT_RETRIES)) {
- Serial.println("sucessefully connected to TWX!");
- }
- }
-
-
- void loop() {
-
- 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 .