Creating a QR Code for Onboarding
Onboarding can be accelerated by creating a deep link embedded in a QR code that contains all Cozie settings. The link can be opened on the iPhone. Alternatively, the QR code can be scanned with the camera app on the iPhone. Both actions open the 'Settings' tab in the Cozie iPhone app. To complete the change of settings, open the Cozie Watch app and press the sync button in the 'Settings' tab of the Cozie iPhone app while the Cozie watch app is open. The transfer of the settings from the iPhone to the Apple Watch is successful if the first question of the watch survey is visible on the Apple Watch.
Deep link and QR code creation
Below is a code snippet that creates a deep link and corresponding QR code.
import json
import base64
import qrcode
from IPython.display import Image
# Onboarding payload with Cozie settings
id_participant = "example_participant_01"
id_experiment = "example_experiment"
id_password = "1G8yOhPvMZ6xx"
payload = (
f"{{"
f'"id_participant": "{id_participant}",'
f'"id_experiment": "{id_experiment}",'
f'"wss_title": "Thermal (long)",'
f'"wss_goal": 150,'
f'"wss_time_out": 3500,'
f'"wss_reminder_enabeled": true,'
f'"wss_participation_time_start": "09:00",'
f'"wss_participation_time_end": "18:00",'
f'"wss_participation_days": "Mo,Tu,We,Th",'
f'"wss_reminder_interval": 60,'
f'"pss_reminder_enabled": true,'
f'"pss_reminder_days": "Fr",'
f'"pss_reminder_time": "14:00",'
f'"api_read_url": "https://d3lupjxfs7.execute-api.ap-southeast-1.amazonaws.com/prod/read-influx",'
f'"api_read_key": " XsM7ks4lLU3JexCO8RjHG6nKq8yj9oBJ7bdI3R3R",'
f'"api_write_url": "https://d3lupjxfs7.execute-api.ap-southeast-1.amazonaws.com/prod/write-queue",'
f'"api_write_key": " XsM7ks4lLU3JexCO8RjHG6nKq8yj9oBJ7bdI3R3R",'
f'"app_one_signal_app_id": "be00093b-ed75-4c2e-81af-d6b382587283",'
f'"id_password": "{id_password}",'
f'"api_watch_survey_url": "https://www.cozie-apple.app/watch_surveys/watch_survey_example.json",'
f'"api_phone_survey_url": "https://docs.google.com/forms/d/e/1FAIpQLSfOj7_vVRUNDHELmwQqvpFYF5m1p6IXpXaWsQgHOF8HxuTmrw/viewform?usp=pp_url&entry.32388053={id_participant}&entry.1973683772={id_experiment}"'
f"}}"
)
# Convert payload to deep link
payload_bytes = payload.encode("ascii")
base64_bytes = base64.b64encode(payload_bytes)
base64_payload = base64_bytes.decode("ascii")
deep_link_url = "cozie://param?data=" + base64_payload
# Print deep link
print(deep_link_url)
print(
"Number of characters:",
len(deep_link_url),
"of 2048 characters (",
int(len(deep_link_url) / 2048 * 100),
"%)",
)
# Generate QR code
qr = qrcode.QRCode(version=1, box_size=10, border=5)
qr.add_data(deep_link_url)
qr.make(fit=True)
img = qr.make_image(fill="black", back_color="white")
img.save("qrcode001.png")
Image("qrcode001.png", width=700, height=700)
Example QR Code
The above code snippet will return the deep link and QR code shown below. The QR code can be scanned with the default iPhone camera app and it will open the Cozie app with settings applied. You still need to sync the settings with the Cozie app on the Apple Watch.
Example Deep Link
As an alternative to the QR code the deep link below that can be sent to the participant. Opening the link on the iPhone will open the Cozie app with settings applied.