automed IOS SDK

The automed SDK is now available to be integrated with your iOS application. This document will help you to understand our automed iOS Software Development Kit (SDK) and show you step by step how to use it in your iOS application

                 


Pre-requisites

  1. iOS IDE (Xcode is used in our example)
  2. iOS System Version 10+
  3. iOS Device

 


Step 1:

Use the following link to download the iOS SDK for apple applications

Click to download the automed iOS SDK


Step 2:

Open your iOS project in Xcode.  Select your project and then select your app target

 

Drag the automed SDK into ‘Embedded Binaries’

 

Make sure to enable ‘Copy items if needed’ and ‘Create groups’. Click Finish

Your ‘Embedded Binaries’ and ‘Linked Frameworks and Libraries’ should contain the automed SDK

Now we are ready to use the automed SDK in your application!


Step 3:

Import the automed SDK in your class (UIViewController class is preferred if you want the automed button in your view)

import automedSDK

In your class, create an automed object as a local variable and then in your viewDidAppear, assign your view controller object to the automed object.

class ViewController: UIViewController {
    
    var automed = automed()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
    
    override func viewDidAppear(_ animated: Bool) {
        automed = automed(vc: self)
    }

You can also create an automed floating button by calling this method in viewDidAppear

automed.createAutomedButton(x: CGFloat, y: CGFloat, width: CGFloat, height: CGFloat)

Now we can move to the next step: connect to the automed device


Step 4:

Use your iPhone to adjust some of the settings in order to connect to the automed device. The connection between your phone and the automed device is based on your phone’s hotspot.

Change your iPhone’s name to “AutoMed” in Settings->General->About->Name

Secondly, you need to change your iPhone’s hotspot password to ‘12345678’ in Settings->Personal Hotspot->WLAN Password. Turn the hotspot on.

At last, if you used the createAutomedButton function in your view controller, you can run your app on the iPhone directly. Otherwise, you need to put the connect function into your code

automed.connect()

To disconnect, simply call

automed.disconnect()

Once your app is running on your iPhone and you see there is at least one device connected to your iPhone’s hotspot, you can click or call the connect function to scan and connect to the automed device.


Step 5:

Once you have connected to the automed device successfully, you can use the two basic functions: Prime and RFID

1. Prime is the function to set the device in Prime mode. If you used the automed button, you can just click on it. Otherwise, you have to let the user select the device first. You can easily get the devices list by:

let devices = automed.devices

then you need to let the user choose one device from the list and call the prime function.

automed.prime(device: automedDevice)

Call this function again to turn off the Prime mode.

2. RFID is the function to set the device into RFID reading mode. Same setup as Prime. The only difference is there are two options: individual RFID mode and group RFID mode.

// for rfidMode, put 0 to 'stop RFID reading', put 1 to 'start individual RFID reading', put 2 to 'start group RFID reading'
automed.RFID(device: automedDevice, rfidMode: Int)

These two are basic functions to control the automed device. Next step is to configure the device and make it dose. The process is complex so make sure you follow the tutorial step by step.


Step 6 :

Get values you need to configure the adapter

What you need in your app:

  1. Token (Authorization)
  2. User ID (the user ID in our automed system)
  3. Farm ID (aka site ID)
  4. Industry type of users farm (can only be “Beef”, “Export Beef”, “Pork”, “Dairy Cattle”, “Dairy Sheep”, “Sheep”)
  5. amID (the medication ID in our automed system)

How to get:

  1. Token: you need to ask the users for their emails and passwords of their automed accounts to login. The function to call is:
    automedHttpService().login(email: email, password: password) { (status, json) in
                if status {
                    //succeed
                    let token = json!["token"] as! String
                }
                else {
                    //fail
                }
            }

    It is an Http GET request to get the token from our server so it needs an internet connection on your iPhone. It is a call back function. The status means if the request succeeds or not. The json is where contains the token. You need to store your token somewhere for later use.

  2. userID: once you have the token, you can call another function to get the user details
    automedHttpService().getUserDetail(token: token) { (status, json) in
                        if status {
                            //succeed
                            let userID = json!["id"] as! String
                        }
                        else {
                            //fail
                        }
                    }

