The author order

What? Five lines of code can be embedded to achieve user positioning, the number of users online statistics, and cloud message interaction!

Yes, thanks to ali Cloud Internet of Things kit to create equipment for free, the message charge is only three million messages six yuan (use after payment, dissatisfaction, no money), especially for the student party, basically can not use so much, which means free! (Student Party Gospel [Manual funny])

Talk is cheap,show me the code

Public static void main(String[] args) {public static void main(String[] args) {public static void main(String[] args) {public static void main(String[] args) { String productKey = "<your productKey>"; //english name only String deviceName = "anyDeviceName"; // create device constructor (productKey, deviceName) // if you already have a triplet (productKey, deviceName, // Simulator = new Simulator("<your productKey>", "<your deviceName>", "<your deviceSecret>"); simulator.connect(msgJson -> { System.out.println("received: " + msgJson); });});});}); // Can be placed in devices with location, mobile phones, watches, etc. UplinkMessage = new UplinkMessage(). Put ("GeoLocation", New GeoLocation (122.250852 f, 30.193851 f, 12 f, 2)); / / can report according to the product definition extra attributes / /. The put (" PM25 ", 60) / /. The put (" CO2Value ", 123) / /. The put (" HeatSwitch ", 0) / /. The put (" LightSwitch ", 1); simulator.uplink(uplinkMessage); }Copy the code

(Ahem, about five lines.) Take a look at the comments in the code. The sparrow is small, but it has all the organs.

The overall directory structure is such that it will soon be put on Github and the urgently needed soldering iron can be put into the main code of the Nail group 21939141

How to use

Usage seems relatively simple, requiring only three key keys:

  1. ProductKey (passed into the Simulator constructor)
  2. AppKey (configure to api.json)
  3. AppSecret(configure to api.json)

These three keys do not need to be coded, but can be applied on Ali Cloud. Look at the breakdown action:

productKey

  1. Visit ali Cloud Internet of Things console to create an advanced version of the product (the advanced version also does not charge, more powerful), select the classification of custom, we will define the function for him later.
  2. Look at your product and add a geolocation feature to the feature definition (select one after searching for other types)
  3. Knock on the blackboard!! Take out a notebook and memorize your ProductKey

AppKey&AppSecret

  1. Access the iot Developer Platform console to create a custom project
  2. Go to your project and click Software Development > Web Applications on the left menu bar to create a Web application (front-end Application)
  3. Click into your Web application and you’ll see AppKey and AppSecret
  4. Knock on the blackboard!! Take out a notebook and memorize your AppKey and AppSecret

Ready? Go!

  1. After all the parameters are set, run the program.
  2. To create a 2d scene in spatial data visualization, select the product you created earlier.
  3. If all goes well, here’s what you’ll see

Sorry, the device was named girlFriend — and set to the ocean.

Of course, you can also use it to count the number of clients (users) and the number of messages sent and received

Enjoy!