Medsimo

CC3100 PUBNUB-FREEBOARD

1 post in this topic

 

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now