    It is also an Http GET request to get the user details from our server so it needs an internet connection on your iPhone. It is a call back function. The status means if the request succeeds or not. The json is where contains the user ID. You need to store the user ID somewhere for later use and you don’t need additional information.

  3. farmID and industryType: same with userID, you can get them by calling:
    automedHttpService().getFarm(token: token) { (status, json) in
                        if status {
                            //succeed
                            for farm in json as! [[String : AnyObject]]{
                               let farmID = farm["id"] as! String
                               let industryType = farm["industry"] as! String
                            }
                        }
                        else {
                            //fail
                        }
                    }

    Note: User might have access to multiple farms. So the json here should be an array contains all farms’ information. You need to store farmID and industryType for each farm so the user can select it later.

  4. amID: Once you get the farmID, you can call this function:
    automedHttpService().getRefTreatmentData(farmId: farmID, token: token) { (status, json) in
                        if status {
                            //succeed
                            for refTreatment in json as! [[String : AnuObject]] {
                                //store refTreatment somewhere you want
                            }
                        }
                        else {
                            //fail
                        }
                    }

    Important Note: Your application must have your own medication management system. What you need to do once you get the refTreatment here is to connect your medication with the refTreatment’s medication. The best way to do it is to compare the name (in refTreatment we call it ‘amProduct’). Find the correct amID value in refTreatment for your medication. You will need it to configure the adapter of the automed device.


Step 7:

Configure the adapter of the automed device to make it dose

We have three dose types:

  1. Fix dose                                      (The device will do a fixed dose based on the medication that is configured to the adapter)
    automed.configureAdapterForFixDose(device: automedDevice, amID: amID, userID: userID, farmID: farmID, industryType: industryType)

    Input: device should be an automedDevice object; amID should be an Int; userID, farmID and industryType should be String

  2. Manual dose                              (The device will do the amount of dose which is input by the user.)
    automed.configureAdapterForManualDose(device: automedDevice, amID: amID, userID: userID, farmID: farmID, industryType: industryType, dose: doseValue)

    Input: device should be an automedDevice object; amID should be an Int; userID, farmID and industryType should be String; doseValue should be a Double

  3. Weight-based dose                   (The device will do the dose which is calculated by the weight of animals)
    automed.configureAdapterForWeightBasedDose(device: automedDevice, amID: amID, userID: userID, farmID: farmID, industryType: industryType, weight: weightValue)

    Input: device should be an automedDevice object; amID should be an Int; userID, farmID and industryType should be String; weightValue should be a Double

Important Note: Before configuring the weight-based dose, it is better to set the weight unit to be your preferred one. The default weight unit is ‘lbs’. You can set it by calling this function:

automed.setUnit(unit: "kg")
automed.setUnit(unit: "lbs")

Once the automed device and adapter is configured, the user can administer the dose and the treatment records will be stored in the local database of the iPhone. The next step is to show you how to get those records.

 


Step 8:

  1. Get the latest treatment record
    let treatment = automed.getLatestTreatmentRecord()
    print(treatment.getRefTreatmentsAmId())
    print(treatment.getTrDose())
    //you can check the other information of this record
  2. Get all treatment record in the local database
    let treatments = automed.getAllTreatmentRecords()
    for treatment in treatments {
        print(treatment.getRefTreatmentsAmId())
        print(treatment.getTrDose())
        //you can check other information of that treatment
    }
  3. Sync records from the automed device. We have a new feature called Set&Forget for the automed device. All treatments the user did without connecting to the app will store in the device itself. You need to call this function to get the records and store them into the local database
    automed.syncRecordsFromDevice(device: automedDevice)

    Note: you need to ask the user to select a device first before you call this function

 

The above steps should include all functions your app can have to control the automed device. Have fun and enjoy the development!


Demo

Here is a demo project to show you how to use the automed iOS SDK.

automed iOS SDK Demo project

 


More Information

There is more information stored in the automedDevice object such as MAC address, fwVer (firmware version of the device) and AdapterSettings (adapter settings). You can write your own code to get those value if you need. If you have any question about automed SDK for iOS or this tutorial, feel free to contact us at support@automed.io

Related Content

The following links relate to content within this document.

 

 

Still need help?

Can’t find the answer you’re looking for?
Don’t worry we’re here to help!

Request Support

Send us your question over email.

Phone

Send us your question over email.