9 years, 7 months ago.

Problex with Xively

I have loaded the demo to my C027 and added in a connection to Xively however it seems to hang when I use the modem rather than Ethernet the problem occurs during xi_feed_update(xi_context, &feed); during the read operation. Any ideas? I added the HTTP post and GET in as a test and I also get header errors. I am very new to this so any help is appreciated

  1. include "mbed.h"
  2. include "HTTPClient.h"
  1. include "GPS.h"
  2. include "MDM.h"
  3. include "xively.h"
  4. include "xi_err.h"
  1. define XI_FEED_ID 1265594688 set Xively Feed ID (numerical, no quoutes)
  2. define XI_API_KEY "5YJ2i0AV0yH9NcU1FL2IcN7SzGEgMDCEEPh3EVrKh7arD6IN" set Xively API key (double-quoted string)

------------------ You need to configure these cellular modem / SIM parameters. These parameters are ignored for LISA-C200 variants and can be left NULL. ---------------- ! Set your secret SIM pin here (e.g. "1234"). Check your SIM manual.

  1. define SIMPIN NULL /*! The APN of your network operator SIM, sometimes it is "internet" check your contract with the network operator. You can also try to look-up your settings in google: https://www.google.de/search?q=APN+list */
  2. define APN "wlapn.com" ! Set the user name for your APN, or NULL if not needed
  3. define USERNAME "????" ! Set the password for your APN, or NULL if not needed
  4. define PASSWORD "adaptive" ------------------

InterruptIn Alm_In_int(P2_11);

int Bool_Fire_Contacts = 0; DigitalOut myled(LED1); DigitalIn Alm_In(P2_11); Ticker flipper_seconds; Ticker flipper_led; uint32_t time_seconds; char str[512];

void pressed() { Bool_Fire_Contacts = 1; printf("Active\r\n"); }

void update_timer() { time_seconds++; }

int main(void) {

bool abort=false;

char buf[2048] = ""; HTTPClient http;

Create the GPS object

  1. if 1 use GPSI2C class GPSI2C gps;
  2. else or GPSSerial class GPSSerial gps;
  3. endif Create the modem object MDMSerial mdm; mdm.setDebug(4); enable this for debugging issues MDMParser::DevStatus devStatus = {}; MDMParser::NetStatus netStatus = {}; bool mdmOk = mdm.init(SIMPIN, &devStatus); mdm.dumpDevStatus(&devStatus); mdmOk = mdm.registerNet(&netStatus); mdm.dumpNetStatus(&netStatus); Alm_In_int.rise(&pressed); mdm.connect(SIMPIN, APN,USERNAME,PASSWORD);

if (mdmOk) { join the internet connection MDMParser::IP ip = mdm.join(APN,USERNAME,PASSWORD); if (ip != NOIP) { mdm.dumpIp(ip); printf("We have an IP address\n"); } }

GET data printf("\nTrying to fetch page...\n"); int ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128); if (!ret) { printf("Page fetched successfully - read %d characters\n", strlen(str)); printf("Result: %s\n", str); } else { printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); }

POST data HTTPMap map; HTTPText inText(str, 512); map.put("Hello", "World"); map.put("test", "1234"); printf("\nTrying to post data...\n"); ret = http.post("http://httpbin.org/post", map, &inText); if (!ret) { printf("Executed POST successfully - read %d characters\n", strlen(str)); printf("Result: %s\n", str); } else { printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); }

PUT data strcpy(str, "This is a PUT test!"); HTTPText outText(str); HTTPText inText(str, 512); printf("\nTrying to put resource...\n"); ret = http.put("http://httpbin.org/put", outText, &inText); if (!ret) { printf("Executed PUT successfully - read %d characters\n", strlen(str)); printf("Result: %s\n", str); } else { printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); }

DELETE data HTTPText inText(str, 512); printf("\nTrying to delete resource...\n"); ret = http.del("http://httpbin.org/delete", &inText); if (!ret) { printf("Executed DELETE successfully - read %d characters\n", strlen(str)); printf("Result: %s\n", str); } else { printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); }

