Monica Houston
Published

Getting Started With ARTIK Cloud - Grove Weather Station

Quick and easy project that uses Samsung's ARTIK Cloud to collect temperature data from an arduino

BeginnerWork in progress1,858
Getting Started With ARTIK Cloud - Grove Weather Station

Things used in this project

Story

Read more

Schematics

Connecting the Temperature Sensor

Code

grove_tempsensor.ino

C/C++
/*
/* This is based on Grove - Temperature Sensor demo v1.0
*  This sensor detects the environment temperature,
*  Connect the signal of this sensor to A0, use the 
*  Serial monitor to get the result.
*/
#include <math.h>
int a;
double temperature;
int B=3975;                  //B value of the thermistor
double resistance;

void setup()
{
  Serial.begin(9600);  
}

void loop()
{
  delay(30000); // 30 seconds
  a=analogRead(0);
  resistance=(float)(1023-a)*10000/a; //get the resistance of the sensor;
  temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;//convert to temperature via datasheet ;
  if (isnan(temperature)) {
     temperature == 1000; // error
     return;
  }
  Serial.println(temperature);
 }

weather.js

Plain text
//this code is from Samsung's blog: https://blog.samsungsami.io

var sami = "https://api.samsungsami.io/v1.1/messages";
var bearer = "Bearer <INSERT_DEVICE_TOKEN";
var sdid = "<INSERT_DEVICE_ID";

var serialport = require("serialport")
var SerialPort = serialport.SerialPort;
var sp = new SerialPort("/dev/<INSERT_COM_PORT>", {
	baudrate: 9600,
	parser: serialport.parsers.readline("\n")
});

var Client = require("node-rest-client").Client;
var c = new Client();


function build_args (temp, ts) {

	var args = {
		headers: {
			"Content-Type": "application/json",
			"Authorization": bearer 
		},  
		data: { 
    			"sdid": sdid,
			"ts": ts,
			"type": "message",
			"data": {
        			"temperature": temp
    			}
		}
	};
	return args;
}

sp.on("open", function () {
	sp.on('data', function(data) {
		var args = build_args(parseInt(data).toString(), new Date().valueOf());

		c.post(sami, args, function(data, response) {            
			console.log(data);
        	});	    
	});
});

Credits

Monica Houston

Monica Houston

76 projects • 451 followers
I don't live on a boat anymore.

Comments