Plugin WFN Data Review

Plugin offers weather data from Ambient, for the demo purpose the data lake units are being formed from various installation units at the Gulf location. This can be taken widely by setting up similar units across the globe, thus it forms a great data lake.

To execute or set up the weather data "Ambient" & how to contribute - Please wait for our directions.

Weather Data UI

The weather Data UI points to the link: https://wfn.goplugin.co/

Pre-requisites

You need the following information to test the weather data onto your contract using the Weather Data UI.

  • Oracle Address

  • Job ID

  • API endpoint

  • Environment endpoint

Steps For Using weather Data UI - Mainnet

  • Write and deploy your client contract using the network details

  • Fund it with PLI

  • Call your request method with the following input params

    • Oracle Address

      • 0x1948745008E2704f8784e6654f76458BfF0Cdae5

    • Job ID

      • 9ce06be377d846ed9333ef835a342e64

    • API Endpoint

      • gettempbyids

    • Environment endpoint

      • Wind

      • Temperature

      • RelativeHumidity

      • HeatIndex

Client Contract

pragma solidity 0.4.24;

import "@goplugin/contracts/src/v0.4/vendor/Ownable.sol";
import "@goplugin/contracts/src/v0.4/PluginClient.sol";

contract ClientContract is PluginClient, Ownable {
      
   //Initialize Oracle Payment    
   uint256 constant private ORACLE_PAYMENT = 0.01 * 10**18;
   uint256 public Temperature;
   uint256 public Humidity;
   uint256 public HeatIndex;
   uint256 public WindSpeed;
 
   //Initialize event RequestWeatherFulfilled  
   event RequestWeatherFulfilled(
       bytes32 indexed requestId,
       uint256 indexed weather
   );
 
   //Initialize event requestCreated  
   event requestCreated(address indexed requester,bytes32 indexed jobId, bytes32 indexed requestId);
 
   //Constructor to pass Pli Token Address during deployment
   constructor(address _pli) public Ownable() {
       setPluginToken(_pli);
   }
 
   //_endCheck should be in these categories(WindDirection,Temperature,WindChill)
   //_endpoint should be getlatesttemp
   //_jobID should be tagged in Oracle
   //_Oracle should be fulfiled with your plugin node address
 
   function requestTemperature(address _oracle, string _jobId,string _endpoint,string _envCheck,string _countryId,string _stateId,string _cityId,string _latlng)
       public
       returns (bytes32 requestId)
   {
       Plugin.Request memory req = buildPluginRequest(stringToBytes32(_jobId), this, this.fulfillTemperature.selector);
       req.add("endpoint",_endpoint);
       req.add("envCheck",_envCheck);
       req.add("country",_countryId);
       req.add("state",_stateId);
       req.add("city",_cityId);
       req.add("latlng",_latlng);
       req.addInt("times", 100);
       requestId = sendPluginRequestTo(_oracle, req, ORACLE_PAYMENT);
       emit requestCreated(msg.sender, stringToBytes32(_jobId), requestId);
   }
 
 
   function requestHumidity(address _oracle, string _jobId,string _endpoint,string _envCheck,string _countryId,string _stateId,string _cityId,string _latlng)
       public
       returns (bytes32 requestId)
   {
       Plugin.Request memory req = buildPluginRequest(stringToBytes32(_jobId), this, this.fulfillHumidity.selector);
       req.add("endpoint",_endpoint);
       req.add("envCheck",_envCheck);
       req.add("country",_countryId);
       req.add("state",_stateId);
       req.add("city",_cityId);
       req.add("latlng",_latlng);
       req.addInt("times", 100);
       requestId = sendPluginRequestTo(_oracle, req, ORACLE_PAYMENT);
       emit requestCreated(msg.sender, stringToBytes32(_jobId), requestId);
   }
 
 
   function requestWindSpeed(address _oracle, string _jobId,string _endpoint,string _envCheck,string _countryId,string _stateId,string _cityId,string _latlng)
       public
       returns (bytes32 requestId)
   {
       Plugin.Request memory req = buildPluginRequest(stringToBytes32(_jobId), this, this.fulfillWindSpeed.selector);
       req.add("endpoint",_endpoint);
       req.add("envCheck",_envCheck);
       req.add("country",_countryId);
       req.add("state",_stateId);
       req.add("city",_cityId);
       req.add("latlng",_latlng);
       req.addInt("times", 100);
       requestId = sendPluginRequestTo(_oracle, req, ORACLE_PAYMENT);
       emit requestCreated(msg.sender, stringToBytes32(_jobId), requestId);
   }
 
   function requestHeatIndex(address _oracle, string _jobId,string _endpoint,string _envCheck,string _countryId,string _stateId,string _cityId,string _latlng)
       public
       returns (bytes32 requestId)
   {
       Plugin.Request memory req = buildPluginRequest(stringToBytes32(_jobId), this, this.fulfillHeatIndex.selector);
       req.add("endpoint",_endpoint);
       req.add("envCheck",_envCheck);
       req.add("country",_countryId);
       req.add("state",_stateId);
       req.add("city",_cityId);
       req.add("latlng",_latlng);
       req.addInt("times", 100);
       requestId = sendPluginRequestTo(_oracle, req, ORACLE_PAYMENT);
       emit requestCreated(msg.sender, stringToBytes32(_jobId), requestId);
   }
   //callBack function
   function fulfillTemperature(bytes32 _requestId, uint256 _weather)
       public
       recordPluginFulfillment(_requestId)
   {
       emit RequestWeatherFulfilled(_requestId, _weather);
       Temperature = _weather;
   }
 
   //callBack function
   function fulfillHeatIndex(bytes32 _requestId, uint256 _weather)
       public
       recordPluginFulfillment(_requestId)
   {
       emit RequestWeatherFulfilled(_requestId, _weather);
       HeatIndex = _weather;
   }
 
 
   //callBack function
   function fulfillWindSpeed(bytes32 _requestId, uint256 _weather)
       public
       recordPluginFulfillment(_requestId)
   {
       emit RequestWeatherFulfilled(_requestId, _weather);
       WindSpeed = _weather;
   }
 
 
   //callBack function
   function fulfillHumidity(bytes32 _requestId, uint256 _weather)
       public
       recordPluginFulfillment(_requestId)
   {
       emit RequestWeatherFulfilled(_requestId, _weather);
       Humidity = _weather;
   }
 
   function getPluginToken() public view returns (address) {
       return pluginTokenAddress();
   }
 
   //With draw pli can be invoked only by owner
   function withdrawPli() public onlyOwner {
       PliTokenInterface pli = PliTokenInterface(pluginTokenAddress());
       require(pli.transfer(msg.sender, pli.balanceOf(address(this))), "Unable to transfer");
   }
 
   //Cancel the existing request
   function cancelRequest(
       bytes32 _requestId,
       uint256 _payment,
       bytes4 _callbackFunctionId,
       uint256 _expiration
   )
       public
       onlyOwner
   {
       cancelPluginRequest(_requestId, _payment, _callbackFunctionId, _expiration);
   }
 
   //String to bytes to convert jobid to bytest32
   function stringToBytes32(string memory source) private pure returns (bytes32 result) {
       bytes memory tempEmptyStringTest = bytes(source);
       if (tempEmptyStringTest.length == 0) {
       return 0x0;
       }
       assembly {
       result := mload(add(source, 32))
       }
   }
   }

