Jump to content
Medsimo

CC3100 PUBNUB-FREEBOARD

Recommended Posts

 

Hello everyone !!

I have a small problem and it is the following:

First I'm simulating sensors with approximate random's values, and I need to upload this data to pubnub and freeboard as monitoring platform, the problem I have is that in pubnub I find the values updated in real time,  What happens, is that when I upload to freeboard are not updated, they take a fixed number.  

I am hesitating in the way of storing them, I think it is not appropriate.

I have the well-linked accounts between pubnub and freeboard.

 

Greetings. MR

this is my code !! 

 

#include <SPI.h>
#include <WiFi.h>
#include "PubNub.h"
#include <aJSON.h>

#define NUM_CHANNELS 4  // How many analog channels do you want to read 

double randomDouble(double min, double max, int numCasas){
  long _min = min * pow(10, numCasas) + 0.1;
  long _max = max * pow(10, numCasas) + 0.1;

  return (double) random(_min, _max) / pow(10, numCasas) ; 
}

int sn=0;

char pubkey[] = "***";
char subkey[] = "***";
char channel[] ="***";
char uuid[] =  "***";

// your network name also called SSID
char ssid[] = "***";
// your network password
char password[] = "***";
static int keyIndex = 0; 


void setup()
{

	Serial.begin(115200);
    randomSeed(analogRead(0));
	PubNub.begin(pubkey, subkey);
	PubNub.set_uuid(uuid);
	Serial.println("PubNub set up");
}

void loop()
{
  double Freq = randomDouble(10.71, 10.79, 2)+1839755.00;
  double voltage_1 = randomDouble(0.82, 0.88, 2);
  double temperature = randomDouble(18.30, 20.00, 2);
  double vol = randomDouble(3.10, 3.29, 2);
  
  double data[] = {Freq, voltage_1, temperature, vol};
  
  
	PubSubClient *client;
 
        // create JSON objects
        aJsonObject *msg, *dataReadings;
        msg = aJson.createObject();
        aJson.addItemToObject(msg, "DataReading", dataReadings = aJson.createObject());
        
        // get latest sensor values then add to JSON message
        for (int i = 0; i < NUM_CHANNELS; i++) {
          String Channel = String(data[i]);
          char charBuf[Channel.length()+1];
          Channel.toCharArray(charBuf, Channel.length()+1);
          double Values = data[i];
          aJson.addNumberToObject(dataReadings, charBuf, Values);
        }
        
        // convert JSON object into char array, then delete JSON object
        char *json_String = aJson.print(msg);
        aJson.deleteItem(msg);
        
        // publish JSON formatted char array to PubNub
	Serial.print("publishing a message: ");
	Serial.println(json_String);
        PubNub.publish(channel, json_String);
        free(json_String);
        
	delay(500);
}

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...