This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3220: Does the CC3220 HTTP Server Supports CORS (Cross-Origin Resource Sharing)?

Part Number: CC3220

Hi,

Following on from Ryan Hunter65's query and response, I cannot fathom how to get the link_local_task.c code to send back the "Access-Control-Allow-Origin: *" response to allow my javascript app on another computer to send GET requests to my CC3220 firmware. I need to use this to circumvent the fact that the 4MB serial Flash on the launchpad is miniscule for my requirements, as the flash is full of TI files, which I understand nothing of their essentiality. 

Basically, I have an existing central heating dashboard implemented in Javascript on a Raspberry Pi, sending HTTP requests to a Python server application on another Pi. I now want to port the server side to CC3220 and so eliminate the need for the Pi altogether. The grand plan is to have a network of sub-GHz CC1310 sensor nodes connected to the CC3220.

Ryan seemed to suggest he'd found a way to send back the "Access-Control-Allow-Origin: *" response. I would be grateful if he or anyone else can enlighten me how to implement this.

Thanks

Martin 

  • Hello,

    Not sure whether Ryan had it figured. Maybe he can reply on this post.

    However, since the internal HTTP server is not supporting CORS as part of the HTTP headers, you must implement an HTTP server in the host and parse requests that include CORS headers.

    Actually, we did something similar as part of the local_ota example. You can look at otaReportServerTask() where we use a server running on the host which reply with Access-Control-Allow-Origin: * header.

    Shlomi

  • Hi Shlomi,

    Thank you for your prompt reply. I took a look at the OTA example you suggested and saw where the Access Control header was added to the metadata response. I modified prepareGetMetadata() to add the following after the content-type header:

    // add CORS header

    *pMetadata = (uint8_t) SL_NETAPP_REQUEST_METADATA_TYPE_ORIGIN_CONTROL_ACCESS;
    pMetadata++;
    metadataLen+=1;
    (*(uint16_t *)pMetadata) = (uint16_t) 1;
    pMetadata+=2;
    metadataLen+=2;
    *pMetadata = '*';
    *pMetadata++;
    metadataLen+=1;

    (I changed the metadaLen calculation to cumulatively build up with each element rather than re-calculate at the end of the routine).

    The result works great: I can now receive back a sensible response into my Javascript code from a different location to the CC3220SF.

    Thanks again for your help.

    Best regards,

    Martin