【发布时间】:2019-04-07 21:44:17
【问题描述】:
我已按照 AWS 网站上的示例进行操作 https://aws-amplify.github.io/docs/js/pubsub
无论我每次跑步时会发生什么 等待 PubSub.publish 我没有收到 AWS 的回复。任何帮助,将不胜感激。 我的代码超时了。
Triend 通过 MQTT react-native 与 AWS 交互的不同方式。到处找。没有使用这个的例子。
import Amplify, { PubSub, Auth } from 'aws-amplify';
import { AWSIoTProvider } from '@aws-amplify/pubsub/lib/Providers';
import aws_exports from './src/aws-exports';
// aythentication import
import { withAuthenticator } from 'aws-amplify-react-native';
Amplify.configure(aws_exports);
Amplify.addPluggable(new AWSIoTProvider({
aws_pubsub_region: 'us-east-1',
aws_pubsub_endpoint: 'wss://azk3aah4ivg82-ats.iot.us-east-1.amazonaws.com/mqtt',
}));
PubSub.subscribe(['$aws/things/B_Bone_1/shadow/get/accepted', '$aws/things/B_Bone_1/shadow/get/rejected']).subscribe({
next: data => console.log('Message received get accepted', data),
error: error => console.error(error),
close: () => console.log('Done'),
});
//
export default class Main extends React.Component {
//...... sign in stuff This just makes a cognito accound and lets me log in. Its working
}
class App extends Component {
//constuct props
///...
update = async () => {
await PubSub.publish('$aws/things/B_Bone_1/shadow/update', {msg: '{"state":{"reported":{"temp": -1}}}' });
Alert.alert('Update all local values from Device Shadow');
}
render() {
return (
//A page with a button that runs update function
);
}}
//Stylesheet stuff
当调用 update 时,程序应该运行 subscribe 函数。但我得到一个超时错误,因为没有返回任何内容。 任何帮助都会很棒。
【问题讨论】:
标签: javascript amazon-web-services react-native iot publish-subscribe