Craig Mulligan
Published

ARTIK and ARTIK Cloud tutorial

Deploy a demo application to the Samsung ARTIK with resin.io and send data to ARTIK cloud.

BeginnerProtip1 hour1,288

Things used in this project

Hardware components

ARTIK 10
Samsung ARTIK 10
×1
ARTIK 5
Samsung ARTIK 5
×1

Software apps and online services

balenaCloud
balenaCloud
ARTIK Cloud for IoT
Samsung ARTIK Cloud for IoT

Story

Read more

Code

Code snippet #1

Plain text
  {
    "name": "reading",
    "type": "CUSTOM",
    "valueClass": "Integer",
    "isCollection": false,
    "tags": []
  }

Code snippet #2

Plain text
# base-image for node on any machine using a template variable,
# see more about dockerfile templates here:http://docs.resin.io/pages/deployment/docker-templates
FROM resin/%%RESIN_MACHINE_NAME%%-node

# Save source folder
RUN printf "%s\n" "${PWD##}" > SOURCEFOLDER

# Move to /usr/src/app
WORKDIR /usr/src/app

# Move package to filesystem
COPY "$SOURCEFOLDER/app/package.json" ./

# Install NodeJS dependencies via NPM
RUN JOBS=MAX npm i --unsafe-perm --production && npm cache clean

# Move app to filesystem
COPY "$SOURCEFOLDER/app/index.js" ./

# Start app
CMD ["node", "/usr/src/app/index.js"]  

Code snippet #3

Plain text
function getReading(cb){  
  // got a sensor ?
  read_adc0(function(reading){
    if (reading != 0) {
      // sensor connected
      cb(reading)
    } else {
      // no sensor connected so generate a value
      cb(generateRandomVal(sensor_threshold))
    }
  });
}

Code snippet #4

Plain text
/*
Function that enables and reads proximity sensor  
*/
function enable_proximity_sensor() {  
  console.log('Monitoring for movement');

  setInterval(function() {
    getReading(function(reading){
      console.log('Sensor reading: ' + reading)
      if (reading > sensor_threshold) {
        console.log('pushing event to ARTIK Cloud');
        push2ArtikCloud(reading);
      }
    })
  }, poll_interval);
}

Code snippet #8

Plain text
  {
    "name": "reading",
    "type": "CUSTOM",
    "valueClass": "Integer",
    "isCollection": false,
    "tags": []
  }

Code snippet #9

Plain text
# base-image for node on any machine using a template variable,
# see more about dockerfile templates here:http://docs.resin.io/pages/deployment/docker-templates
FROM resin/%%RESIN_MACHINE_NAME%%-node

# Save source folder
RUN printf "%s\n" "${PWD##}" > SOURCEFOLDER

# Move to /usr/src/app
WORKDIR /usr/src/app

# Move package to filesystem
COPY "$SOURCEFOLDER/app/package.json" ./

# Install NodeJS dependencies via NPM
RUN JOBS=MAX npm i --unsafe-perm --production && npm cache clean

# Move app to filesystem
COPY "$SOURCEFOLDER/app/index.js" ./

# Start app
CMD ["node", "/usr/src/app/index.js"]  

Code snippet #10

Plain text
function getReading(cb){  
  // got a sensor ?
  read_adc0(function(reading){
    if (reading != 0) {
      // sensor connected
      cb(reading)
    } else {
      // no sensor connected so generate a value
      cb(generateRandomVal(sensor_threshold))
    }
  });
}

Code snippet #11

Plain text
/*
Function that enables and reads proximity sensor  
*/
function enable_proximity_sensor() {  
  console.log('Monitoring for movement');

  setInterval(function() {
    getReading(function(reading){
      console.log('Sensor reading: ' + reading)
      if (reading > sensor_threshold) {
        console.log('pushing event to ARTIK Cloud');
        push2ArtikCloud(reading);
      }
    })
  }, poll_interval);
}

Github

https://github.com/resin-io-projects/resin-artik-cloud-publisher

Github file

https://help.github.com/articles/checking-for-existing-ssh-keys/

Github file

https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/

Credits

Craig Mulligan

Craig Mulligan

8 projects • 24 followers

Comments