I have some code compiled on the web IDE which works nicely when flashed on a Photon but doesn’t work on an old Core, in both cases I’m compiling for firmware version 1.1.0.
// This #include statement was automatically added by the Particle IDE.
#include <elapsedMillis.h>
// This #include statement was automatically added by the Particle IDE.
#include <HttpClient.h>
int count;
int interval;
String id;
String channel;
elapsedMillis elapsed;
void setup() {
Particle.function("update", update);
Particle.function("setId", setId);
Particle.function("setChannel", setChannel);
Particle.function("setInterval", setInterval);
Particle.variable("count", count);
Particle.variable("channel", channel);
Particle.variable("interval", interval);
Particle.variable("id", id);
id = read(20);
channel = read(0);
EEPROM.get(70, interval);
if (interval < 10000) {
interval = 10000;
}
update("start");
}
void loop() {
if (elapsed > interval) {
update("auto");
}
}
HttpClient http;
http_request_t request;
http_response_t response;
http_header_t headers[] = {
{ "Accept" , "*/*"},
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
int update(String extra) {
request.hostname = "myhost.example.com";
request.port = 80;
request.path = "/counter/" + channel + "/" + id;
http.get(request, response, headers);
if (response.status != 200) {
return -1;
} else {
elapsed = 0;
count = atoi(response.body);
Particle.publish("counter", extra + " " + channel + ":" + count);
return count;
}
}
int setInterval(String val) {
interval = atoi(val) * 1000;
EEPROM.put(70, interval);
return 1;
}
int setId(String val) {
id = val;
write(20, val, 50);
return 1;
}
int setChannel(String val) {
if (val == "youtube" || val == "twitter") {
channel = val;
write(0, val, 20);
return 1;
}
return -1;
}
const int STRING_BUF_SIZE = 64;
void write(int addr, String data, const int max) {
char stringBuf[STRING_BUF_SIZE];
data.getBytes((unsigned char *)stringBuf, max);
EEPROM.put(addr, stringBuf);
}
String read(int addr) {
char stringBuf[STRING_BUF_SIZE];
EEPROM.get(addr, stringBuf);
stringBuf[sizeof(stringBuf) - 1] = 0; // make sure it's null terminated
String str(stringBuf);
return str;
}
On the core, from the web console:
- the OS version doesn’t show up
- any attempt to invoke the
setChannel
function fails (returns-1
) - any function call seems unable to write to EEPROM
- no event gets published