Temperature Logger With Arduino And Artik Cloud




Sending temperature from Arduino MKR1000 to Artik Cloud.

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
× 1

Software apps and online services

ARTIK Cloud for IoT
Samsung ARTIK Cloud for IoT
Arduino IDE
Arduino IDE

Story

At last check this working video:

Schematics

Code

Used to detect temperature in LM35 and send in to ARTIKcloud ,
#include <WiFi101.h>
#include <ArduinoJson.h>
int temp = 9; //temperature pin
int val;

// Web REST API params
char server[] = "api.artik.cloud";  
int port = 443; //(port 443 is default for HTTPS)

String AuthorizationData = "Authorization: Bearer  <YOUR DEVICE TOKEN>";


char buf[200];
int LED = 6;
int ledState = ;

WiFiSSLClient client;
char ssid[] = "YOUR SSID";      //  your network SSID (name)
char pass[] = "YOUR PASSWORD";
int status = WL_IDLE_STATUS;

void setup() {

  pinMode(LED,OUTPUT);
  pinMode(temp, INPUT); // LM35 pin

  Serial.begin(9600);
  while (status != WL_CONNECTED){
    Serial.println("Attempting to connect to WiFi");
    status = WiFi.begin(ssid,pass);
  }
  Serial.println("connected to WiFi ");
  
}
  
void loop() {
  Serial.println("loop");
  ledToggle();
  client.connect(server, port);
  delay(1000);
  if (!client.connected()) { 
    Serial.println(" error ");
  } else {
      //int t = dht.readTemperature();
      //int h = dht.readHumidity();
      val = analogRead(temp);
float mv = ( val/1024.0)*5000; //FInd temperature
float cel = mv/100;            //convert in to celsius 
float farh = (cel*9)/5 + 32;   //convert in to fahrenheat (optional) 
      Serial.println("Sending data"+String(cel)); // sending data 
      client.println("POST /v1.1/messages HTTP/1.1");
      client.println("Host: api.artik.cloud");
      client.println("Accept: */*");
      client.println("Content-Type: application/json");
      client.println("Connection: close");
      client.println(AuthorizationData);

       // Automated POST data section
       client.print("Content-Length: ");
       client.println(loadBuffer(cel,farh)); // loads buf, returns length
       client.println();
       client.println(buf);
       Serial.println("Data posted");
       client.stop();       
  }
 
  delay(3*60*1000); // setting delay foe 3 minutes 

}

int loadBuffer(int insTemp, int insHumid ) {  
   StaticJsonBuffer<200> jsonBuffer; // reserve spot in memory

   JsonObject& root = jsonBuffer.createObject(); // create root objects
     root["sdid"] = "<YOUR DEVICE ID>"; // FIX 
     root["type"] = "message";

   JsonObject& dataPair = root.createNestedObject("data"); // create nested objects
     dataPair["temp"] = insTemp;  
     dataPair["humid"] = insHumid;

   root.printTo(buf, sizeof(buf)); // JSON-print to buffer

   return (root.measureLength()); // also return length
 }

 void ledToggle(){
  if (ledState == ){
    digitalWrite(LED,LOW);
    ledState = 1;
  } else {
    digitalWrite(LED,HIGH);
    ledState = ;
  }
 }
READ  bit rate from ISM transceiver‘World’s highest’

Source : Temperature Logger With Arduino And Artik Cloud




Leave a Comment

*
= 3 + 6

(Spamcheck Enabled)

Read previous post:
facetVISION Compound Eyes for Industry and Smartphone
facetVISION: Compound Eyes for Industry and Smartphone

Researchers at the Fraunhofer Institute for Applied Optics and Precision Engineering IOF have developed a process that makes the production of...

Close
Scroll to top