[Help!][MKR1000 - Artik Cloud] Publish problem

Hello! I’m the one who is trying to do mkr1000&grove heart rate sensor

Problem: Publish to artik cloud has some problem…! (I think code or something will be problem)

1.Open SSL generated & updated

I downloaded open ssl generation tool and make keys

& firmware update with WIFI101 FIRMWARE UPDATER ← update certification with “arduino.cc:443, api.artik.cloud:443”

  1. my code:
#include <WiFi101.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiSSLClient.h>
#include <WiFiUdp.h>
#include <ArduinoHttpClient.h>
#include <ArduinoJson.h>
#include <SPI.h>
#include <Wire.h>

int bpm;

String state;
// ARTIK Cloud REST endpoint
char server[] = “api.artik.cloud”;
int port = 443; // We’re using HTTPS
// Device ID tokens
String deviceToken = “2af07ef39656458b9a749b1dcd5e9d8f”;
String deviceId = “484f96b4fc6d4b0aa731ee38618c7294”;
// Your wifi network
char ssid[] = “/*secret..!!*/”;
char pass[] = “/secret/”;

char buf[200]; // buffer to store the JSON to be sent to the ARTIK cloud
const int LED = 6;
int ledState = 0;
WiFiSSLClient wifi;
HttpClient client = HttpClient(wifi, server, port);
int status = WL_IDLE_STATUS;

void setup() {
Serial.begin(9600);
while(!Serial);
while ( status != WL_CONNECTED) { // Keep trying until connected
Serial.print(“Attempting to connect to Network named: “);
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
long rssi = WiFi.RSSI();
Serial.print(“signal strength (RSSI):”);
Serial.print(rssi);
Serial.println(” dBm”);
}
}
void loop() {
Serial.println(“loop”);
Serial.println(“making POST request”);
String contentType = “application/json”;
String AuthorizationData = "Bearer " + deviceToken; //Device Token
String convert;

Wire.requestFrom(0xA0 >> 1, 1);    // request 1 bytes from slave device
while(Wire.available()) {          // slave may send less than requested
   unsigned char c = Wire.read();   // receive heart rate value (a byte)
   //Serial.println(c, DEC);         // print heart rate value
   convert=String(c,DEC);
   bpm=convert.toInt();               
}

int len = loadBuffer(bpm);  
Serial.println("Sending data"+String(bpm));  
// push the data to the ARTIK Cloud     
client.beginRequest();  
client.post("/v1.1/messages"); //, contentType, buf     
client.sendHeader("Authorization", AuthorizationData);  
client.sendHeader("Content-Type", "application/json");  
client.sendHeader("Content-Length", len);  
client.endRequest();  
client.print(buf);  
// read the status code and body of the response     
int statusCode = client.responseStatusCode();  
String response = client.responseBody();  
Serial.print("Status code: ");  
Serial.println(statusCode);  
Serial.print("Response: ");  
Serial.println(response);  
Serial.println("Wait a bit");  
delay(15000);  
}
int loadBuffer(int BPM) {
StaticJsonBuffer < 200 > jsonBuffer; // reserve spot in memory
JsonObject & root = jsonBuffer.createObject(); // create root objects
root[“sdid”] = deviceId;
root[“type”] = “message”;
JsonObject & dataPair = root.createNestedObject(“data”); // create nested objects
dataPair[“heartRate”] = BPM;

root.printTo(buf, sizeof(buf)); // JSON-print to buffer     
return (root.measureLength()); // also return length     
}

===================

  1. result:
    “Attempting to connect to~~
    ssid

    loop
    making POST request”

That’s all…

No charts were generated on artik cloud

  • no prints on serial monitor more

what can I do for this problem?

I thought more about using https. I thought it would be better to communicate with mqtt instead of https

so I changed to use mqtt

after it, I uploaded ssl certificate with mkr1000 (remove the one that is displayed on updater program and add api.artik.cloud:8883)

when I used it, I can attach to cloud and I can add more sensors to check about sensor data to cloud

It worked very well

And one more thing that I knew from add more sensors was I must think about a number of data fields and data size

Because I saw from somewhere, if you upload a lot of things to cloud, it can make nothing uploaded to cloud

You can see the example on tutorial page!

https://developer.artik.io/documentation/advanced-concepts/mqtt/color-mqtt-arduino.html

and use the latest library of MQTT&ArduinoJson&Wifi101+the latest arduino IDE(you can use hourly IDE too)

Enjoy your MKR1000+Artik Cloud! Thank you!

Happy to know more!