Hi CMata,
Thank you for your reply! I am following the Getting Started Guide, I have screenshots of what I have set up and what happens. I am uploading a customized sketch for IoT Analytics. Here is what I have:
The Galileo serial console is on the left and the Arduino IDE is on the Right. It looks like the upload is successful according to the Arduino IDE however the last line on the Galileo side shows the segfault.
I am using the correct Board and Port Indicated below:
Thank you for taking the time to look at this!
This screenshot shows that the segfault does not appear when loading a vanilla sketch
This is the sketch:
//This example reads the temperature sensor on the Galileo's
//onboard ADC, AD7298, using the iio (Industrial I/O) subsystem and
//sends the observed data to the Intel IoTkit Cloud
#include <IoTkit.h> // include IoTkit.h to use the Intel IoT Kit
#include <Ethernet.h> // must be included to use IoTkit
#include <aJSON.h>
//#include <OneWire.h>
//#include <DallasTemperature.h>
#include <SPI.h>
#include "EmonLib.h"
//
const int CT1 = 1;
const int CT2 = 1; // Set to 0 to disable CT channel 2
const int CT3 = 1;
const int CT4 = 1;
const int UNO = 0;
//
EnergyMonitor ct1; // Create instances for each CT channel
EnergyMonitor ct2;
EnergyMonitor ct3;
EnergyMonitor ct4;
//
//#define ONE_WIRE_BUS 4 // Data wire is plugged into port 2 on the Arduino
//OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
//DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
// DeviceAddress address_T1 = { 0x28, 0x47, 0x28, 0xB5, 0x05, 0x00, 0x00, 0x0D };
//
typedef struct {
int realPower; // RealPower
int apparentPower; // ApparentPower
int T1; // temperature sensor 1
} Payload;
Payload emontx;
//
// create an object of the IoTkit class
IoTkit iotkit;
int temp;
//
//
void setup() {
Serial.begin(115200);
// call begin on the IoTkit object before calling any other methods
iotkit.begin();
//
ct1.currentTX(1, 90.9); // Setup emonTX CT channel (channel, calibration)
ct2.currentTX(2, 90.9);
ct3.currentTX(3, 90.9); // CT Calibration factor = CT ratio / burden resistance
ct4.currentTX(4, 90.9);
}
void loop() {
temp = getADCTemp();
// Serial.print("Temperature is ");
// Serial.print(temp);
// Serial.println(" degrees celcius.");
//Serial.print("Current Tap 1");
// Serial.println(ct1.calcIrms(1480));
// Serial.println(ct2.calcIrms(1480));
// Serial.println(ct3.calcIrms(1480));
// Serial.println(ct4.calcIrms(1480));
// Serial.println(" Amps");
//
//
// sensors.requestTemperatures(); // Send the command to get temperatures//
//
// emontx.T1 = sensors.getTempF(address_T1);
//
// float Irms1 = ct1.calcIrms(1480); // Calculate RMS current 1
// float Irms2 = ct2.calcIrms(1480); // Calculate RMS current 2
// float Irms3 = ct3.calcIrms(1480); // Calculate RMS current 3
// float Irms4 = ct4.calcIrms(1480); // Calculate RMS current 4
//
double Irms1 = ct1.calcIrms(1480); // Calculate RMS current 1
double Irms2 = ct2.calcIrms(1480); // Calculate RMS current 2
double Irms3 = ct3.calcIrms(1480); // Calculate RMS current 3
double Irms4 = ct4.calcIrms(1480); // Calculate RMS current 4
//
//
// call send to generate one observation.
// parm1 - the name of the measurement. It must have been previously registered.
// parm2 - the value to send as the measurement observation
// you can also generate your own JSON and send multiple keys and values
// in this format:
//
// {
// “n”: “temperature sensor”,
// “v”: “27.2"
// }
//
// you need to escape the quotations to pass it directly to iotkit.send:
//iotkit.send("{\"n\": \"temperature.v1.0\",\"v\":\"27.2\"}");
//iotkit.send("{\"n\": \"obtemp\",\"v\":\"temp\"}");
//
iotkit.send("obtemp", temp*1.8+32);
iotkit.send("current1", ct1.calcIrms(1480));
iotkit.send("current2", ct2.calcIrms(1480));
iotkit.send("current3", ct3.calcIrms(1480));
iotkit.send("current4", ct4.calcIrms(1480));
// you can also send a full JSON string with your own variables:
//
// aJsonObject* root = aJson.createObject();
// if (root != NULL) {
// aJson.addItemToObject(root, "n", aJson.createItem(metric));
// aJson.addItemToObject(root, "v", aJson.createItem(value));
// iotkit.send(aJson.print(root)); // this sends your full json
// aJson.deleteItem(root);
// }
//
// If you are receiving incoming commands, listen for them with receive
// If you have your own custom json-parsing receive function, pass as argument
// such as iotkit.receive(callback);
// It must follow this prototype, but any name: void callback(char* json)
//
iotkit.receive();
iotkit.receive(callback);
delay(30000);
}
// this is an example callback that parses a user-created JSON in the form
// {
// "component": "led",
// "command": "off"
// }
// and turns off LED at pin 13 hard-coded
//
void callback(char* json) {
Serial.println(json);
aJsonObject* parsed = aJson.parse(json);
if (&parsed == NULL) {
// invalid or empty JSON
Serial.println("received invalid JSON");
return;
}
aJsonObject* component = aJson.getObjectItem(parsed, "component");
aJsonObject* command = aJson.getObjectItem(parsed, "command");
if ((component != NULL)) {
if (strcmp(component->valuestring, "led") == 0) {
if ((command != NULL)) {
if (strcmp(command->valuestring, "off") == 0) {
pinMode(13, OUTPUT);
digitalWrite(13, false);
}
if (strcmp(command->valuestring, "on") == 0) {
pinMode(13, OUTPUT);
digitalWrite(13, true);
}
}
}
}
}
// reads hardware temp sensor
int getADCTemp(){
char scale[4];
char raw[4];
char offset[4];
int raw_i;
int scale_i;
int offset_i;
FILE *fp_raw;
fp_raw = fopen("/sys/bus/iio/devices/iio:device0/in_temp0_raw", "r"); //read the values from scale, raw and offset files.
fgets(raw, 4, fp_raw); //we need all three values, because the formula for
fclose(fp_raw); //calulating the actual temperature in milli-degrees Celcius
//is: TEMP = (RAW + OFFSET) * SCALE
FILE *fp_scale;
fp_scale = fopen("/sys/bus/iio/devices/iio:device0/in_temp0_scale", "r");
fgets(scale, 4, fp_scale);
fclose(fp_scale);
FILE *fp_offset;
fp_offset = fopen("/sys/bus/iio/devices/iio:device0/in_temp0_offset", "r");
fgets(offset, 4, fp_offset);
fclose(fp_offset);
raw_i = atoi(raw); //we have the values now, but they are in ASCII form-
scale_i = atoi(scale); //we need them as integers so we can use them for calculations.
offset_i = atoi(offset);
int temp = (raw_i + offset_i) * scale_i; //Calculate temperature in milli-degrees celcius
temp /= 1000; //divide by 1000 to convert to degrees celcius
return temp;
}