Adrian Fernandez
Published

Cloud-connected SubGHz RF Star Sensor Network

Connect multiple low power sensor networks to the cloud!

BeginnerFull instructions provided1,524
Cloud-connected SubGHz RF Star Sensor Network

Things used in this project

Story

Read more

Schematics

MSP-EXP430G2 LaunchPad pin map

Pin mapping for MSP430G2553 LaunchPad

CC110L RF BoosterPack pin mapping

Code

CC110L RF Sensor Node

C/C++
This is the code for the MSP-EXP430G2 LaunchPad + CC110L RF BoosterPack + analog sensor
#include <SPI.h>
#include <AIR430BoostFCC.h>

// -----------------------------------------------------------------------------
/**
 *  Defines, enumerations, and structure definitions
 */

/**
 *  sPacket - packet format.
 */
struct sPacket
{
  uint8_t message[59];    // Local node message [MAX. 59 bytes]
};

// -----------------------------------------------------------------------------
/**
 *  Global data
 */
// Data to write to radio TX FIFO (60 bytes MAX.)
String myName = "AMF";
String mySensor = "Water";
int sensorPin = 6;
struct sPacket txPacket;

// -----------------------------------------------------------------------------
// Main example

void setup()
{
  // The radio library uses the SPI library internally, this call initializes
  // SPI/CSn and GDO0 lines. Also setup initial address, channel, and TX power.
  Radio.begin(0x01, CHANNEL_1, POWER_MAX);

  memset(txPacket.message, 0, sizeof(txPacket.message));

  // Setup serial for debug printing.
  Serial.begin(9600);

  pinMode(RED_LED, OUTPUT);       // Use red LED to display message reception
  digitalWrite(RED_LED, LOW);
}

void loop()
{
  digitalWrite(RED_LED, HIGH);
  int myData = analogRead(sensorPin);
  String json = "{\""+myName+"\":{";
  json = json+"\""+mySensor+"\":";
  json = json + myData;
  json = json + "}}\0";
  int payloadLength = json.length()+1;
  json.toCharArray((char*)txPacket.message, payloadLength); 
  Radio.transmit(ADDRESS_BROADCAST, (unsigned char*)&txPacket, sizeof(txPacket));
  Serial.println((char*)&txPacket);
  digitalWrite(RED_LED, LOW);
  delay(1000);    // Send every second
}

CC3200-based Wi-Fi connected RF Gateway

C/C++
This is code for the CC3200 Wi-Fi LaunchPad + CC110L RF BoosterPack.
#include <SPI.h>
#include <AIR430BoostFCC.h>
#include <WiFi.h>
#include <PubSubClient.h>

// your network name also called SSID
char ssid[] = "puglife";
// your network password
char password[] = "olliethepug";
// MQTTServer to use
char server[] = "iot.eclipse.org";

void callback(char* topic, byte* payload, unsigned int length) {
}

WiFiClient wifiClient;
PubSubClient client(server, 1883, callback, wifiClient);

// -----------------------------------------------------------------------------
/**
 *  Defines, enumerations, and structure definitions
 */

#define ADDRESS_LOCAL    0x01

/**
 *  sPacket - packet format.
 */
struct sPacket
{
  uint8_t from;           // Local node address that message originated from
  uint8_t message[59];    // Local node message [MAX. 59 bytes]
};

// -----------------------------------------------------------------------------
/**
 *  Global data
 */

struct sPacket rxPacket;

// -----------------------------------------------------------------------------
// Main example

void setup()
{
  Radio.begin(ADDRESS_LOCAL, CHANNEL_1, POWER_MAX);
  // Setup serial for debug printing.
  Serial.begin(9600);
  // attempt to connect to Wifi network:
  Serial.print("Attempting to connect to Network named: ");
  // print the network name (SSID);
  Serial.println(ssid); 
  // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
  WiFi.begin(ssid, password);
  while ( WiFi.status() != WL_CONNECTED) {
    // print dots while we wait to connect
    Serial.print(".");
    delay(300);
  }
  
  Serial.println("\nYou're connected to the network");
  Serial.println("Waiting for an ip address");
  
  while (WiFi.localIP() == INADDR_NONE) {
    // print dots while we wait for an ip addresss
    Serial.print(".");
    delay(300);
  }

  Serial.println("\nIP Address obtained");
  // We are connected and have an IP address.
  // Print the WiFi status.
  printWifiStatus();
  
  // The radio library uses the SPI library internally, this call initializes
  // SPI/CSn and GDO0 lines. Also setup initial address, channel, and TX power.


  rxPacket.from = 0;
  memset(rxPacket.message, 0, sizeof(rxPacket.message));



  /**
   *  Setup LED for example demonstration purposes.
   *
   *  Note: Set radio first to ensure that GDO2 line isn't being driven by the 
   *  MCU as it is an output from the radio.
   */
  pinMode(RED_LED, OUTPUT);       // Use red LED to display message reception
  digitalWrite(RED_LED, LOW);
}

void loop()
{
  // Reconnect if the connection was lost
  if (!client.connected()) {
    client.connect("cc3200_gateway");
    Serial.println("Connected to Broker");
  }
  
  // Turn on the receiver and listen for incoming data. Timeout after 1 seconds.
  // The receiverOn() method returns the number of bytes copied to rxData.
  if (Radio.receiverOn((unsigned char*)&rxPacket, sizeof(rxPacket), 1000) > 0)
  {
    digitalWrite(RED_LED, HIGH);
    Serial.print(" Publishing MSG: ");
    Serial.println((char*)rxPacket.message);
    client.publish("mySensorData",(char*)rxPacket.message);
    digitalWrite(RED_LED, LOW);
  }
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

Credits

Adrian Fernandez

Adrian Fernandez

10 projects • 45 followers
peek a boo my name is adrian

Comments

Add projectSign up / Login