Deploy the above ClientContract using http://remix.ethereum.org/. Once the contract is deployed, it has to be funded(0.2 PLI). For the sake of convenience, we can call the address of this contract CC for now.

After deployment, you should fund your client contract with PLI(0.2 PLI)

After the contract is funded it has to be flattened using remix, for the convenience of the user the flattened form of the ClientContract is provided below.

Now you can go to the weather Data UI - link

WEATHER INFO

Select the filtering criteria like 'City', 'State', and 'Country' and click 'Show', you will be getting the latest weather info of the place you selected. After getting the result, move to the 'BLOCKCHAIN INFO' tab.

BLOCKCHAIN INFO

Deploy your contract tab details:

1) Select the 'Deploy your contract' tab and paste the flattened form of the contract and make sure you have selected the 'Mainnet' selection button and not 'Apothem', then press compile, after successful compilation you should get the ABI as the resultant.

2) Make sure you have XDC wallet installed and the account is pointing to 'mainnet', now click on the Deploy button. Now you should have got 'View Transaction' at the bottom, right-click on that and verify whether the transaction succeeded.

3) Copy and paste the 'ABI' contents from this page to a notepad.

Push Weather tab details:

1) Paste the copied ABI into the ABI field, client contract address (which is mentioned above as CC) into the 'Contract Address' field, oracle address, and job id to the respective fields.

2) Select an 'Environmental check' and click on Submit.

3) Once the transaction is done successfully you will get the 'View Transaction' button, click on it and verify the transaction status as 'success'. On the same page you can find the 'To:' field, copy the address in this field, and fund the address with 0.1 PLI

Show Weather tab details:

1) Paste the address which you copied and fund the same in 'Weather tab details' into 'Request Contract' field. Make sure you replaced the 'xdc' to '0x' at the start of the address.

2) Paste the ABI content into the 'ABI' field, select the 'Environmental check' field which you pushed and click submit, you will be receiving the weather details whatever you just pushed onto the plugin blockchain.

10 DAYS RECORD

In this tab the user can witness the 10 days of data for the selected location. Currently, the weather details include Temperature, Wind, Humidity and, HeatIndex.

Last updated