Disappearing resources in API Explorer

Hi guys,

I’m new here, but am very much loving Thinger. I’m looking for some help. I have my basic prototype working, and now that I want to add some enhancements, I’m running into problems.
Is there any reason why adding a simple input resource to change a sketch variable would cause all my resources in the API explorer to vanish? They’re just not there. If I comment out the input resource, my output resource (temp sensor) shows up again. Here’s my sketch:

#include <UIPEthernet.h>
#include <ThingerENC28J60.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define USERNAME ""
#define DEVICE_ID ""
#define DEVICE_CREDENTIAL ""

ThingerENC28J60 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

// Data wire is plugged into port 5 on the Arduino
  #define ONE_WIRE_BUS 5
  
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

unsigned long previousMillis = 0;       // to know when to post the temperature
unsigned int minutes_interval = 2;     // variable in minutes for posting the temperature
int lowTempAlarm = 20;                  

float ReadTemperature(){
    sensors.requestTemperatures(); // Send the command to get temperatures
    return(sensors.getTempCByIndex(0));
}

void call_alarm_endpoint(){
  pson text_data;
  text_data["value1"] = ReadTemperature();
  thing.call_endpoint("IFTTT_Maker", text_data);
}

void setup() {
  // ENC28J60 using fixed IP Address. DHCP is too big for the sketch.
  uint8_t mac[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
  Ethernet.begin(mac, IPAddress());
  sensors.begin();
  //Resource that will Read Temperature
  thing["temperature"] >> outputValue(ReadTemperature());
  //Resource that will allow for dynamic changing of temperature alarm. This is causing problems.
  thing["lowAlarmValue"] << inputValue(lowTempAlarm);
}

void loop() {
    thing.handle();
    unsigned long currentMillis = millis();
  if(minutes_interval>0 && currentMillis - previousMillis >= minutes_interval * 60000) {
    previousMillis = currentMillis;   
    if(ReadTemperature()<lowTempAlarm) {
        call_alarm_endpoint();
    }
  }
}

Your sketch seems to be fine! I will try your code with a similar device I have here… let me test that

Hi,

I have tested a similar code without using a Dallas Temp sensor, and everything seems to work fine:

#include <UIPEthernet.h>
#include <ThingerENC28J60.h>

#define USERNAME "alvarolb"
#define DEVICE_ID "enc28j60"
#define DEVICE_CREDENTIAL ""

ThingerENC28J60 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

unsigned long previousMillis = 0;       // to know when to post the temperature
unsigned int minutes_interval = 2;     // variable in minutes for posting the temperature
int lowTempAlarm = 20;                  

float ReadTemperature(){
    return 20.0;
}

void call_alarm_endpoint(){
  pson text_data;
  text_data["value1"] = ReadTemperature();
  thing.call_endpoint("IFTTT_Maker", text_data);
}

void setup() {
  // ENC28J60 using fixed IP Address. DHCP is too big for the sketch.
  uint8_t mac[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
  Ethernet.begin(mac, IPAddress(192, 168, 1, 125));

  //Resource that will Read Temperature
  thing["temperature"] >> outputValue(ReadTemperature());
  //Resource that will allow for dynamic changing of temperature alarm. This is causing problems.
  thing["lowAlarmValue"] << inputValue(lowTempAlarm);
}

void loop() {
    thing.handle();
    unsigned long currentMillis = millis();
  if(minutes_interval>0 && currentMillis - previousMillis >= minutes_interval * 60000) {
    previousMillis = currentMillis;   
    if(ReadTemperature()<lowTempAlarm) {
        call_alarm_endpoint();
    }
  }
}

Here is the api:

I suppose that your Dallas is working fine, is it? try to remove the dallas reading, or add a small sleep before reading…

Thanks so much for your help! I’m afraid I’m baffled, though. I replaced the Dallas read with just a value, as you did, and I get the same results as before; that is to say that if I include the lowAlarmValue input resource, I get no resources listed in the API explorer, but if I comment out the lowAlarmValue resource, the temperature output resource does appear.
I did some more troubleshooting, and here’s what I found:
The following code works; it shows both resources. Note the commented out lines in call_alarm_endpoint():

#include <UIPEthernet.h>
#include <ThingerENC28J60.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define USERNAME "plastixmith"
#define DEVICE_ID "HotTubTemp"
#define DEVICE_CREDENTIAL "oMZGzrYj8VmG"
ThingerENC28J60 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
  
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

unsigned long previousMillis = 0;       // to know when to post the temperature
unsigned int minutes_interval = 2;     // variable in minutes for posting the temperature
int lowTempAlarm = 20;                  // how cold the hot tub can get before it alarms 35C=95F

float ReadTemperature(){
    return 21.0;
}

void call_alarm_endpoint(){
  pson text_data;
  //text_data["value1"] = ReadTemperature();
  //thing.call_endpoint("IFTTT_Maker", text_data);
}
void setup() {
  sensors.begin();
  // ENC28J60 using fixed IP Address. DHCP is too big for the sketch.
  uint8_t mac[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
  Ethernet.begin(mac, IPAddress(192, 168, 1, 123));
  //Resource that will Read Temperature
  thing["temperature"] >> outputValue(ReadTemperature());
  //Resource that will allow the alarm value to be changed
  thing["lowAlarmValue"] << inputValue(lowTempAlarm);
}

void loop() {
    thing.handle();
    unsigned long currentMillis = millis();
  if(minutes_interval>0 && currentMillis - previousMillis >= minutes_interval * 60000) {
    previousMillis = currentMillis;   
    if(ReadTemperature()<lowTempAlarm) {
        call_alarm_endpoint();
    }
  }
}

If I uncomment text_data[“value1”] = ReadTemperature() in that function, my endpoints disappear. Furthermore, when I go to check them, my device disconnects, and the onboard LED turns on.

In fact, even if I leave out the call the ReadTemperature() and do something like this: text_data[“value1”] = 21.0, I still get the same result as above.

I’m lost!

I wonder if I’m running out of SRAM? The sketch leaves less than 500 bytes of dynamic memory , so querying the API could be enough to cause a stack crash. If I add a few lengthy strings, I can see the same behaviour. My next move is to try something different. I have an ESP8266 on the way, so maybe that will be better. I’ll post if I figure out an answer.