wifi - How do use the AdaFruit CC3000 library to send a simple HTTP Post of my Uno JSON sensor data to Bluemix (node red)? -


i clueless , after week of racking brains. background: out of memory on working arduino uno weather station , flawless internet connectivity using sample wifi sketches cc3000 wifi shield. mqtt samples work great well, but! can't fit mqtt client need bare bones. thinking http post bare bones based on advice received in forums.

i can't figure out how send http post using adafruit cc3000 library bluemix node red app , display 300 or character json formatted string want send every 5 minutes. want strings display in node red debug area. absolutely clueless!!!

this http code (cc3000 webclient sample) out adafruit way works , shown below know have work with. don't understand credentials use either relative bluemix. confusing new of being hardware product development engineer of life. loving learning experience though!

essentially want convert post , pull in string on bluemix using node red. please helppp!!!!

here basic functional code on uno using adafruit site test.

#define website      "www.adafruit.com" #define webpage      "/testwifi/index.html"  ... ip = 0;   // try looking website's ip address   serial.print(website); serial.print(f(" -> "));   while (ip == 0) {     if (! cc3000.gethostbyname(website, &ip)) {       serial.println(f("couldn't resolve!"));     }     delay(500);   } ... adafruit_cc3000_client www = cc3000.connecttcp(ip, 80);   if (www.connected()) {     www.fastrprint(f("get "));     www.fastrprint(webpage);     www.fastrprint(f(" http/1.1\r\n"));     www.fastrprint(f("host: ")); www.fastrprint(website); www.fastrprint(f("\r\n"));     www.fastrprint(f("\r\n"));     www.println();   } else {     serial.println(f("connection failed"));         return;   }    serial.println(f("-------------------------------------"));    /* read data until either connection closed, or idle timeout reached. */    unsigned long lastread = millis();   while (www.connected() && (millis() - lastread < idle_timeout_ms)) {     while (www.available()) {       char c = www.read();       serial.print(c);       lastread = millis();     }   }   www.close(); 

the http spec post not hugely different get.

you need add couple of headers, such content-type , content-length.

but should starting point

... adafruit_cc3000_client www = cc3000.connecttcp(ip, 80);   if (www.connected()) {     www.fastrprint(f("post "));     www.fastrprint(webpage);     www.fastrprint(f(" http/1.1\r\n"));     www.fastrprint(f("host: "));      www.fastrprint(website);     www.fastrprint(f("\r\n"));     www.fastprint(f("content-type: application/json\r\n"));     www.fastprint(f("content-length: "));     www.fastprint(payload.length));     www.fastrprint(f("\r\n"));     www.fastrprint(f("\r\n"));     www.fastprint(payload);     www.println(); ... 

Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -