-
-
Save domadev812/365587c8d50108a2ff614d02e944a12d to your computer and use it in GitHub Desktop.
Code chunks from project javamon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Publish the value using PubNub | |
static void publishMsg (void) | |
{ | |
// Check values for I2C line error... | |
if (TWI_msg[0] > 99 || TWI_msg[1] > 99) { | |
TWI_fullMsg = 10000; | |
} | |
// Ignore very small values | |
else if (TWI_msg[0] == 0 && TWI_msg[1] < 50) { | |
TWI_fullMsg = 0; | |
} | |
// Record full value and round to nearest 10 | |
else { | |
int mod = TWI_msg[1] % 10; | |
TWI_msg[1] /= 10; | |
if (mod > 4) | |
++TWI_msg[1]; | |
TWI_msg[1] *= 10; | |
TWI_fullMsg = (uint16_t)TWI_msg[1] + 100 * (uint16_t)TWI_msg[0]; | |
} | |
// Only publish if this is a new value or it's been a while... | |
if((TWI_fullMsg != TWI_lastMsg) || TIME_TO_PUBLISH) { | |
char buf[40] = { 0, }; | |
sprintf(buf, "{\"columns\":[[\"Coffee\",\"%d\"]]}", TWI_fullMsg); | |
pubnub_publish(channel, buf); | |
TWI_lastMsg = TWI_fullMsg; | |
stat_flag &= ~REQUEST_PUBLISH; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Callback - Called when a connection to PubNub is made | |
static void IFA PN_connectedCB(void) | |
{ | |
// Do Stuff once connected to PubNub | |
} | |
// Callback - Called when on PubNub connection error | |
static void IFA PN_connErrorCB(sint8 error) | |
{ | |
// Do stuff on Connection error | |
// Maybe request a device reset! | |
} | |
// ... | |
// Called after connection to WiFi is established... | |
pubnub_connect(PN_connectedCB, PN_connErrorCB); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Creates a connection to Pubnub | |
* This should be called when a network connection is established! | |
* User can specify functions to be called on certain events. | |
* | |
* @param connCB callback for connection success event | |
* @param connErrCB callback for connection error events | |
*/ | |
void IFA pubnub_connect(Pubnub_connectedCB connCB, Pubnub_connErrorCB connErrCB); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eon.chart({ | |
pubnub: PUBNUB, | |
channels: ['eon-chart'], | |
limit: 20, | |
generate: { | |
bindto: '#body-spline' | |
} | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function historyCall(){ | |
var unixTime = Date.now() / 1000; // current time in seconds | |
var endTime = (unixTime - (5 * 60)); // get the time five minutes ago | |
pubnub.history( | |
{ | |
channel: 'javamon', | |
count: 1, // how many items to fetch | |
reverse: false, // Setting to true will traverse the time line in reverse starting with the oldest message first. | |
stringifiedTimeToken: true, // false is the default | |
start: '123123123123', // start time token to fetch | |
end: '123123123133' // end timetoken to fetch | |
}, | |
function (status, response) { | |
if (response[2] != 0) { // If there are no messages, this timetoken will be 0 | |
var publishConfig = { | |
channel : "javamon", | |
message : response[0][0]} | |
pubnub.publish(publishConfig, function(status, response) { | |
console.log(status, response); | |
}) | |
} | |
else { | |
} | |
} | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var pubnub = new PubNub({ | |
publishKey: 'demo', | |
subscribeKey: 'demo' | |
}); | |
var channel = "javamon"; | |
eon.chart({ | |
pubnub: pubnub, | |
channels: [channel] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment