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 = require('pubnub'); | |
var pubnub = new PubNub({ | |
publish_key : "pub...", | |
subscribe_key : "sub..." | |
}); | |
var five = require('johnny-five'); | |
var board = new five.Board(); | |
var LED3_RED; | |
var LED3_GREEN; |
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
import 'package:flutter/services.dart'; | |
import 'dart:convert'; | |
… | |
class _MyHomePageState extends State<MyHomePage> { | |
... | |
static const subscriber = const MethodChannel('flutter.native/subscriber'); |
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
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
GeneratedPluginRegistrant.registerWith(this) | |
val pnConfiguration = PNConfiguration() | |
pnConfiguration.setSubscribeKey("sub-...") | |
pnConfiguration.setPublishKey("pub-...") | |
val pubnub = PubNub(pnConfiguration) | |
val channelName = "flutter_iot" |
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
… | |
dependencies { | |
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | |
testImplementation 'junit:junit:4.12' | |
androidTestImplementation 'com.android.support.test:runner:1.0.2' | |
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | |
implementation group: 'com.pubnub', name: 'pubnub-gson', version: '4.24.0' | |
} |
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
... | |
import 'package:http/http.dart' as http; | |
... | |
Future<String> getData(int action) async { | |
http.Response response = await http.get( | |
Uri.encodeFull( | |
"https://ps.pndsn.com/publish/pubkey/subkey/0/flutter_iot_lamp/0/{\"action\":$action}?uuid=db..."), | |
); |
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
… | |
void _turnOn() { | |
print("on"); | |
} | |
void _turnOff() { | |
print("off"); | |
} | |
@override |
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
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), |
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
private val PUB_SUB_STRATEGY = Strategy.Builder().setTtlSeconds(Strategy.TTL_SECONDS_MAX).build() | |
private val PUB_OPTIONS = PublishOptions.Builder() | |
.setStrategy(PUB_SUB_STRATEGY) | |
.setCallback(object : PublishCallback() { | |
override fun onExpired() { | |
"Experid message".toast(this@MainActivityK); | |
} | |
}) | |
.build() |
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
private final Strategy PUB_SUB_STRATEGY = new Strategy.Builder() | |
.setTtlSeconds(Strategy.TTL_SECONDS_MAX).build(); | |
private final PublishOptions PUB_OPTIONS = new PublishOptions.Builder() | |
.setStrategy(PUB_SUB_STRATEGY) | |
.setCallback(new PublishCallback(){ | |
@Override | |
public void onExpired() { | |
Toast.makeText( | |
MainActivity.this, |
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
@Override | |
public void onStart() { | |
super.onStart(); | |
Nearby.getMessagesClient(this).subscribe(mMessageListener); | |
} | |
@Override | |
public void onStop() { | |
if (message != null) |