Last active
July 22, 2017 00:42
-
-
Save shyampurk/100784ded22531d1dacd to your computer and use it in GitHub Desktop.
Smart Parking App
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
/***************************************************************************/ | |
/*PubNub C-Core Initialization*/ | |
pubnub_t *l_receive = pubnub_alloc(); | |
if (NULL == l_receive) | |
{ | |
printf("Failed to allocate Pubnub context!\n"); | |
return (void *)-1; | |
} | |
pubnub_init(l_receive, "demo", "demo"); | |
/***************************************************************************/ | |
/***************************************************************************/ | |
/*PubNub Javascript SDK Initialization */ | |
pubnub = PUBNUB({ | |
publish_key: 'demo', | |
subscribe_key: 'demo' | |
}) | |
/***************************************************************************/ |
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
pubnub.subscribe({ | |
channel: "parkingstatus-resp", | |
message: function(message, env, ch, timer, magic_ch) { | |
$.mobile.loading( "hide" ); | |
var currentStatus = Object.keys(message).reverse().map(function(key) { | |
return codeColor[message[key]] | |
}) | |
$('.parking-spot').each(function(i, elem) { | |
$(elem).removeClass("available unavailable occupied").addClass(currentStatus[i]) | |
}) | |
}, | |
connect: pub | |
}) | |
function pub() { | |
console.log("Since we’re publishing on subscribe connectEvent, we’re sure we’ll receive the following publish."); | |
pubnub.publish({ | |
channel: "parkingstatus-req", | |
message: { | |
"Requester": "APP", | |
"Device ID": 0, | |
"Request Type": 4, | |
"Request Value": 0 | |
}, | |
callback: function(m) { | |
console.log(m) | |
} | |
}) | |
} |
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
int uartInit(void) | |
{ | |
g_uart0_filestream = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY | O_NDELAY); | |
if(g_uart0_filestream == -1) | |
{ | |
printf("Error Connecting with the Device \n"); | |
return -1; | |
} | |
//Setting the Baud Rate and No. of the Stop Bits for the UART | |
struct termios options; | |
tcgetattr(g_uart0_filestream,&options); | |
//BAUD Rate Initialized to 9600 bps | |
options.c_cflag = B9600 | CS8 | CLOCAL | CREAD; | |
options.c_iflag = IGNPAR; | |
options.c_oflag = 0; | |
options.c_lflag = 0; | |
tcflush(g_uart0_filestream, TCIFLUSH); | |
tcsetattr(g_uart0_filestream,TCSANOW,&options); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment