🚀 Browse our open source reference applications to accelerate your IoT project!

Search
Documentation Results
End of results
Community Results
End of results
Support
Blues.io
Notehub.io
Shop
Sign In
Search
Documentation Results
End of results
Community Results
End of results
Support
Blues.io
Notehub.io
Shop
×
HomeNotecardNotecard API ReferenceNotecard Guides
Notecard Firmware Updates
Notecard Walkthrough
Overview
Notecard Requests & Responses
JSON Fundamentals
Notecard Interfaces
Essential Requests
Time & Location Requests
Inbound Requests & Shared Data
Web Transactions
Low Power Design
Low Bandwidth Design
Host Firmware Update Requests
Advanced Notecard Configuration
Notecard Error and Status Codes
Rate this page  
  • ★
    ★
  • ★
    ★
  • ★
    ★
  • ★
    ★
  • ★
    ★
Can we improve this page? Send us feedbackRate this page
  • ★
    ★
  • ★
    ★
  • ★
    ★
  • ★
    ★
  • ★
    ★
© 2023 Blues Inc.Terms & ConditionsPrivacy
blues.ioTwitterLinkedInGitHubHackster.io
Disconnected
Notecard Disconnected
Having trouble connecting?

Try changing your Micro USB cable as some cables do not support transferring data. If that does not solve your problem, contact us at support@blues.com and we will get you set up with another tool to communicate with the Notecard.

Advanced Usage

The help command gives more info.

Connect a Notecard
Use USB to connect and start issuing requests from the browser.
Try Notecard Simulator
Experiment with Notecard's latest firmware on a Simulator assigned to your free Notehub account.

Don't have an account? Sign up

Web Transactions

If your host needs to perform web requests with a 3rd party API or service, the Notecard can facilitate these requests with the web.get, web.put, web.post, and web.delete APIs. See complete details in the web Requests API reference.

Use of these requests in the Notecard API requires the following:

1) The Notecard must be in continuous mode and connected to Notehub.

For example:

    {
      "req": "hub.set",
      "product": "com.your-company.your-name:your_product",
      "mode": "continuous"
    }
    J *req = NoteNewRequest("hub.set");
    JAddStringToObject(req, "product", "com.your-company.your-name:your_product");
    JAddStringToObject(req, "mode", "continuous");
    
    NoteRequest(req);
    req = {"req": "hub.set"}
    req["product"] = "com.your-company.your-name:your_product"
    req["mode"] = "continuous"
    
    card.Transaction(req)

    If any of the web.* requests are issued to a Notecard not in continuous mode or not connected, an error will be returned:

    {"err":"web operations require being online (hub.set)"}

    2) The endpoint to the 3rd party API or service must be configured as a proxy Route in Notehub as a "Proxy for Device Web Requests" type.

    This allows the host to avoid hardcoded URLs, keys, and certificates, while relying on Notehub secure authentication mechanisms for performing requests.

    notehub proxy for web requests

    Once the device is in continuous mode and the proxy Route is created, use web.get, web.put, web.post, or web.delete in accordance with the requirements of the final endpoint.

    For example, the Route shown above creates a proxy to a GET request to the weather endpoint of the OpenWeatherMap API . The route argument corresponds to the Route Alias specified when the proxy Route is created.

      {
        "req": "web.get",
        "route": "weatherInfo"
      }
      J *req = NoteNewRequest("web.get");
      JAddStringToObject(req, "route", "weatherInfo");
      
      NoteRequest(req);
      req = {"req": "web.get"}
      req["route"] = "weatherInfo"
      
      rsp = card.Transaction(req)

      For all web requests, the Notecard returns the HTTP Status Code in the result field. If the response also contains a body, that body is provided in the body field.

      warning

      The Notecard can only accept valid JSON in response to a GET, POST, or PUT request unless you override the default content argument of application/json with the appropriate MIME type.

      {
       "result": 200,
       "body": {
        "base": "stations",
        "clouds": {
         "all": 75
        },
        "coord": {
         "lat": 42.5776,
         "lon": -70.87134
        },
        "name": "Beverly",
        "weather": [
         {
          "description": "broken clouds",
          "icon": "04d",
          "id": 803,
          "main": "Clouds"
         }
        ],
        "wind": {
         "deg": 240,
         "speed": 5.1
        }
       }
      }
      note

      Data returned by a proxy Route is delivered to the Notecard unmodified. To preserve power and data, make sure the APIs you're working with return only the data needed by your host, if possible.

      For web.put and web.post requests, a JSON body OR base64-encoded payload can be provided using the body or payload arguments. Unlike the note.add API, you cannot use both at the same time in a single web transaction.

        {
          "req": "web.post",
          "route": "SensorService",
          "name": "/addReading",
          "body": {"temp":72.32, "humidity":32.2}
        }
        J *req = NoteNewRequest("web.post");
        JAddStringToObject(req, "route", "SensorService");
        JAddStringToObject(req, "name", "/addReading");
        
        J *body = JCreateObject();
        JAddNumberToObject(body, "temp", 72.32);
        JAddNumberToObject(body, "humidity", 32.2);
        JAddItemToObject(req, "body", body);
        
        NoteRequest(req);
        req = {"req": "web.post"}
        req["route"] = "SensorService"
        req["name"] = "/addReading"
        req["body"] = {"temp":72.32, "humidity":32.2}
        
        rsp = card.Transaction(req)

        After performing a web request, don't forget to set your Notecard back into a non-continuous mode, if needed, using hub.set.

        Sending Large Payloads to Notehub

        If your application needs to send large payloads to Notehub, as of Notecard firmware v3.2.1, web.post and web.put support sending payload fragments and can assemble these fragments before routing to your cloud application.

        To utilize this feature, your host will need to disassemble the payload into fragments, and send these in successive web.post requests. Your request must use arguments that Notehub uses to verify each fragment and understand where the individual fragments should be placed in the reassembled payload. Those fields are:

        • total - The total size of the entire payload, in bytes, across all fragments.
        • offset - For a given fragment, the number of bytes to offset from 0 when reassembling fragments in Notehub.
        • status - A 32-character hex-encoded MD5 sum of the payload or payload fragment. Used by Notehub to perform verification upon receipt.
        • verify - Can optionally be set to true to request verification from Notehub once the payload or payload fragment is received. Automatically set to true when status is supplied.
          {
            "req": "web.post",
            "payload": "<600 base64-encoded bytes of payload>",
            "status": "<base64 md5 sum of payload fragment>",
            "route": "SensorService",
            "offset": 600,
            "total": 8191
          }
          J *req = NoteNewRequest("web.post");
          JAddStringToObject(req, "payload", "<600 base64-encoded bytes of payload>");
          JAddStringToObject(req, "status", "<base64 md5 sum of payload fragment>");
          JAddStringToObject(req, "route", "SensorService");
          JAddNumberToObject(req, "offset", 600);
          JAddNumberToObject(req, "total", 8191);
          
          NoteRequest(req);
          req = {"req": "web.post"}
          req["payload"] = "<600 base64-encoded bytes of payload>"
          req["status"] = "<base64 md5 sum of payload fragment>"
          req["route"] = "SensorService"
          req["offset"] = 600
          req["total"] = 8191
          
          rsp = card.Transaction(req)

          Once the payload is received, it will be verified on Notehub and the verification result will be returned in the response from the Notecard.

          Inbound Requests & Shared DataLow Power Design