Well, I haven’t been working with small programs for very long, but I’ve been using wild dogs for a long time, more than a year. You know what wild dogs are good at. So, I made a little program that monitors network latency, using wild dogs in the background. Let me tell you how I did it.







1. Back-end implementation


First, the network delay data of the relevant nodes of China Unicom and China Telecom is crawled by the way of network crawler (data crawling is done by Python).


After getting the data, the next thing to do is write the data into the dingo on the server. This is where I use the Dingo REST API. Dingo does not provide support for various languages, which makes sense when you think about it, since Firebase does not have a Python platform.


2. WXML&WXSS


The interface is written with Flex layout, no other tricks, it is a tool after all, not that complicated layout.


3. JavaScript


As mentioned above, I grab the data from various interfaces in Python and write it to Dingo through the REST API. Then through dingo’s wechat small program document that way, step by step to do the implantation:

  • Download wilddog-eapp-all. js to the root directory of the applet.

  • Add wilddog-eapp-all.js to the applet using require.

  • Set a data route to getDataList in app.js. Data routing do not understand you can go to the group owner’s blog…

  • In index.js, we use an onLoad method, with the next few points in the onLoad method:

    • Timer to control the page data update time, although the dingo data is updated in real time, but if the data update frequently will be very fast, let a person feel very unfriendly.

    • Obtain data in real time through dingo value event monitoring, but as mentioned above, the page data is not updated in real time, update once 250ms.

    • Nothing else.

    • Attached is a small program CODE I wrote:

  this.ref.child("/Unicom/Shanghai-Unicom").on('value',function(snapshot,prKey){
      clearTimeout(timer2)
      this.setData({
        ShanghaiUnicomValue:snapshot.val(),
        changed2: 'changed'
      })
      var timer2 = setTimeout(function() {
        self.setData({
          changed2: ''
        })
      },250)
    },this)Copy the code


Full source please download: download address

https://blog.wilddog.com/wp-content/uploads/2017/01/wilddog-ping-demo.zip