func recordSound(ctx context.Context, soundSensor *aio.GroveSoundSensorDriver) {
	soundStrength, soundErr := readSound(soundSensor)
	if soundErr != nil {
		log.Fatalf("Could not read value from sound sensors\n")
	} else {
		stats.Record(ctx, soundStrengthMeasure.M(int64(soundStrength)))
	}
}
Record the sound strength based on two kinds of aggregation.
One is distribution, the other is the lastValue.
package main
import (
	"context"
	"fmt"
	"log"
	"math"
	"os"
	"time"
	"contrib.go.opencensus.io/exporter/stackdriver"
	"github.com/d2r2/go-dht"
	"github.com/d2r2/go-logger"
	"go.opencensus.io/stats"
	"go.opencensus.io/stats/view"
	"go.opencensus.io/tag"
	"gobot.io/x/gobot"
	"gobot.io/x/gobot/drivers/aio"
	"gobot.io/x/gobot/drivers/i2c"
	"gobot.io/x/gobot/platforms/raspi"
)
var (
	viewSoundDist = &view.View{
		Name:        "opencensus.io/views/sound_strength_distribution",
		Description: "sound strength distribution over time",
		Measure:     soundStrengthMeasure,
		Aggregation: view.Distribution(0, 2, 4, 8, 16, 32, 64, 128),
	}
	viewSoundLast = &view.View{
		Name:        "opencensus.io/views/sound_strength_instant",
		Description: "sound strength instantly over time",
		Measure:     soundStrengthMeasure,
		Aggregation: view.LastValue(),
	}
	viewLight = &view.View{
		Name:        "opencensus.io/views/light_strength_instant",
		Description: "voltage level on GPIO over time",
		Measure:     lightStrengthMeasure,
		Aggregation: view.LastValue(),
	}
	viewHumidity = &view.View{
		Name:        "opencensus.io/views/humidity_instant",
		Description: "humidity_over time",
		TagKeys:     []tag.Key{sensorKey},
		Measure:     humidityMeasure,
		Aggregation: view.LastValue(),
	}
	viewTemperature = &view.View{
		Name:        "opencensus.io/views/temperature_instant",
		Description: "temperature over time",
		TagKeys:     []tag.Key{sensorKey},
		Measure:     temperatureMeasure,
		Aggregation: view.LastValue(),
	}
	soundStrengthMeasure = stats.Int64("opencensus.io/measure/sound_strength_svl_mp1_7c3c", "strength of sound", stats.UnitDimensionless)
	lightStrengthMeasure = stats.Int64("opencensus.io/measure/light_strength_svl_mp1_7c3c", "strength of light", stats.UnitDimensionless)
	humidityMeasure      = stats.Float64("opencensus.io/measure/humidity_svl_mp1_7c3c", "humidity", stats.UnitDimensionless)
	temperatureMeasure   = stats.Float64("opencensus.io/measure/temperature_svl_mp1_7c3c", "temperature", stats.UnitDimensionless)
	soundSamplePeriod       = 50 * time.Millisecond
	temperatureSamplePeriod = 5 * time.Second
	sensorKey tag.Key
	lg = logger.NewPackageLogger("main",
		logger.DebugLevel,
	)
)
func main() {
	ctx := context.Background()
	projectId := os.Getenv("PROJECTID")
	if projectId == "" {
		log.Fatal("Cannot detect PROJECTID in the system environment.\n")
	} else {
		log.Printf("Project Id is set to be %s\n", projectId)
	}
	var err error
	sensorKey, err = tag.NewKey("opencensus.io/keys/sensor")
	if err != nil {
		log.Fatal(err)
	}
	initOpenCensus(projectId, 1)
	go RecordTemperatureHumidity(ctx, 4)
	go RecordTemperatureHumidity(ctx, 17)
	board := raspi.NewAdaptor()
	ads1015 := i2c.NewADS1015Driver(board)
	soundSensor := aio.NewGroveSoundSensorDriver(ads1015, "0")
	lightSensor := aio.NewGroveLightSensorDriver(ads1015, "1")
	work := func() {
		gobot.Every(soundSamplePeriod, func() {
			recordSound(ctx, soundSensor)
			recordLight(ctx, lightSensor)
		})
	}
	robot := gobot.NewRobot("sensorDataCollection",
		[]gobot.Connection{board},
		[]gobot.Device{ads1015},
		work,
	)
	robot.Start()
}