CAVEDU Education
Published © GPL3+

LattePanda IoT - Mediatek Cloud Sandbox

Using DFrobot LattePanda to upload sensor data to MCS cloud service.

AdvancedFull instructions provided3 hours205
LattePanda IoT - Mediatek Cloud Sandbox

Things used in this project

Hardware components

LattePanda 4GB/64GB
LattePanda 4GB/64GB
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Photo resistor
Photo resistor
×1

Story

Read more

Schematics

3-10_LsqOQPRUHo.png

Code

mcs.py

Python
uppload data to MCS
import serial
import time
import requests

ser = serial.Serial('COMX',9600) 

device_id = "Your device ID"
device_key = "Your device Key"

data_channel = "sensor"
data_channel +=",,"
url = "http://api.mediatek.com/mcs/v2/devices/" + device_id
url += "/datapoints.csv"

def MCS_upload(value,length):
        data = data_channel+str(value)
        r = requests.post(url,headers = {"deviceKey" : device_key,'Content-Type':'text/csv'},data=data)
        print r.text

print "Start"
while True:
        if ser.read()=='a':
                IncommingNum = ser.read()
                sensor = int(ser.read(int(IncommingNum)))
                a = 8
                a += int(IncommingNum)
                MCS_upload(sensor,a)

mcs.js

JavaScript
upload data to MCS
var mcs = require('mcsjs');
var SerialPort = require("serialport").SerialPort;
var serialPort = new SerialPort("COMX",
{baudrate: 9600
});

var myApp = mcs.register({
        deviceId: 'your device ID',
        deviceKey: 'your device Key',
});

serialPort.on("open", function () {
        receivedData ="";
        serialPort.on('data',function(data)
        {
                receivedData =data.toString();
                a = receivedData.length;
                myApp.emit('sensor','', receivedData.substring(2,a));
                //trim length a from string[2] to get the data
        });
});

Arduino sketch

Arduino
send data from lattepanda's Arduino to python/node.js
#define sensorPin A0

void setup() {
  Serial.begin(9600);    //Serial monitor
  Serial1.begin(9600);  //LattePanda-Arduino serial 
}

void loop() {
  int Sensor = analogRead(sensorPin);
  Serial.println(Sensor);   //show A0 pin status
  Serial1.print('a');
  Serial1.print(String(Sensor).length());
  Serial1.print(Sensor);        
  //#11~#13 is a packet with header'a', data length and data
  delay(1000);
}

Credits

CAVEDU Education

CAVEDU Education

11 projects • 28 followers
We provide tutorials of robotics, Arduino, Raspberry Pi and IoT topics. http://www.cavedu.com

Comments