Hi, I am trying to connect to the IBM IoT via ethernet using a registered connection. I've tried to follow https://github.com/ibm-watson-iot/device-arduino/blob/master/samples/registered/registered.ino
but got some errors. I tried to find out which paho file I need and downloaded the C library but this says it's not valid in the arduino IDE.
I've tried my own code based on another example found but it just contionously tries to connect. The code is here:
#include <SPI.h>
#include <Ethernet.h>
#include "Adafruit_SGP30.h"
#include <ArduinoJson.h>
#include <MQTTClient.h>
#define PUBLISH_TOPIC "iot-2/evt/status/fmt/json"
#define AUTHMETHOD "use-token-auth"
#define CLIENT_ID "d:ORG:Type:ID"
#define MS_PROXY "ORG.messaging.internetofthings.ibmcloud.com"
#define AUTHTOKEN "TOKEN"
// Update these with values suitable for your network.
byte mac[] = { 0x90, 0xA2, 0xDA, 0x11, 0x22, 0x19 };
//byte ip[] = {10, 1, 128, 231};
Adafruit_SGP30 sgp;
EthernetClient c;
MQTTClient client;
uint16_t TVOC_base, eCO2_base;
String deviceEvent;
void connect() {
Serial.print("connecting...");
while (!client.connect(CLIENT_ID, AUTHMETHOD, AUTHTOKEN)) {
Serial.print(".");
delay(1000);
}
Serial.println("\nconnected!");
}
void setup() {
Serial.begin(9600);
Ethernet.begin(mac);
client.begin("0167pz.messaging.internetofthings.ibmcloud.com",c);
connect();
if (! sgp.IAQmeasure()) {
Serial.println("Measurement failed");
return;
}
Serial.print("TVOC "); Serial.print(sgp.TVOC); Serial.print(" ppb\t");
Serial.print("eCO2 "); Serial.print(sgp.eCO2); Serial.println(" ppm");
readTenTimes();
delay(1000);
}
void loop() {
int count=0;
client.loop();
if (! sgp.IAQmeasure()) {
Serial.println("Measurement failed");
return;
}
Serial.print("TVOC "); Serial.print(sgp.TVOC); Serial.print(" ppb\t");
Serial.print("eCO2 "); Serial.print(sgp.eCO2); Serial.println(" ppm");
count++;
if(count==10){
count=0;
if (! sgp.getIAQBaseline(&eCO2_base, &TVOC_base)) {
Serial.println("Failed to get baseline readings");
return;
}
Serial.print("****Baseline values: eCO2: 0x"); Serial.print(eCO2_base, HEX);
Serial.print(" & TVOC: 0x"); Serial.println(TVOC_base, HEX);
}
/* StaticJsonBuffer<300> JSONbuffer;
JsonObject& JSONencoder = JSONbuffer.createObject();
JSONencoder["eCO2"]=sgp.eCO2;
JSONencoder["TVOC"]=sgp.TVOC;
String jsonO;
JSONencoder.printTo(jsonO);
Serial.println("\nPublishing message: ");
Serial.println(jsonO);
client.publish(PUBLISH_TOPIC, jsonO);*/
delay(1000);
}
/*void readTenTimes(){
int counter = 0;
for(counter=0;counter<10;counter++){
sgp.IAQmeasure();
Serial.print("TVOC "); Serial.print(sgp.TVOC); Serial.print(" ppb\t");
Serial.print("eCO2 "); Serial.print(sgp.eCO2); Serial.println(" ppm");
delay(1000);
}
}*/
I've replaced important info with letters such as the token. Can any help be provided?
Much appreciated,
Dillon