CC3220SF LaunchPad is a low-cost IoT development board designed by Texas Instruments. It has buttons, LEDs, onboard Bosch BMA222 accelerometer and onboard TI TMP006 temperature sensor. This tutorial provides the easiest way to start IoT development with CC3220, Mongoose OS and Google IoT Core, and covers the following:

  1. Install gcloud command line tool
  2. Follow the Google IoT Core configuration instructions
  3. Login to Google IoT Core Console. Make sure you have your device registry created, and you have your device listed on it.
  1. Download and install TI CCS Uniflash
  2. Download and install Mongoose OS mos tool
  3. Connect CC3220SF LaunchPad to your computer via a micro-USB cable
  4. Start mos tool. A Web UI will appear, with the connection dialog
  5. Select "Serial Port" click Connect
  6. Choose "cc3220" platform, "demo-js" app, click Flash. If you see Tick uptime: device logs appear but Flash button still spinning, restart mos tool.
  7. Enter your WiFi credentials, click "Save"
  8. Click "Done". That should open the init.js file which you can edit and upload to your device by clicking on the button in the toolbar.
Troubleshooting: post on Mongoose OS forum or talk on Mongoose OS chat.

In this tutorial we are going to provision the board and connect it to Google IoT Core.

  1. Follow instructions on Google IoT Core setup
  2. Follow instructions on Setup device side
  3. Open mos Web UI
  4. Make sure that the device is connected to WiFi: a "device setup" icon is green.
  5. Watch the device logs after reboot, you should be seeing the MQTT CONNACK 0 message:
    [Nov 27 00:51:12.342] _poll        New heap free LWM: 215880
    mgos_sntp_ev         SNTP reply from 52.48.113.20: time 1511743872.824787, local 1511743873.394000, delta -0.569[Nov 27 00:51:12.438] 213
    mgos_mqtt_ev         MQTT CONNACK 0
  6. Open Google IoT console, make sure your device appears in the iot-registry device registry.

In this tutorial, we'll send a message to Google IoT Core on a button press.

  1. In the mos Web UI, open the init.js file
  2. Copy/paste the following code:
    load('api_config.js');
    load('api_gpio.js');
    load('api_timer.js');
    load('api_mqtt.js');
    
    let topic = '/devices/' + Cfg.get('device.id') + '/state';
    let pin = Cfg.get('pins.button');
    
    GPIO.set_mode(pin, GPIO.MODE_INPUT);
    GPIO.set_pull(pin, GPIO.PULL_DOWN);
    GPIO.set_button_handler(pin, GPIO.PULL_DOWN, GPIO.INT_EDGE_NEG, 200, function() {
      let msg = JSON.stringify({ time: Timer.now() });
      let ok = MQTT.pub(topic, msg, 1);
      print(ok, msg);
    }, null);
  3. Click the upload button. Wait until device reboots.
  4. Press on a push button to send a message.
  5. Open Google IoT Core console in another browser tab, go to the iot-registry registry, click on your device, and then on "Configuration and state history" tab
  6. Click refresh button, click on State, and choose Text representation.

In this tutorial, we'll implement remote LED control using Google IoT core config object.

  1. In the mos Web UI, open the init.js file
  2. Copy/paste the following code:
    load('api_config.js');
    load('api_gpio.js');
    load('api_mqtt.js');
    
    let topic = '/devices/' + Cfg.get('device.id') + '/config';
    let led = Cfg.get('pins.led');
    
    GPIO.set_mode(led, GPIO.MODE_OUTPUT);
    MQTT.sub(topic, function(conn, topic, msg) {
      print('Topic:', topic, 'message:', msg);
      let obj = JSON.parse(msg) || { on: false };
      GPIO.write(led, obj.on ? 1 : 0);
    }, null);
  3. Click the upload button. Wait until device reboots.
  4. Press on a push button to send a message.
  5. Open Google IoT Core console in another browser tab, go to the iot-registry registry, click on your device, and then on "Configuration and state history" tab
  6. Click on "Update Config" Button. Enter {"on": true}, click "Send to Device"
  7. Notice the log message from a device, and LED changing its color.
  8. Update the config several times, change "on" from true to false and back, see how device reacts.