Upload the code, given below, to check MKR1000 and temperature sensor.
- TMP +v to MKR1000 - VCC
- TMP GND to MKR1000 - GND
- TMP SIG to MKR1000 - A0
You will see the serial monitor, as given below-
This means our temperature sensor and Arduino MKR1000 works perfectly.
Setup Artik Cloud
Now, the time to connect to the Cloud (Samsung Artik Cloud) has come.
Go to Developer dashboard to create a device type.
- Sign in to Developer Dashboard.
- Click the "+ Create Device Type".
- Name the device type "Arduino Temperature Sensor" and give it a unique name "my.device.arduino.temperature".
- Click "Create Device Type" to create the device type.
Now, create a new Manifest for the new device type by following-
- Click "Arduino Temperature Sensor" in the left column.
- Click "Manifest" and then "+ New Manifest".
- Enter Temperature as the Field Name and "Double" as Data Type.
- Click "Manifest" and then "+ New Manifest".
- Click "Save" and then "Next: Actions".
- Leave Actions as default and click "Save New Manifest".
- Go to MY ARTIK Cloud to create a new Arduino Temperature Sensor device.
- Sign in to MY ARTIK Cloud.
- Click to connect a new device. Select the "Arduino Temperature Sensor" device type.
- Click "Connect Device..."
- Click the Settings icon of the newly created device. In the pop-up, click "GENERATE DEVICE TOKEN…".
- Copy the device ID and device.
- A token will come on this screen. You will use this in the code.
- Click the Settings icon of the newly created device. In the pop-up, click "GENERATE DEVICE TOKEN…".
- Now Artk part is set.
Sending Temperature Readings to ARTIK Cloud
Paste you DEVICE ID, given below-
- String deviceId = "your deviceId";
paste you DEVICE Token, given below-
- String deviceToken = "your deviceToken";
Paste Your Wi-Fi name, given below-
- char ssid[] = "Your wifi name";
Paste Your Wi-Fi password, given below-
- char pass[] = "Your wifi Password";
When everything is set, upload your code-
- #include < WiFi101.h >
- #include < ArduinoJson.h >
- #include < ArduinoHttpClient.h >
- #include < SPI.h >
-
- char server[] = "api.artik.cloud";
- int port = 443;
-
- String deviceToken = "Your deviceToken";
- String deviceId = "Your deviceId";
-
- char ssid[] = "Your wifi name";
- char pass[] = "Your wifi Password";
- float temperature = 0.0;
- boolean onFire = false;
- char buf[200];
- const int LED = 6;
- int ledState = 0;
- WiFiSSLClient wifi;
- HttpClient client = HttpClient(wifi, server, port);
- int status = WL_IDLE_STATUS;
- void setup() {
- pinMode(LED, OUTPUT);
- Serial.begin(9600);
- while (status != WL_CONNECTED) {
- Serial.print("Attempting to connect to Network named: ");
- Serial.println(ssid);
-
- status = WiFi.begin(ssid, pass);
- }
- }
- void loop() {
- Serial.println("loop");
- ledToggle();
- Serial.println("making POST request");
- String contentType = "application/json";
- String AuthorizationData = "Bearer " + deviceToken;
- temperature = ((analogRead(A0) * (3300 / 1024)) - 500) / 10;
- onFire = false;
- int len = loadBuffer(temperature, onFire);
- Serial.println("Sending data " + String(temperature));
-
- client.beginRequest();
- client.post("/v1.1/messages");
- client.sendHeader("Authorization", AuthorizationData);
- client.sendHeader("Content-Type", "application/json");
- client.sendHeader("Content-Length", len);
- client.endRequest();
- client.print(buf);
-
- 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(30000);
- }
- int loadBuffer(float temp, boolean onFire) {
- StaticJsonBuffer < 200 > jsonBuffer;
- JsonObject & root = jsonBuffer.createObject();
- root["sdid"] = deviceId;
- root["type"] = "message";
- JsonObject & dataPair = root.createNestedObject("data");
- dataPair["Temperature"] = temp;
- dataPair["onFire"] = onFire;
- root.printTo(buf, sizeof(buf));
- return (root.measureLength());
- }
- void ledToggle() {
- if (ledState == 0) {
- digitalWrite(LED, LOW);
- ledState = 1;
- } else {
- digitalWrite(LED, HIGH);
- ledState = 0;
- }
- }
Open serial monitor.
Now, sign in to My ARTIK Cloud.
Click Arduino Temperature Sensor. Click "+/- CHARTS" and check the Temp field to visualize a chart.