xi_feed_t feed; printf("Size of xi_feed_t: %d \r\n", sizeof(xi_feed_t)); with default settings this can get over 11kB std::memset(&feed, 0, sizeof( xi_feed_t ) );

feed.feed_id = XI_FEED_ID; feed.datastream_count = 2;

feed.datastreams[0].datapoint_count = 1; xi_datastream_t* status_datastream = &feed.datastreams[0]; strcpy(status_datastream->datastream_id, "FireInput"); xi_datapoint_t* led_status = &status_datastream->datapoints[0];

feed.datastreams[1].datapoint_count = 1; xi_datastream_t* counter_datastream = &feed.datastreams[1]; strcpy(counter_datastream->datastream_id, "Uptime"); xi_datapoint_t* counter = &counter_datastream->datapoints[0];

xi_context_t* xi_context = xi_create_context(XI_HTTPS, XI_API_KEY, feed.feed_id);

if (xi_context == NULL) { printf("Context failed to initialized. \r\n"); return -1; }

flipper_seconds.attach(&update_timer, 1.0);

printf("SMS and GPS Loop\r\n"); char link[128] = ""; unsigned int i = 0xFFFFFFFF; const int wait = 100;

DigitalOut led(LED1); while (!abort) { led = !led; while ((ret = gps.getMessage(buf, sizeof(buf))) > 0) { int len = LENGTH(ret); printf("NMEA: %.*s\r\n", len-2, msg); if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6)) { if (!strncmp("$GPGLL", buf, 6)) { double la = 0, lo = 0; char ch; if (gps.getNmeaAngle(1,buf,len,la) && gps.getNmeaAngle(3,buf,len,lo) && gps.getNmeaItem(6,buf,len,ch) && ch == 'A') { printf("GPS Location: %.5f %.5f\r\n", la, lo); sprintf(link, "I am here!\n" "https://maps.google.com/?q=%.5f,%.5f", la, lo); } } else if (!strncmp("$GPGGA", buf, 6)) { double a = 0; if (gps.getNmeaItem(9,buf,len,a)) altitude msl [m] printf("GPS Altitude: %.1f\r\n", a); } else if (!strncmp("$GPVTG", buf, 6)) { double s = 0; if (gps.getNmeaItem(7,buf,len,s)) speed [km/h] printf("GPS Speed: %.1f\r\n", s); } } } if (mdmOk && (i++ == 50/wait)) { i = 0; check the network status if (mdm.checkNetStatus(&netStatus)) { mdm.dumpNetStatus(&netStatus, fprintf, stdout); }

checking unread sms int ix[8]; int n = mdm.smsList("REC UNREAD", ix, 8); if (8 < n) n = 8; while (0 < n) { char num[32]; printf("Unread SMS at index %d\r\n", ix[n]); if (mdm.smsRead(ix[n], num, buf, sizeof(buf))) { printf("Got SMS from \"%s\" with text \"%s\"\r\n", num, buf); printf("Delete SMS at index %d\r\n", ix[n]); mdm.smsDelete(ix[n]); provide a reply const char* reply = "Hello my friend"; if (strstr(buf, /*w*/"here are you")) reply = *link ? link : "I don't know"; reply wil location link else if (strstr(buf, /*s*/"hutdown")) abort = true, reply = "bye bye"; printf("Send SMS reply \"%s\" to \"%s\"\r\n", reply, num); mdm.smsSend(num, reply); } } }

if (Bool_Fire_Contacts) { Bool_Fire_Contacts = 0; mdm.smsSend("+447958526616", "HELLO"); printf("Sent SMS reply \"%s\" to \"%s\"\r\n", "HELLO", "+447958526616"); }

xi_set_value_f32(led_status, Alm_In); xi_set_value_f32(counter, time_seconds);

printf( "update...\r\n"); xi_feed_update(xi_context, &feed); printf( "done...\r\n");

} gps.powerOff(); mdm.powerOff(); return 0; }

Question relating to:

C027_Support library test C027, GNSS, GPRS, GPS, GSM, modem
Be the first to answer this question.