sys_http.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "http_client.h"
  2. #include "string.h"
  3. #include "stdio.h"
  4. #include "main.h"
  5. #include "myFIle.h"
  6. #include "sys_http.h"
  7. #include "log.h"
  8. #include "main.h"
  9. uint8_t load_http_config=0;
  10. //get请求 http://gpu.ringzle.com:8082/iot/transmit/getTransmitConfig/DT8pd3ac6h 端口8082
  11. //目前为此处去控制http一次性读入数据大小,应为该处为读入函数
  12. void http_getDemo(void)
  13. {
  14. int datalen;
  15. int ret;
  16. char* device_config = mymalloc(SRAMEX, 10);
  17. memset(device_config, 0,10);
  18. read_file("device.txt", device_config);
  19. if((strstr(device_config,"tcp_config")) == NULL)
  20. {
  21. myfree(SRAMEX, device_config);
  22. char *http_data=mymalloc(SRAMEX, 20 * 1024);
  23. char *http=mymalloc(SRAMEX,50);
  24. sprintf(http,"/iot/transmit/getTransmitConfig/%s",gatewayId);
  25. ret = http_clientGet("gpu.ringzle.com", http, 8082, 0, (uint8_t*)http_data, &datalen);
  26. if(ret==200) //获取成功
  27. {
  28. DeleteDirFile("device.txt");
  29. write_file("device.txt",http_data,strlen(http_data));
  30. load_http_config=1;
  31. printf("http get demo success\n");
  32. }
  33. HTTP_PRINTF("%s", (char *)http_data);
  34. HTTP_PRINTF("\r\n ret=%d datalen=%d\r\n", ret, datalen);
  35. myfree(SRAMEX,http_data);
  36. myfree(SRAMEX,http);
  37. return;
  38. }
  39. myfree(SRAMEX, device_config);
  40. }
  41. char *postData = "{\"bandwidth\":250,\"codeRate\":4700}";
  42. uint8_t postResult[512];
  43. //POST请求 http://gpu.ringzle.com/iot/test/httpTest 端口号8082
  44. void http_postDemo(void)
  45. {
  46. int datalen, ret;
  47. memset(postResult, 0, sizeof(postResult));
  48. // ret = http_clientPost("gpu.ringzle.com", "/iot/test/httpTest", 8082, 0, http_data, 5837, postResult, &datalen);
  49. ret = http_clientPost("gpu.ringzle.com", "/iot/test/httpTest", 8082, 0, (uint8_t *)postData, strlen(postData), postResult, &datalen);
  50. HTTP_PRINTF("%s", (char *)postResult);
  51. HTTP_PRINTF("\r\n ret=%d datalen=%d\r\n", ret, datalen);
  52. }
  53. /*
  54. *********************************************************************************************************
  55. * 函 数 名: int get_http_config(void)
  56. * 功能说明: 获取http配置的相关参数
  57. * 形 参:无
  58. * 返 回 值: 返回http是否配置 0:没有配置过,1:配置过
  59. *********************************************************************************************************
  60. */
  61. int get_http_config(void)
  62. {
  63. return load_http_config;
  64. }