Lua sample program

Last update: May 2015

This is a sample program that uploads the images in to Facebook from your FlashAir.

lua_sample.zip (5KB)

All sample code on this page is licensed under BSD 2-Clause License

  1. Register as a Developer
  2. Create a new App
  3. Get an Access Token
  4. Prepare to upload
  5. Upload!

Place the sample program in /lua on your FlashAir. Your directory structure should look something like the following:

/
+-- DCIM/
|   +-- 100__TSB/
|   +-- 101_FILE/
|       +-- JPEG file
+-- lua/
|   +-- facebook.html
|   +-- facebook.cfg
|   +-- fb_auto_up.lua
|   +-- fb_get_token.lua
|   +-- fb_token_handler.lua
|   +-- lastupload.cfg
+-- SD_WLAN/
    +-- CONFIG
  • DCIM/101_FILE is just an example path, the folder name will change depending on your camera.

Notes

  • This program is intended to be a demonstation, not for practical use.
  • If you have insufficient space on your card, the sample may not work.
  • If Facebook’s API changes, there is a chance this sample will no longer work.

1. Register as a Developer

To create an app that will access Facebook, you must be registered as a developer. If you are already registered, skip to the next step!

You’ll need a PC connected to the internet to continue.

  1. Open Facebook Developers
  2. Select "My Apps" → "Register as a Developer" from the menu.
  3. Complete the Developer Registation process.

2. Create a new App

Register a new application with Facebook. You’ll need a PC connected to the internet to continue.

  1. Open the Application Management Page
  2. Select "Create a New App" lua_sample_02_03
  3. Enter the "Display Name", choose a "category" and select "Create App ID". lua_sample_02_04
    • Example: "Lua Upload", "Photo"
  4. Then registration is complete, the Dashboard should appear. lua_sample_02_05
  5. Click "Settings" in the top left, and then select"+ Add Platform". lua_sample_02_06
  6. Choose "Website". lua_sample_02_07
  7. You will be asked for a site URL. Enter "URL: http://flashair.local/lua/facebook.html and then click "Save Changes" lua_sample_02_08
  8. The application information should be private, don’t share it with others! lua_sample_02_09
    • Application ID (App ID)
    • Application Secret Key (App Secret)
      • Press "Display" to see the App’s secret key.
  9. From the "Tools & Support" menu, select "Access Token Tool". lua_sample_02_10
  10. You should now have your "App Token". lua_sample_02_11

3. Aquiring the Access Token

  1. Insert the FlashAir into your card reader.
  2. Edit the "CONFIG" file, stored in the "SD_WLAN" folder.
Key Value Description
APPMODE 6 Sets "Internet pass-thru" mode.
APPSSID example) lua_test FlashAir’s SSID
APPNETWORKKEY example) 12345678 FlashAir’s WiFi Password
BRGSSID example) my_home_wlan WLAN AP’s SSID
BRGNETWORKKEY example) password12345678 WLAN AP’s Password
APPAUTOTIME 0 Disables the automatic timeout of the FlashAir’s network.
WEBDAV 2 WebDAV
  1. Edit facebook.html, and set your App ID (the appID variable).
var appId = "475125929999999";
  1. Remove and re-insert your FlashAir.
  2. From a PC, connect to the FlashAir’s Wireless LAN (using the SSID and password in CONFIG).
  3. Connect to http://flashair.local/lua/facebook.html with a web browser.
  4. An OAuth authentication screen should appear, click "OK". lua_sample_02_12
  5. It might be a good idea to set it so posts are only shared with you. lua_sample_02_13
  6. If it worked, it should output PUT Success: Created lua_sample_02_14
    • Your access token should be stored in a file called "fb_access_token" on your FlashAir (in the "lua" folder).

4. Preparing to Upload

  1. Insert the FlashAir into a card reader.
  2. Edit facebook.cfg and set the App ID.
app_access_token=475125929999999|qDhN3XeXxXxXxXxXxXxXxXxXxXx
app_secret=859ac999999999999999999999999999
app_id=475125929999999
token_fullpath=/lua/fb_access_token
  1. This will request an access token that should last for 60 days, as the current token will only be valid for about one hour. Access http://flashair.local/lua/fb_get_token.lua, and if the output looks like the following you’re ready to continue. lua_sample_02_15
  2. Edit lastupload.cfg and set the contents to the following. If the file does not exist, create it!
lastupload=1000001
  • This will tell the app to ignore the FA000001.JPG file in 100__TSB.
  1. It is a good idea to switch your FlashAir to Station Mode, by editing SD_WLAN/CONFIG
Key Value Description
APPMODE 5 Sets Station Mode
APPSSID example) my_home_wlan WLAN AP SSID
APPNETWORKKEY example) password12345678 WLAN AP Password
LUA_RUN_SCRIPT example) /lua/fb_auto_up.lua Run the FB uploader script on boot!
  1. Remove the FlashAir from the SDCard reader.

5. Upload!

  1. Re-insert the FlashAir
  2. Your FlashAir will automatically begin uploading to Facebook!
    • Your images will be sorted into albums based on date, in “YYYY-MM-DD” format.
    • Images will be uploaded by folder, oldest folder first.
    • Note: Deleting or renaming a folder may have unexpected results.
    • It can take several minutes for large images to upload.
  3. You should be able to see the uploaded photos on your Facebook page! lua_sample_02_16