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

EasyWork in progress1,352
Getting Started With ARTIK Cloud - Grove Weather Station

Things used in this project

Hardware components

SparkFun RedBoard
SparkFun RedBoard
×1
Grove starter kit plus for Intel Edison
Seeed Grove starter kit plus for Intel Edison
×1

Software apps and online services

ARTIK Cloud for IoT
Samsung ARTIK Cloud for IoT

Story

Read more

Schematics

Connecting the Temperature Sensor

Schematic

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

26 projects • 255 followers
I live on a boat. Microcontroller enthusiast. Web & App developer.

Comments

Add projectSign up / Login