This is a quick example of a simple HTTP client program using the network-socket API that is provided as a part of mbed-os. The program brings up an underlying network interface, and uses it to perform an HTTP transaction over a TCPSocket.

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Mon Jun 18 09:15:03 2018 +0100
Parent:
47:08787ef063cb
Child:
49:1923a727df5b
Commit message:
Merge remote-tracking branch 'origin/mbed-os-5.9.0-oob'

* origin/mbed-os-5.9.0-oob:
Print Mbed OS version
Updating mbed-os to mbed-os-5.9.0-rc3
Updating mbed-os to mbed-os-5.9.0-rc2
Use Ethernet by default on all platforms.
Add Jenkinsfile
Use Ethernet by default on ODIN_W2
Updating mbed-os to mbed-os-5.9.0-rc1

.
Commit copied from https://github.com/ARMmbed/mbed-os-example-sockets

Changed in this revision

Jenkinsfile Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Jenkinsfile	Mon Jun 18 09:15:03 2018 +0100
@@ -0,0 +1,75 @@
+properties ([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [
+  [$class: 'StringParameterDefinition', name: 'mbed_os_revision', defaultValue: '', description: 'Revision of mbed-os to build. Use format "pull/PR-NUMBER/head" to access mbed-os PR']
+  ]]])
+
+if (params.mbed_os_revision == '') {
+  echo 'Use mbed OS revision from mbed-os.lib'
+} else {
+  echo "Use mbed OS revisiong ${params.mbed_os_revision}"
+  if (params.mbed_os_revision.matches('pull/\\d+/head')) {
+    echo "Revision is a Pull Request"
+  }
+}
+
+// List of targets with supported RF shields to compile
+def targets = [
+  "UBLOX_EVK_ODIN_W2",
+  "K64F",
+  "NUCLEO_F429ZI"
+  ]
+
+// Map toolchains to compilers
+def toolchains = [
+  ARM: "armcc",
+  GCC_ARM: "arm-none-eabi-gcc",
+  IAR: "IAR-linux"
+  ]
+
+def stepsForParallel = [:]
+
+// Jenkins pipeline does not support map.each, we need to use oldschool for loop
+for (int i = 0; i < targets.size(); i++) {
+    for(int j = 0; j < toolchains.size(); j++) {
+          def target = targets.get(i)
+          def toolchain = toolchains.keySet().asList().get(j)
+          def compilerLabel = toolchains.get(toolchain)
+
+          def stepName = "${target} ${toolchain}"
+          stepsForParallel[stepName] = buildStep(target, compilerLabel, toolchain)
+    }
+}
+
+timestamps {
+  parallel stepsForParallel
+}
+
+def buildStep(target, compilerLabel, toolchain) {
+  return {
+    stage ("${target}_${compilerLabel}") {
+      node ("${compilerLabel}") {
+        deleteDir()
+        dir("mbed-os-example-socket") {
+          checkout scm
+
+          // Set mbed-os to revision received as parameter
+          execute ("mbed deploy --protocol ssh")
+          if (params.mbed_os_revision != '') {
+            dir ("mbed-os") {
+              if (params.mbed_os_revision.matches('pull/\\d+/head')) {
+                execute("git fetch origin ${params.mbed_os_revision}:PR")
+                execute("git checkout PR")
+              } else {
+                execute ("git checkout ${params.mbed_os_revision}")
+              }
+            }
+          }
+          execute("mbed new .")
+          execute ("mbed compile --build out/${target}_${toolchain}/ -m ${target} -t ${toolchain}")
+        }
+        stash name: "${target}_${toolchain}", includes: '**/mbed-os-example-socket.bin'
+        archive '**/mbed-os-example-socket.bin'
+        step([$class: 'WsCleanup'])
+      }
+    }
+  }
+}
--- a/main.cpp	Wed Jun 06 15:00:09 2018 +0100
+++ b/main.cpp	Mon Jun 18 09:15:03 2018 +0100
@@ -14,6 +14,11 @@
 
     // Bring up the ethernet interface
     printf("Ethernet socket example\n");
+
+#ifdef MBED_MAJOR_VERSION
+    printf("Mbed OS version %d.%d.%d\n\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
+#endif
+
     r = net.connect();
     if (r != 0) {
         printf("Error! net.connect() returned: %d\n", r);
--- a/mbed-os.lib	Wed Jun 06 15:00:09 2018 +0100
+++ b/mbed-os.lib	Mon Jun 18 09:15:03 2018 +0100
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#35fa909641fedcad9bbe0c7300d4ccdf15a2b71a
+https://github.com/ARMmbed/mbed-os/#866850acc15e86cd4ac11bf4404078a49f921ddd
--- a/mbed_app.json	Wed Jun 06 15:00:09 2018 +0100
+++ b/mbed_app.json	Mon Jun 18 09:15:03 2018 +0100
@@ -1,10 +1,8 @@
 {
     "target_overrides": {
         "*": {
-            "platform.stdio-convert-newlines": true
-        },
-        "UBLOX_EVK_ODIN_W2": {
-            "target.device_has_remove": ["EMAC"]
+            "platform.stdio-convert-newlines": true,
+            "target.network-default-interface-type": "ETHERNET"
         }
     }
 }